I keep E2E (end-to-end) tests few, and focus them on critical user journeys. Edge cases go into component tests.
E2E tests are the only ones that prove the whole system works together:
- a real browser
- real routing
- server rendering
- auth cookies
- often the real API
But they're slower and more fragile. So I cover the critical journeys:
- sign-up and login
- checkout or payment
- the product's main create, edit and delete flow
E2E is also the right tool for things unit tests can't reach. Examples are async Server Components, middleware redirects and full navigation.
Edge cases are cheaper as component tests. Examples are every validation message, empty states and error variants.
To keep E2E tests stable:
- Seed test data through an API.
- Reuse login state with
storageState, instead of logging in through the UI every time. - Mock unstable third-party services with
page.route.
- E2E tests prove the whole system works together.
- Keep a few E2E tests on critical user journeys.
- E2E covers what jsdom can't, like Server Components, middleware and navigation.
- Edge cases belong in component tests, because they're cheaper there.
- Keep E2E stable: seed data, reuse auth state, and mock third parties with
page.route.
Read more