Advertisement
Chaiwa

Example React Test

Jun 21st, 2021
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @jest-environment jsdom
  3.  */
  4.  
  5. import React from 'react';
  6. import { cleanup, fireEvent, render } from '@testing-library/react';
  7. import CheckboxWithLabel from '../../js/fake_components/CheckboxWithLabel';
  8.  
  9. // Note: running cleanup afterEach is done automatically for you in @testing-library/react@9.0.0 or higher
  10. // unmount and cleanup DOM after the test is finished.
  11. afterEach(cleanup);
  12.  
  13. it('CheckboxWithLabel changes the text after click', () => {
  14.   const { queryByLabelText, getByLabelText } = render(
  15.     <CheckboxWithLabel labelOn="On" labelOff="Off" />
  16.   );
  17.  
  18.   expect(queryByLabelText(/off/i)).toBeTruthy();
  19.  
  20.   fireEvent.click(getByLabelText(/off/i));
  21.  
  22.   expect(queryByLabelText(/on/i)).toBeTruthy();
  23. });
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement