SHARE
TWEET

Untitled

a guest Jun 15th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React    from 'react';
  2. import ReactDOM from 'react-dom';
  3.  
  4. import Modal    from './Modal';
  5.  
  6. import { cleanup, fireEvent, render} from '@testing-library/react'
  7.  
  8. describe('Modal', () => {
  9.   afterEach(cleanup);
  10.  
  11.   it('renders without crashing', () => {
  12.     const div = document.createElement('div');
  13.     ReactDOM.render(<Modal/>, div);
  14.     ReactDOM.unmountComponentAtNode(div);
  15.   });
  16.  
  17.  
  18.   it('renders correctly', () => {
  19.     const div = document.createElement('div');
  20.     const {getByText} = render(
  21.       <Modal modal={true}>
  22.         <div>Content</div>
  23.       </Modal>, div
  24.     )
  25.     expect(getByText('Content')).toBeTruthy()
  26.   });
  27.  
  28.   it('backdrop click calls openModal(false)', () => {
  29.     const openModal = jest.fn();
  30.  
  31.     const div = document.createElement('div');
  32.     const { getByRole } = render(
  33.       <Modal modal={true} openModal={() => openModal(false)} >
  34.         <div>Content</div>
  35.       </Modal>, div
  36.     );
  37.     fireEvent.click(getByRole('complementary'));
  38.     expect(openModal.mock.calls[0][0]).toBe(false);
  39.     expect(openModal.mock.calls.length).toBe(1);
  40.   });
  41.  
  42. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top