Skip to content

🧪 Testing - The Testing Trophy

The Senior Mindset: 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.

  • Senior 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.”

1. Mocking the API: MSW (Mock Service Worker)

Section titled “1. Mocking the API: MSW (Mock Service Worker)”

Stop mocking fetch or axios at the component level.

  • Senior 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.

💡 Seniority Note: A test suite that takes 30 minutes to run in CI is a failed suite. It kills developer velocity. As a senior, you must actively prune slow tests, parallelize execution, and ensure that the “local development loop” remains fast.


  • [[Frontend-Acessibilidade-WCAG]]
  • [[Optimization-Web-Performance]]
  • [[Architecture-CI-CD-Pipelines]]