.claude/skills-en/typescript-testing/SKILL.md
Applies Vitest test design and quality standards. Provides coverage requirements and mock usage guides. Use when writing unit tests.
npx skillsauth add shinpr/ai-coding-project-boilerplate typescript-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
import { describe, it, expect, beforeEach, vi } from 'vitest'vi.mock()Mandatory: Unit test coverage must be 70% or higher Metrics: Statements, Branches, Functions, Lines
Unit Tests
Integration Tests
Cross-functional Verification in E2E Tests
src/
└── application/
└── services/
├── __tests__/
│ ├── service.test.ts # Unit tests
│ └── service.int.test.ts # Integration tests
└── service.ts
{target-file-name}.test.ts{target-file-name}.int.test.tsRecommended: Keep all tests always active
Avoid: test.skip() or commenting out
Include boundary values and error cases alongside happy paths.
it('returns 0 for empty array', () => expect(calc([])).toBe(0))
it('throws on negative price', () => expect(() => calc([{price: -1}])).toThrow())
Use literal values for assertions. Do not replicate implementation logic. Valid test: Expected value != Mock return value (implementation transforms/processes data)
expect(calcTax(100)).toBe(10) // not: 100 * TAX_RATE
Verify results, not invocation order or count.
expect(mock).toHaveBeenCalledWith('a') // not: toHaveBeenNthCalledWith
Each test must include at least one verification.
it('creates user', async () => {
const user = await createUser({name: 'test'})
expect(user.id).toBeDefined()
})
Mock only direct external I/O dependencies. Use real implementations for indirect dependencies.
vi.mock('./database') // external I/O only
Use fast-check when verifying invariants or properties.
import fc from 'fast-check'
it('reverses twice equals original', () => {
fc.assert(fc.property(fc.array(fc.integer()), (arr) => {
return JSON.stringify(arr.reverse().reverse()) === JSON.stringify(arr)
}))
})
Usage condition: Use when Property annotations are assigned to ACs in Design Doc.
// Only required parts
type TestRepo = Pick<Repository, 'find' | 'save'>
const mock: TestRepo = { find: vi.fn(), save: vi.fn() }
// Only when absolutely necessary, with clear justification
const sdkMock = {
call: vi.fn()
} as unknown as ExternalSDK // Complex external SDK type structure
Mocks validate call patterns but cannot verify data layer correctness. The following pass through undetected with mock-only testing:
Options for verifying data layer correctness against a real database engine:
The appropriate approach depends on project environment and CI/CD capabilities.
import { describe, it, expect, vi } from 'vitest'
vi.mock('./userService', () => ({
getUserById: vi.fn(),
updateUser: vi.fn()
}))
describe('ComponentName', () => {
it('should follow AAA pattern', () => {
const input = 'test'
const result = someFunction(input)
expect(result).toBe('expected')
})
})
development
Vitestテスト設計と品質基準を適用。カバレッジ要件とモック使用ガイドを提供。ユニットテスト作成時に使用。
development
型安全性とエラーハンドリングルールを適用。any禁止、型ガード必須。TypeScript実装、型定義レビュー時に使用。
tools
環境変数、アーキテクチャ設計、ビルド・テストコマンドを定義。環境設定、アーキテクチャ設計時に使用。
tools
タスクの本質を分析し適切なスキルを選択。規模見積もりとメタデータを返却。タスク開始時、スキル選択時に使用。