.claude/skills-en/frontend-typescript-testing/SKILL.md
Designs tests with React Testing Library, MSW, and Playwright E2E. Applies component testing and E2E testing patterns.
npx skillsauth add shinpr/ai-coding-project-boilerplate frontend-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.
| Test Type | Reference | When to Use | |-----------|-----------|-------------| | Unit / Integration | This document | Implementing React component tests with RTL + Vitest + MSW | | E2E | references/e2e.md | Implementing browser-level E2E tests with Playwright |
import { describe, it, expect, beforeEach, vi } from 'vitest'import { render, screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'vi.mock()Mandatory: Unit test coverage must be 60% or higher Component-specific targets:
Metrics: Statements, Branches, Functions, Lines
Unit Tests (React Testing Library)
Integration Tests (React Testing Library + MSW)
Cross-functional Verification in E2E Tests
src/
└── components/
└── Button/
├── Button.tsx
├── Button.test.tsx # Co-located with component
└── index.ts
Rationale:
{ComponentName}.test.tsx{FeatureName}.integration.test.tsxRecommended: Keep all tests always active
Avoid: test.skip() or commenting out
// Type-safe MSW handler (MSW v2)
import { http, HttpResponse } from 'msw'
const handlers = [
http.get('/api/users/:id', () => {
return HttpResponse.json({ id: '1', name: 'John' } satisfies User)
})
]
// Only required parts
type TestProps = Pick<ButtonProps, 'label' | 'onClick'>
const mockProps: TestProps = { label: 'Click', onClick: vi.fn() }
// Only when absolutely necessary, with clear justification
const mockRouter = {
push: vi.fn()
} as unknown as Router // Complex router type structure
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Button } from './Button'
describe('Button', () => {
it('should call onClick when clicked', async () => {
const user = userEvent.setup()
const onClick = vi.fn()
render(<Button label="Click me" onClick={onClick} />)
await user.click(screen.getByRole('button', { name: 'Click me' }))
expect(onClick).toHaveBeenCalledOnce()
})
})
// Correct: test user-visible results
it('increments count when clicked', async () => {
const user = userEvent.setup()
render(<Counter />)
await user.click(screen.getByRole('button', { name: '+' }))
expect(screen.getByText('Count: 1')).toBeInTheDocument()
})
// Avoid: testing implementation details
it('calls setState', () => {
const setState = vi.spyOn(React, 'useState')
render(<Counter />)
// ...
})
development
Vitestテスト設計と品質基準を適用。カバレッジ要件とモック使用ガイドを提供。ユニットテスト作成時に使用。
development
型安全性とエラーハンドリングルールを適用。any禁止、型ガード必須。TypeScript実装、型定義レビュー時に使用。
tools
環境変数、アーキテクチャ設計、ビルド・テストコマンドを定義。環境設定、アーキテクチャ設計時に使用。
tools
タスクの本質を分析し適切なスキルを選択。規模見積もりとメタデータを返却。タスク開始時、スキル選択時に使用。