Skip to content

Unit Testing Guide

Write the test first, always.

Red → Green → Refactor. Never write feature code without a failing test waiting for it.


Where Things Live

apps/backend/src/
  some.service.ts        ← source
  some.service.spec.ts   ← test lives next to it
apps/frontend/src/
  some.component.tsx       ← source
  some.component.spec.tsx  ← test lives next to it (or in __tests__/)
jest.config.base.js   ← shared timeout + reporters - don't touch

What to Run

pnpm run test:unit                              # all unit tests (no e2e)
pnpm --filter backend run test -- --coverage   # backend with coverage
pnpm --filter frontend run test -- --coverage  # frontend with coverage

What to Worry About

Test quality
  • Name reads like a sentence: it('should return 400 if the date is in the past')
  • One behaviour per test - if it can fail for two reasons, split it.
  • Only mock what crosses a real boundary (HTTP, DB, file system).

Definition of Done

Unit Test Checklist
  • [ ] Failing test written before the feature.
  • [ ] Happy path and edge cases covered.
  • [ ] Test name clearly describes the expected behaviour.
  • [ ] Suite passes locally (pnpm run test:unit).
  • [ ] Coverage thresholds met.

Tools

Context Tool
Frontend / Backend Jest
Solver (Python) pytest