Course contentsShow
← React
Lesson 2188 of 2,39648. End-to-End TestingFree lesson

Unit Tests for Fast Feedback Loops

Run unit tests on every save during development; E2E tests are slower and better suited for CI pipelines.

Unit Tests for Fast Feedback Loops

What you'll learn: How to use unit tests during active development for instant feedback, while reserving E2E tests for slower, comprehensive validation.

When you're building a React component, you want to know immediately if you broke something. That's where unit tests shine—they're your development safety net, running in milliseconds on every save.

The Speed Difference

Unit tests (with Jest and React Testing Library) typically run in under a second for dozens of tests. E2E tests (Playwright, Cypress) can take several seconds per test because they:

  • Launch real browsers
  • Navigate between pages
  • Wait for network requests
  • Render entire application flows

Think of it like spell-check vs. peer review: spell-check (unit tests) happens instantly as you type, catching typos immediately. Peer review (E2E tests) happens later, checking if your entire document makes sense.

The Development Workflow

Configure your unit tests to run on file save using watch mode:

npm test -- --watch

Now every time you modify a component, your tests re-run instantly. You get a tight feedback loop: change code → see test results → fix → repeat. This is impossible with E2E tests that might take 30+ seconds to run a full suite.

Where E2E Fits In

E2E tests belong in your CI pipeline, running before merges to production. They validate that login flows work, checkout processes complete, and multi-page journeys succeed—things unit tests can't verify. But they're too slow for the rapid iteration of active development.

Use unit tests to validate component logic, user interactions, and edge cases as you build. Use E2E tests to validate the assembled application before you ship.

Key Takeaway: Run unit tests on every save for instant feedback during development; save slower E2E tests for CI pipelines where they validate complete user journeys before deployment.