Skip to content

๐Ÿงช Testing - The Testing Trophy

Move away from the traditional Testing Pyramid and embrace the Testing Trophy. In modern frontend development, Integration Tests provide the highest ROI because they verify that components work togetherโ€”exactly how the user experiences the appโ€”without the overhead of slow E2E tests.


Tools like TypeScript and ESLint catch typos, null checks, and syntax errors before you even run a test.

  • Programmerโ€™s Strategy: Strict TypeScript configurations are your first and cheapest line of defense.

Testing small, isolated units of logic (pure functions, utility helpers).

  • Tools: Vitest, Jest.
  • Best For: Complex business logic, date formatting, or mathematical calculations.
  • Avoid: Mocking the entire world just to test a component that only renders a โ€œHelloโ€ message.

Testing a group of components or a whole page to ensure they interact correctly.

  • Tools: React Testing Library, Vue Test Utils.
  • Focus: Test behavior, not implementation. Instead of checking if a function was called, check if the โ€œSuccessโ€ message appeared on the screen after a button click.
  • Philosophy: โ€œThe more your tests resemble the way your software is used, the more confidence they can give you.โ€ โ€” Kent C. Dodds.

Testing the full user flow in a real browser, from the frontend to the real database.

  • Tools: Playwright, Cypress.
  • Best For: Critical paths like โ€œUser Login,โ€ โ€œCheckout Flow,โ€ or โ€œAccount Creation.โ€
  • Warning: E2E tests are slow and โ€œflaky.โ€ Use them sparingly for the โ€œHappy Path.โ€

Stop mocking fetch or axios at the component level.

  • Programmerโ€™s Move: Use MSW. It intercepts network requests at the browser/node level using Service Workers. This allows your tests to remain unaware of the network, making them more resilient to code changes.

Code tests canโ€™t tell if your CSS is broken or if a button is hidden behind a div.

  • Tools: Chromatic, Percy, or Playwright Screenshots.
  • Process: It takes a snapshot of your UI and compares it pixel-by-pixel against a โ€œbaselineโ€ to detect unexpected visual changes.

Integrate accessibility checks into your automated suite.

  • Tool: jest-axe.
  • Example: A test can fail if your new component includes a button without an accessible name or a form input without a label.

Test TypeSpeedCost to WriteConfidenceFlakiness
StaticInstantVery LowLowZero
UnitVery FastLowModerateLow
IntegrationFastModerateHighLow
E2ESlowHighVery HighHigh

  • Testing Implementation Details: If you rename a private variable and your test fails, you are testing how the code works, not what it does. This makes refactoring impossible.
  • Over-Mocking: If you mock every sub-component and every API call, you arenโ€™t testing your application; youโ€™re testing your mocks.
  • Snapshot Testing Overuse: Big snapshots of HTML are hard to review and often get updated blindly (u key). Use them only for small, stable components.

๐Ÿ’ก Note: A test suite that takes 30 minutes to run in CI is a failed suite. It kills developer velocity. As a Programmer, you must actively prune slow tests, parallelize execution, and ensure that the โ€œlocal development loopโ€ remains fast.