I’m doing Blogvent, a challenge to blog every day through December 25th. Today’s prompt is:

Day 5: Your local testing setup. Explain how you structure fast unit tests, seed databases, or mock external APIs locally.

I think of tests in layers, inspired by Kent C. Dodd’s Testing Trophy.

JavaScript testing took a while to catch up to the popularity of the frontend frameworks. I think this gave us JavaScript devs the incorrect idea that you can’t test a JavaScript application. You can.

I’ve built a frontend test suite from scratch several times, and each time I build these parts, in this order.

  1. Static analysis
  2. Unit tests
  3. Integration tests
  4. End-to-end tests
  5. Code review & observability

Static analysis catches lots of mistakes. On a JavaScript app, this would be a formatter (Prettier), linter (ESLint), TypeScript, and scanners: security, accessibility, etc.

Unit tests enforce contracts between functional code. I use Jest to write tests about my helpers and utilities. I write only enough to cover the core behavior and prevent regressions.

Integration tests are where the real value lies. I write React Testing Library tests that load each top-level component with no mocking, simulate user behavior, and assert about what a user would see. They’re like E2E tests, but faster and easier to maintain.

E2E tests cover core user experiences like adding an item to the cart. For these, I use Cypress or Playwright.

The last two tests aren’t tests: code review and observability. Code review catches things that tools can’t catch. Observability (Sentry, Datadog, etc.) catches bugs triggered by the ever-surprising behavior of users.

When this is all in place, we have a test suite.