| name | testing-patterns |
| description | Testing patterns for Jest unit and integration tests. Use when writing tests, setting up test fixtures, or validating implementations. Jest only -- tests in `tests/` directory. |
Testing Patterns Skill
Purpose
Guide consistent and effective testing. Routes to existing test patterns and provides evidence templates.
When This Skill Applies
- Writing unit or integration tests
- Setting up test fixtures
- Running test suites
- Packaging test evidence
Critical Rules
FORBIDDEN
let sharedData: any;
beforeAll(() => { sharedData = createData(); });
const userId = "user-123";
CORRECT
beforeEach(() => {
const testData = createTestData();
});
const userId = `user-${crypto.randomUUID()}`;
Test Commands
npm test
npm run test:watch
npx jest tests/specific-file.test.ts
npx jest --testPathPattern="keyword"
npm test -- --coverage
Coverage Thresholds
| Metric | Threshold |
|---|
| Branches | 70% |
| Functions | 80% |
| Lines | 80% |
| Statements | 80% |
Test Directory Structure
tests/
├── unit/ # Fast, isolated tests
├── integration/ # API and database tests
└── setup.ts # Global setup
Evidence Template
**Test Execution Evidence**
**Test Suite**: [unit/integration]
**Files Changed**: [list files]
**Test Results:**
- Total Tests: [X]
- Passed: [X]
- Failed: [0]
**Commands Run:**
```bash
npm test -- --coverage
## Reference
- **Jest Config**: `jest.config.js`
- **Test Directory**: `tests/`