All topics
Testingintermediate

End-to-End Testing with Cypress/Playwright vs Component Testing

Understand the different layers of the testing pyramid as applied to a React app and when each tool is appropriate.

End-to-end (E2E) tests, using tools like Cypress or Playwright, drive a real, fully running application in an actual browser, simulating a real user's complete journey across multiple pages and real (or realistically mocked) backend interactions. This gives the highest confidence that the whole system works together correctly, but at the cost of being the slowest and most expensive tests to write, run, and maintain.

It's like the difference between a full dress rehearsal of an entire theater production from start to finish (E2E) versus individual actors rehearsing their specific scenes in a smaller room (component tests) — the full dress rehearsal gives the most complete confidence the whole show works together, but you can't afford to run a full dress rehearsal for every tiny line change, so most rehearsal time happens at the smaller, faster scene level.

Key Concepts

1
Component tests (using React Testing Library, typically run under Jest or Vitest) render individual components in isolation (or small trees of related components), offering much faster feedback and more precise failure localization — when a component test fails, you know exactly which component's behavior broke, whereas an E2E test failure might require more investigation to pinpoint the actual cause across a whole user flow.
2
The common guidance, often visualized as a 'testing pyramid,' is to have many fast, focused component/unit tests forming the base, a smaller number of integration tests covering how several components or a feature work together, and a comparatively small number of E2E tests reserved for the most critical, high-value user journeys (login, checkout, core workflows) where full-system confidence matters most and the cost of a slower, more expensive test is justified.
3
Interviewers ask candidates to design a testing strategy for a given feature (like checkout), expecting them to correctly identify that the bulk of coverage should come from fast component/unit tests, with perhaps one or two E2E tests covering only the critical, unabbreviated happy path — not an attempt to E2E-test every single edge case, which would be prohibitively slow and brittle to maintain.