test-driven-development
Test-Driven Development
Iron Law
No production code without a failing test first.
No exceptions. Not for "simple" changes. Not for "obvious" fixes. Not under time pressure.
RED-GREEN-REFACTOR
1. RED — Write a failing test
- One minimal test with a clear name
- Use real code, not mocks (unless unavoidable)
- Watch it fail. Verify it fails for the RIGHT reason.
2. GREEN — Write minimal code to pass
- Only enough code to make the test pass
- No premature optimization or extra features
- Run the test. See green.
3. REFACTOR — Clean up while green
- Remove duplication, improve naming
- Run tests after every change — stay green
- Commit when clean
Test Classification
| Suffix | Purpose | DOM? | Example |
|---|---|---|---|
.test.ts |
Unit — pure logic | No | parse-config.test.ts |
.test.tsx / .integration.tsx |
Integration — renders components | Yes | UserTable.test.tsx |
e2e/*.spec.ts |
E2E — Playwright browser tests | Browser | login.spec.ts |
When Done Checklist
- All tests pass (
bun test --run) - No async leaks (
bun test --run --detectAsyncLeaks) - No
setTimeout/waitForTimeouthacks — use condition-based waiting - Prefer
getByRoleovergetByTestIdfor accessibility assertions - Tests verify behavior, not implementation
See REFERENCE.md for diagnostic commands, anti-patterns, and condition-based waiting patterns.
More from malinskibeniamin/skills
setup-react-rules
Enforce React/TS/security rules via PostToolUse hooks — bans raw HTML, TS escape hatches, XSS vectors, barrel imports, missing passive listeners. Use when enforcing React patterns or component library standards.
9setup-react-compiler
Install React Compiler with rsbuild and enforce compiler-friendly patterns via PostToolUse hooks. Flags manual memoization, derived state, useRef cache. Use when setting up React Compiler or post-compiler patterns.
9setup-biome
Install Biome linter with Ultracite preset, create biome.jsonc config, and configure Claude Code Stop hook for auto-fix before finishing. Use when setting up linting, formatting, Biome, Ultracite, or code quality enforcement.
9setup-quality-gate
Add quality:gate package.json script for fast local/CI quality checks (biome + tsgo + related tests), GitHub Actions workflow, and Stop hook for type checking. Use when setting up quality gates, CI pipelines, or pre-push validation.
9setup-connect-query
Enforce ConnectRPC + Connect Query + Protobuf v2 patterns via PostToolUse hooks. Bans raw useQuery, empty invalidateQueries, $typeName literals. Use when setting up ConnectRPC, protobuf type safety, or data fetching enforcement.
8work-automation-kit
Install planning and project management skills — PRD creation, implementation planning, issue breakdown, bug triage, code review. Use when setting up project planning workflows or creating PRDs.
8