Testing React
Test React apps the way users use them: Vitest and Testing Library, role queries, user-event, async UI, mocks, hooks, context, and end-to-end checks with Playwright.
A test is a small program that uses your app and checks the result, so you find out a change broke something before your users do. This phase teaches the modern way to test React: render a component, find things the way a person would (by their role and label), act like a user with user-event, and check what appears on the screen.
You'll set up Vitest and React Testing Library, learn the query priority that also keeps your app accessible, test loading states, errors and timers, mock network calls with fake functions and MSW, test custom hooks, context and reducers, and finish with Playwright end-to-end, visual and accessibility tests, plus a plan for what to automate where.
Every live example on these pages runs real Testing Library 16 and user-event 14 against React 19 in your browser. There is no Vitest in the preview, so each example has a five-line test() and expect() helper that prints ✓ for a passing test and ✗ for a failing one. The real Vitest files and terminal output are shown next to them.
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.