Don't E2E-Test Every Edge Case
What you'll learn: Why edge cases and error states belong in unit tests, not end-to-end tests.
The Wrong Approach
It's tempting to use E2E tests to verify every possible scenario—invalid email formats, empty form submissions, network timeouts, missing required fields, and so on. After all, E2E tests exercise the real application, right?
This is a trap. E2E tests are slow and expensive to run. They require spinning up browsers, navigating pages, waiting for animations, and simulating full user flows. Testing 20 edge cases in a form means 20 separate browser sessions, each taking seconds or minutes.
The Smart Approach
Edge cases, error states, and validation logic should live in unit tests. These tests run in milliseconds, don't require browsers, and can cover hundreds of scenarios in the time it takes one E2E test to load.
For example, testing email validation regex? Unit test it. Testing that a form shows an error when a field is empty? Component test with React Testing Library. Testing what happens when an API returns a 500 error? Mock it with MSW in a component test.
Reserve E2E tests for the happy path and critical failure scenarios. Does the login flow work? Does checkout complete successfully? Does the app gracefully handle a complete network failure? These are E2E-worthy.
The Analogy
Think of E2E tests like flight simulators—expensive, time-consuming, but essential for testing pilots in realistic conditions. You don't use a flight simulator to teach someone which button turns on the reading light. That's a quick walkthrough (unit test).
Key Takeaway: E2E tests verify critical user journeys; unit and integration tests verify the edge cases, error handling, and validation logic that make those journeys robust. Test smartly at the right level of the pyramid.