csp-tddlisted
Install: claude install-skill maythyai/code-skills-package
| Test Layer | Scope | When to Write |
|------------|-------|---------------|
| **Unit** | Individual functions, component logic, pure helpers | Always |
| **Integration** | API endpoints, database operations, service interactions | Always |
| **E2E** | Critical user flows (Playwright/Cypress) | Critical paths |
## Coverage Requirements
- Minimum **80%** coverage (branches, functions, lines, statements)
- All edge cases covered
- Error scenarios tested
- Boundary conditions verified
```bash
npm run test:coverage
# Verify 80%+ achieved
```
## Edge Cases You MUST Test
1. **Null/Undefined** input
2. **Empty** arrays/strings
3. **Invalid types** passed
4. **Boundary values** (min/max)
5. **Error paths** (network failures, DB errors)
6. **Race conditions** (concurrent operations)
7. **Large data** (performance with 10k+ items)
8. **Special characters** (Unicode, emojis, SQL chars)
## Test File Organization
```
src/
├── components/
│ └── Button/
│ ├── Button.tsx
│ └── Button.test.tsx # Unit tests
├── app/api/markets/
│ ├── route.ts
│ └── route.test.ts # Integration tests
└── e2e/
└── markets.spec.ts # E2E tests
```
## Mocking External Services
```typescript
// Supabase mock
jest.mock('@/lib/supabase', () => ({
supabase: {
from: jest.fn(() => ({
select: jest.fn(() => ({
eq: jest.fn(() => Promise.resolve({ data: [], error: null }))
}))
}))
}
}))
```
Always mock: external APIs, database