Skip to content

11 · Testing ​

Phase: 4 · Estimate: 2–3 weeks · Prerequisites: 07 Framework

Why it matters ​

Good tests give you the confidence to refactor. Bad tests (brittle, slow, testing implementation) hold you back. The core skill isn't the syntax of a test framework. It's deciding what to test and at which level.

Concept map ​

Basics ​

  • Unit tests: Vitest / Jest
  • Component tests: Testing Library (query by role and label)
  • E2E: Playwright / Cypress
  • Assertions, mocks, spies

Intermediate ​

  • The testing pyramid vs the testing trophy
  • Test doubles: stubs, mocks, fakes; network mocking with MSW
  • Fake timers, testing async code
  • Visual regression (Playwright screenshots, Chromatic)
  • Coverage: its value and its traps

Deep dive ​

  • Flaky tests: their sources (timing, shared state, animation) and how to eliminate them
  • Contract testing between front-end and API
  • Mutation testing (Stryker) to measure test quality
  • Automated accessibility testing (axe-core)

How to learn ​

  1. Write tests for @chalidade/utils, then change the implementation. Which tests fail because behavior changed, and which only because of implementation details?
  2. Replace every getByTestId query in a project with getByRole, and note the a11y bugs you find.
  3. Write one Playwright E2E test, run it 50 times (--repeat-each=50), and fix it until it's not flaky.

Check your understanding ​

  1. Why does Testing Library encourage getByRole queries?
  2. When do mocks make a test useless?
  3. What does 100% coverage not guarantee?
  4. How does Playwright handle auto-waiting, and why is a sleep in a test a warning sign?

Practice projects ​

LevelProjectWhat it trains
BasicUnit tests for a util + a component test for a formVitest, Testing Library
IntermediateAn E2E suite for a login–checkout flow with MSW and PlaywrightE2E, mocking
DeepA mini test runner: describe/it/expect, hooks, a reporterHow runners work

Primary sources ​

MIT License