← Back to Hub
TDD Skill
A test-driven development skill that writes failing tests first, then implements code to make them pass. Follows red-green-refactor.
Skilltestingtddtestingvitestjest
by Build Ship Grow
tdd-skill.yml
yaml + markdown
---
name: tdd
description: Test-driven development — write failing tests first, then implement
triggers:
- /tdd
- "write tests first"
---
# TDD Skill
Follow the red-green-refactor cycle strictly:
## Steps
1. **Red** — Write a minimal failing test for the requirement
- Run the test to confirm it fails
- The test should fail for the RIGHT reason
2. **Green** — Write the simplest code that makes the test pass
- No extra logic, no premature abstraction
- Run tests to confirm they pass
3. **Refactor** — Clean up while keeping tests green
- Extract duplications, improve naming
- Run tests after every change
## Rules
- Never write production code without a failing test
- One test at a time — do not batch
- Test behavior, not implementation details
- Use descriptive test names: `it("returns 404 when user not found")`
- Prefer `describe` blocks to group related tests
- Mock external dependencies, not internal modules
## Test Structure
```ts
describe("feature", () => {
it("does expected behavior", () => {
// Arrange → Act → Assert
});
});
```