Agent skill
typescript-testing
Jest and Vitest testing policies for TypeScript/JavaScript. Use when writing or reviewing TS/JS test code. Do NOT use for application code -- use typescript-patterns instead.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/typescript-testing
SKILL.md
TypeScript/JavaScript Testing Policies
Test Structure (AAA Pattern)
describe('UserService', () => {
describe('createUser', () => {
it('creates user with valid input', async () => {
// Arrange
const input = { name: 'Alice', email: '[email protected]' }
// Act
const user = await userService.createUser(input)
// Assert
expect(user.id).toBeDefined()
})
})
})
Mocking Policies
Mock Cleanup (REQUIRED)
afterEach(() => {
jest.clearAllMocks() // Vitest: vi.clearAllMocks()
jest.restoreAllMocks() // Vitest: vi.restoreAllMocks()
})
Prefer spyOn Over Full Mocks
// GOOD: Spy on specific method
const spy = jest.spyOn(service, 'save')
// AVOID: Full module mock when not needed
jest.mock('./service')
Async Testing
// Use async/await
it('fetches data', async () => {
const data = await fetchData()
expect(data).toBeDefined()
})
// Use rejects for error cases
await expect(fetchData()).rejects.toThrow('Network error')
Coverage Targets
| Metric | Target |
|---|---|
| Lines | 80%+ |
| Branches | 80%+ |
| Functions | 80%+ |
Commands
See makefile-first skill for command execution policy.
Vitest Bench
vitest bench # Run all benchmarks
vitest bench --reporter=verbose # Detailed output
When to Write Benchmarks
- Comparing alternative implementations (data structures, algorithms)
- Validating that an optimization actually improved performance
- Establishing baseline for performance-critical paths
- Preventing regression in hot paths
Benchmark Options
bench('operation', () => { /* code */ }, {
time: 1000, // ms to run (default: 100)
iterations: 100, // minimum iterations
warmupTime: 200, // warmup before measuring
})
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?