Reserved. I ❤ React Testing Library • Make components testable • Provide data-testid="" attribute • Export all components • Test file extension: ComponentFile.test .jsx or .tsx • Test Shallow or Depth of Component? Decide. • Shallow – use jest mock import • Cheatsheet: https://testing-library.com/docs/react-testing- library/cheatsheet • userEvent.click, userEvent.clear, userEvent.type, etc. from @testing-library/user-event • render(), {container}, screen{}, debug(), getByTestId(), renderHook(), getByLabelText() Testing Components
Reserved. I ❤ React Testing Library • React Components • Rendering • Re-rendering • Hooks • Pages • Service Calls • Reducers • Utils • User Actions • Unit Tests What to Test
Reserved. I ❤ React Testing Library • Jest (Runner + Mocking + Spy + Assertion) for Unit Tests • Cypress/Puppeteer/Webdriver/Playwright for E2E Tests with MSW • Test the Happy flow • Test the Edge cases • Negative • Far negative • Positive • Far positive • Zero • User interaction driven • Table based test cases (easy manageable) • Normal tests • Snapshot based • Value Assertion based How to Test
Reserved. I ❤ ReactJS • Write a testable component • Write tests for the component • Add user interactivity to component • Test user interactivity Exercise