React Best Practices

Chapter 7 · Practice 3 of 4

Cover the critical user flows with end-to-end tests

From Testing React code

Why it matters

Unit and component tests cannot catch everything: routing, real network calls, cookies and browser quirks only show up in a real browser.

Write a small number of end-to-end tests with a tool like Playwright for the flows that would hurt most if they broke:

  • sign up and sign in,
  • checkout,
  • publishing.

Keep them few and stable:

  1. Run them in CI on every pull request against a preview build.
  2. Give elements accessible names so tests find them by role instead of brittle CSS selectors.

Do

  • Pick five to ten flows that matter most and test only those end to end