| name | tdd |
| description | TDD (Test-Driven Development) rules and patterns. Use when: (1) Writing unit tests, (2) Determining test targets, (3) Following TDD cycle. Supports Expo, React Native, React Router, NestJS using Vitest/Jest. |
TDD Skill
TDD rules and patterns for Node/TypeScript/React projects.
Test Target Rules
Priority Order (IMPORTANT)
Exclusions are evaluated FIRST, then Must Test patterns apply.
1. Check Exclusion patterns → If matched, SKIP
2. Check Must Test patterns → If matched, WRITE TEST
3. If neither matched → SKIP (not a test target)
Must Test
| Pattern | Description |
|---|
*.service.ts | Service functions |
*.helper.ts, *.util.ts | Helper/utility functions |
*.tsx (components) | React components (except paths matching exclusions) |
loader, action | Route loaders/actions |
*.schema.ts | Zod schemas |
use*.ts | Custom hooks |
Exclude from Testing (Evaluated First)
| Pattern | Reason |
|---|
**/components/ui/** | shadcn/ui auto-generated (takes priority over *.tsx) |
*.d.ts | Type declarations only |
**/types.ts, **/types/** | Type definitions only |
**/*.port.ts | Interface definitions only |
**/index.ts | Barrel files (re-exports) |
*.config.ts | Configuration files |
**/constants.ts, **/const.ts | Static values only |
**/*.css, **/*.scss | Style files |
Naming Convention
Source → Test path mapping:
| Source Path | Test Path |
|---|
app/services/auth.service.ts | __tests__/services/auth.service.test.ts |
app/components/Button.tsx | __tests__/components/Button.test.tsx |
app/domain/user/user.schema.ts | __tests__/domain/user/user.schema.test.ts |
Pattern: Replace root folder with __tests__/ and add .test before extension.
TDD Cycle
Red → Green → Refactor
- Red - Write a failing test
- Green - Write minimal code to pass
- Refactor - Improve code (keep tests passing)
AAA Pattern
All tests follow AAA (Arrange-Act-Assert) pattern:
| Phase | Role | Example |
|---|
| Arrange | Prepare test data and environment | Mocking, input creation |
| Act | Execute test target | Function call, event trigger |
| Assert | Verify results | expect statements |
Framework Test Environment
| Framework | Test Runner | Note |
|---|
| Expo | Jest | Vitest NOT supported |
| React Native | Jest | Vitest NOT supported |
| React Router v7 | Vitest/Jest | Vitest recommended |
| NestJS | Jest | Official default |
Test Utility Structure
| Path | Purpose |
|---|
__tests__/fixtures/ | Mock data builders |
__tests__/utils/ | Test helper functions |
Rules:
- No inline helpers in test files - use shared locations
- Check existing utilities before creating new ones
- Support
overrides parameter for customization
Code Examples
Based on detected framework, read the corresponding reference file (paths relative to .claude/skills/tdd/):
Note: Reference examples use English test descriptions for universal accessibility. When writing actual tests, follow the Output Language Rules below.
Output Language Rules
| Item | Language |
|---|
Test descriptions (it, describe) | Korean |
| Variable/function names | English |
| Code comments | Korean |
Quality Checklist
Before completing tests: