Test React components and user flows with Testing Library

11 steps · about 3 h 55 min · Intermediate

  1. React Testing Library (doc, Testing Library (official docs), 10 min)

    Start with the official install steps and the idea that tests should resemble how users use the app.

  2. React Testing Library Tutorial – How to Write Unit Tests for React Apps (tutorial, freeCodeCamp, 40 min)

    A hands-on setup with Vitest or Jest and jest-dom, ending with your first passing tests.

  3. React Testing Library Tutorial (with Jest & Vitest) (tutorial, Robin Wieruch, 45 min)

    Goes further than the first tutorial: rendering, queries, user events and testing async data fetching in one project.

  4. About Queries (doc, Testing Library (official docs), 15 min)

    Learn the query priority, with getByRole first, before you write many tests.

  5. Introduction (user-event) (doc, Testing Library (official docs), 10 min)

    Learn the userEvent.setup() pattern for clicking and typing like a real user.

  6. Utility APIs (user-event) (reference, Testing Library (official docs), 15 min)

    Practise type, clear, selectOptions and upload, the building blocks of form flows.

  7. Example (doc, Testing Library (official docs), 15 min)

    A full arrange-act-assert example of a user flow that loads data and waits with findBy.

  8. Common mistakes with React Testing Library (blog, Kent C. Dodds, 25 min)

    Once you have written some tests, this fixes habits such as misusing waitFor, skipping user-event and over-using test IDs.

  9. Common Testing Mistakes (blog, Kent C. Dodds, 20 min)

    Explains why testing implementation details makes tests brittle and how to keep them isolated.

  10. Write fewer, longer tests (blog, Kent C. Dodds, 10 min)

    Shows how to structure a whole user flow in one test and avoid act warnings.

  11. MSW Testing Guide: Mock Service Worker with Jest, Vitest & React Testing Library (article, HelpMeTest, 30 min)

    Last step: mock the network with MSW 2.x so full user flows run without a real API.