Courses / React 19: From Components to Production / Chapter 19
Module 9 · Complex Forms and Testing · Chapter 19 of 30
Testing React: Components, Hooks, Network and End-to-End
Builds on Components: Props, Children, Conditions, Lists and Keys, State and Effects: useState, Events, useEffect and Cleanup, Data Fetching: Requests, Loading States, Races, Caching and Errors and Advanced Hooks: Refs, Reducers, Context, Layout Effects and Custom Hooks. Next up: Accessibility, Internationalisation and Design Systems.
Part 1 · What to test and at which level
Three levels of test
A cinema seat picker shows a hall, adds up the price of the chosen seats and books them through an API. Each part can be tested at a different level, and the level decides how fast the test runs and what it can catch.
A unit test checks one function or hook alone, with no screen. An integration test renders components together in a simulated browser and works them the way a person would. An end-to-end test, written E2E, drives a real browser against the built application and a running server. The three trade cost for realism. A unit test is quick and exact and knows nothing about the screen. An E2E test sees what a user sees and is slower, needs a server, and fails for more reasons.
| Unit | Integration | End to end |
|---|