mattpocock / skills
tdd
Red-green-refactor workflow for building features and fixes one slice at a time.
Install
npx skills add https://github.com/mattpocock/skills --skill tddWhen to Mock
Mock at system boundaries only:
- External APIs (payment, email, etc.)
- Databases (sometimes - prefer test DB)
- Time/randomness
- File system (sometimes)
Don't mock:
- Your own classes/modules
- Internal collaborators
- Anything you control
Designing for Mockability
At system boundaries, design interfaces that are easy to mock:
1. Use dependency injection
Pass external dependencies in rather than creating them internally:
2. Prefer SDK-style interfaces over generic fetchers
Create specific functions for each external operation instead of one generic function with conditional logic:
The SDK approach means:
- Each mock returns one specific shape
- No conditional logic in test setup
- Easier to see which endpoints a test exercises
- Type safety per endpoint