vitest-testing
Vitestを使ったテストに関するAIフレンドリーな包括的なガイドで、実践的なパターンや振る舞い駆動開発(BDD)を取り入れ、より効率的で信頼性の高いテストを構築するSkill。
📜 元の英語説明(参考)
**AI-friendly comprehensive testing guidance for Vitest with practical patterns and behavior-driven development.**
🇯🇵 日本人クリエイター向け解説
Vitestを使ったテストに関するAIフレンドリーな包括的なガイドで、実践的なパターンや振る舞い駆動開発(BDD)を取り入れ、より効率的で信頼性の高いテストを構築するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o vitest-testing.zip https://jpskill.com/download/17005.zip && unzip -o vitest-testing.zip && rm vitest-testing.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17005.zip -OutFile "$d\vitest-testing.zip"; Expand-Archive "$d\vitest-testing.zip" -DestinationPath $d -Force; ri "$d\vitest-testing.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
vitest-testing.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
vitest-testingフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 2
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Vitest テストスキル - マスターリファレンス
Vitest のための AI フレンドリーな包括的なテストガイダンス。実践的なパターンと振る舞い駆動開発を含みます。
人間向け: 全体的なナビゲーションについては README.md から始めてください AI エージェント向け: このファイルは、すべてのスキルリソースへのクイックアクセスを提供します
🎯 エージェントのためのクイックアクセス
意思決定支援
- どのような種類のテストを書くべきか? → index.md
- このテストをどのように構成すべきか? → principles/aaa-pattern.md
- このコードはテスト可能か? → refactoring/testability-patterns.md
最も参照されるパターン
- F.I.R.S.T Principles - 高速(Fast)、独立(Isolated)、反復可能(Repeatable)、自己検証(Self-Checking)、タイムリー(Timely)
- AAA Pattern - Arrange-Act-Assert 構造
- Black Box Testing - パブリック API を通じた振る舞いのテスト
- Test Doubles - モック、スタブ、スパイ、フェイク
📚 スキルの構成
コア原則 /principles/
すべてのテストの意思決定を導く基礎となる概念:
| ファイル | 目的 | いつ使用するか |
|---|---|---|
| first-principles.md | F.I.R.S.T 品質属性 | すべてのテスト |
| aaa-pattern.md | Arrange-Act-Assert 構造 | テストの構成 |
| bdd-integration.md | AAA を用いた Given/When/Then | ビジネスに焦点を当てたテスト |
テスト戦略 /strategies/
さまざまなテストシナリオへのアプローチ:
| ファイル | 目的 | いつ使用するか |
|---|---|---|
| black-box-testing.md | パブリック API を介したテスト | デフォルトのアプローチ (テストの 99%) |
| implementation-details.md | 内部をテストする場合 | まれな例外のみ |
実践的なパターン /patterns/
一般的なシナリオですぐに使用できるパターン:
| ファイル | 目的 | いつ使用するか |
|---|---|---|
| test-doubles.md | モック、スタブ、スパイ、フェイク | 依存関係の分離 |
| async-testing.md | Promise、async/await のテスト | 非同期操作 |
| error-testing.md | 例外、エッジケースのテスト | エラーシナリオ |
| component-testing.md | React/Vue コンポーネントパターン | UI コンポーネント |
| api-testing.md | HTTP クライアント、REST API | API 連携 |
| performance-testing.md | ベンチマーク、負荷テスト | パフォーマンスが重要なコード |
| test-data.md | ファクトリ、ビルダー、フィクスチャ | テストデータ管理 |
テスト容易性のためのリファクタリング /refactoring/
テストできないコードをテスト可能なコードに変換する:
| ファイル | 目的 | いつ使用するか |
|---|---|---|
| testability-patterns.md | 純粋関数の抽出、DI など | テストが難しいコード |
クイックリファレンス /quick-reference/
迅速な検索と意思決定支援:
| ファイル | 目的 | いつ使用するか |
|---|---|---|
| cheatsheet.md | 構文、マッチャー、モック | 構文のクイック検索 |
| jest-to-vitest.md | Jest からの移行 | プロジェクトの移行 |
🤖 エージェント連携ポイント
typescript-coder エージェント向け
テストの作成時:
// 1. 意思決定木を確認
const testType = checkDecisionTree(codeType)
// 参照: /skills/vitest-testing/index.md
// 2. F.I.R.S.T 原則を適用
ensureTestsAreFast() // < 100ms
ensureTestsAreIsolated() // 共有状態なし
// 参照: /skills/vitest-testing/principles/first-principles.md
// 3. AAA 構造を使用
// Arrange → Act → Assert
// 参照: /skills/vitest-testing/principles/aaa-pattern.md
// 4. ブラックボックステスト戦略に従う
testThroughPublicAPI() // プライベートメソッドではない
// 参照: /skills/vitest-testing/strategies/black-box-testing.md
リファクタリング時:
// コードがテスト可能かどうかを確認
if (isHardToTest(code)) {
// テスト容易性パターンを適用
applyPattern(testabilityPatterns)
// 参照: /skills/vitest-testing/refactoring/testability-patterns.md
}
コードレビューエージェント向け
以下の側面を確認してください:
- [ ] テストは F.I.R.S.T 原則に従っているか
- [ ] テストは AAA 構造を使用しているか
- [ ] テストはブラックボックスアプローチを使用しているか (パブリック API のみ)
- [ ] 外部依存関係の適切なモック
- [ ] エラーシナリオが網羅されているか
- [ ] 非同期操作が正しく処理されているか
🎯 一般的なワークフロー
ワークフロー 1: 新機能のテストの作成
1. 意思決定木を参照 → /skills/vitest-testing/index.md
2. テストタイプを決定 → Unit/Integration/Component
3. F.I.R.S.T 原則を適用 → /skills/vitest-testing/principles/first-principles.md
4. AAA で構造化 → /skills/vitest-testing/principles/aaa-pattern.md
5. 関連するパターンを使用 → /skills/vitest-testing/patterns/
6. サンプルを参照 → /skills/vitest-testing/examples/ (作成された場合)
ワークフロー 2: テスト容易性のためのリファクタリング
1. 問題点を特定 → 何がテストを難しくしているか?
2. パターンを選択 → /skills/vitest-testing/refactoring/testability-patterns.md
3. パターンを適用 → 純粋関数の抽出、依存性の注入など
4. テストを作成 → リファクタリングされたコードのブラックボックステスト
5. 検証 → すべてのテストがパスし、コードがテストしやすくなる
ワークフロー 3: 非同期コードのテスト
1. 非同期パターンを確認 → /skills/vitest-testing/patterns/async-testing.md
2. 外部 API をモック → /skills/vitest-testing/patterns/test-doubles.md
3. タイミングを制御 → vi.useFakeTimers() を使用
4. 状態をテスト → Loading、success、error
5. クリーンアップを検証 → リソースが解放されている
📖 哲学
このスキルは、以下の核となる信念に従います。
1. 実装よりも振る舞い
テストは、コードがどのように動作するかではなく、コードが何をするかを検証する必要があります。観察可能な結果とパブリックコントラクトに焦点を当ててください。実装の詳細
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Vitest Testing Skill - Master Reference
AI-friendly comprehensive testing guidance for Vitest with practical patterns and behavior-driven development.
For humans: Start with README.md for full navigation For AI agents: This file provides quick access to all skill resources
🎯 Quick Access for Agents
Decision Support
- What type of test should I write? → index.md
- How do I structure this test? → principles/aaa-pattern.md
- Is this code testable? → refactoring/testability-patterns.md
Most Referenced Patterns
- F.I.R.S.T Principles - Fast, Isolated, Repeatable, Self-Checking, Timely
- AAA Pattern - Arrange-Act-Assert structure
- Black Box Testing - Test behavior through public APIs
- Test Doubles - Mocks, stubs, spies, fakes
📚 Skill Organization
Core Principles /principles/
Foundation concepts that guide all testing decisions:
| File | Purpose | When to Use |
|---|---|---|
| first-principles.md | F.I.R.S.T quality attributes | Every test |
| aaa-pattern.md | Arrange-Act-Assert structure | Structuring tests |
| bdd-integration.md | Given/When/Then with AAA | Business-focused tests |
Testing Strategies /strategies/
Approaches for different testing scenarios:
| File | Purpose | When to Use |
|---|---|---|
| black-box-testing.md | Testing via public APIs | Default approach (99% of tests) |
| implementation-details.md | When to test internals | Rare exceptions only |
Practical Patterns /patterns/
Ready-to-use patterns for common scenarios:
| File | Purpose | When to Use |
|---|---|---|
| test-doubles.md | Mocks, stubs, spies, fakes | Isolating dependencies |
| async-testing.md | Testing promises, async/await | Async operations |
| error-testing.md | Testing exceptions, edge cases | Error scenarios |
| component-testing.md | React/Vue component patterns | UI components |
| api-testing.md | HTTP clients, REST APIs | API integration |
| performance-testing.md | Benchmarks, load testing | Performance-critical code |
| test-data.md | Factories, builders, fixtures | Test data management |
Refactoring for Testability /refactoring/
Transform untestable code into testable code:
| File | Purpose | When to Use |
|---|---|---|
| testability-patterns.md | Extract pure functions, DI, etc. | Code hard to test |
Quick Reference /quick-reference/
Fast lookups and decision aids:
| File | Purpose | When to Use |
|---|---|---|
| cheatsheet.md | Syntax, matchers, mocking | Quick syntax lookup |
| jest-to-vitest.md | Migration from Jest | Migrating projects |
🤖 Agent Integration Points
For typescript-coder Agent
When writing tests:
// 1. Check decision tree
const testType = checkDecisionTree(codeType)
// Reference: /skills/vitest-testing/index.md
// 2. Apply F.I.R.S.T principles
ensureTestsAreFast() // < 100ms
ensureTestsAreIsolated() // No shared state
// Reference: /skills/vitest-testing/principles/first-principles.md
// 3. Use AAA structure
// Arrange → Act → Assert
// Reference: /skills/vitest-testing/principles/aaa-pattern.md
// 4. Follow black box strategy
testThroughPublicAPI() // Not private methods
// Reference: /skills/vitest-testing/strategies/black-box-testing.md
When refactoring:
// Check if code is testable
if (isHardToTest(code)) {
// Apply testability patterns
applyPattern(testabilityPatterns)
// Reference: /skills/vitest-testing/refactoring/testability-patterns.md
}
For Code Review Agents
Check these aspects:
- [ ] Tests follow F.I.R.S.T principles
- [ ] Tests use AAA structure
- [ ] Tests use black box approach (public APIs only)
- [ ] Proper mocking of external dependencies
- [ ] Error scenarios covered
- [ ] Async operations handled correctly
🎯 Common Workflows
Workflow 1: Writing Tests for New Feature
1. Consult decision tree → /skills/vitest-testing/index.md
2. Determine test type → Unit/Integration/Component
3. Apply F.I.R.S.T principles → /skills/vitest-testing/principles/first-principles.md
4. Structure with AAA → /skills/vitest-testing/principles/aaa-pattern.md
5. Use relevant pattern → /skills/vitest-testing/patterns/
6. Reference examples → /skills/vitest-testing/examples/ (when created)
Workflow 2: Refactoring for Testability
1. Identify pain points → What makes this hard to test?
2. Select pattern → /skills/vitest-testing/refactoring/testability-patterns.md
3. Apply pattern → Extract pure functions, inject dependencies, etc.
4. Write tests → Black box tests for refactored code
5. Verify → All tests pass, code is easier to test
Workflow 3: Testing Async Code
1. Check async patterns → /skills/vitest-testing/patterns/async-testing.md
2. Mock external APIs → /skills/vitest-testing/patterns/test-doubles.md
3. Control timing → Use vi.useFakeTimers()
4. Test states → Loading, success, error
5. Verify cleanup → Resources released
📖 Philosophy
This skill follows these core beliefs:
1. Behavior over Implementation
Tests should verify WHAT the code does, not HOW it does it. Focus on observable outcomes and public contracts. Implementation details should be testable indirectly through public APIs.
2. Example-Driven Learning
Every principle includes practical examples. Before/after refactoring shows impact. Complete examples provide working templates.
3. Testability by Design
Code that's hard to test is poorly designed. Refactoring patterns transform untestable code. Testability improvements enhance overall code quality.
4. F.I.R.S.T Quality
Fast, Isolated, Repeatable, Self-Checking, Timely tests create a valuable safety net that developers trust and maintain.
🔍 Skill Map
vitest-testing/
├── SKILL.md ← You are here (AI agent entry point)
├── README.md ← Human navigation hub
├── index.md ← Decision tree
├── principles/ ← Testing fundamentals
│ ├── first-principles.md ← F.I.R.S.T (most important)
│ ├── aaa-pattern.md ← Test structure
│ └── bdd-integration.md ← Given/When/Then
├── strategies/ ← Testing approaches
│ ├── black-box-testing.md ← Default strategy
│ └── implementation-details.md ← Rare exceptions
├── patterns/ ← Practical implementations
│ ├── test-doubles.md ← Mocking (highly referenced)
│ ├── component-testing.md ← React/UI testing
│ ├── async-testing.md ← Promises, async/await
│ ├── error-testing.md ← Error scenarios
│ ├── api-testing.md ← HTTP/API testing
│ ├── performance-testing.md ← Benchmarks, load tests
│ └── test-data.md ← Factories, builders
├── refactoring/ ← Making code testable
│ └── testability-patterns.md ← Extract, inject, isolate
└── quick-reference/ ← Fast lookups
├── cheatsheet.md ← Syntax reference
└── jest-to-vitest.md ← Migration guide
🎓 Learning Paths
For Beginners
- F.I.R.S.T Principles - Understand quality attributes
- AAA Pattern - Learn test structure
- Cheatsheet - Basic syntax
- Test Doubles - Mocking basics
For Intermediate Developers
- Black Box Testing - Strategy
- BDD Integration - Business focus
- Async Testing - Handle promises
- Component Testing - UI testing
For Advanced Developers
- Testability Patterns - Design for testability
- Implementation Details - Rare exceptions
- Performance Testing - Benchmarking
- Architecture Alignment - DDD/Clean Architecture
🚀 Integration with Other Skills
With architecture-patterns Skill
- Domain Models → Test business rules (black box)
- Aggregates → Test invariants
- Use Cases → Test orchestration with mocks
- Repositories → Test with in-memory implementations
With typescript-coder Agent
- Automatically references this skill for test generation
- Applies F.I.R.S.T principles
- Uses AAA structure
- Follows black box strategy
📊 Statistics
Files Created: 20+ Coverage:
- ✅ Core principles (F.I.R.S.T, AAA, BDD)
- ✅ Testing strategies (black box, implementation details)
- ✅ Practical patterns (mocks, async, errors, components, APIs, performance, test data)
- ✅ Refactoring guidance (testability patterns)
- ✅ Quick references (cheatsheet, migration guide)
Integration:
- ✅ typescript-coder agent updated
- ✅ Cross-references to architecture-patterns
- ✅ Decision trees for quick pattern selection
💡 Usage Examples for Agents
Example 1: Agent Writing a Test
// Agent receives: "Write a test for the UserService.register function"
// Step 1: Check decision tree (index.md)
// → New feature → Unit test (Black Box)
// Step 2: Apply F.I.R.S.T (first-principles.md)
// → Fast: Mock database
// → Isolated: Fresh mocks in beforeEach
// → Repeatable: Control time
// → Self-Checking: Use expect()
// → Timely: Write now
// Step 3: Use AAA pattern (aaa-pattern.md)
describe('UserService.register', () => {
it('creates user and sends welcome email', async () => {
// ARRANGE
const mockDb = { users: { create: vi.fn().mockResolvedValue({...}) } }
const mockEmailer = { sendWelcome: vi.fn() }
const service = new UserService(mockDb, mockEmailer)
// ACT
const user = await service.register({ email: 'test@example.com' })
// ASSERT
expect(mockDb.users.create).toHaveBeenCalled()
expect(mockEmailer.sendWelcome).toHaveBeenCalledWith('test@example.com')
})
})
// Step 4: Add error scenarios (error-testing.md)
it('throws ValidationError for invalid email', async () => {
const service = new UserService(mockDb, mockEmailer)
await expect(service.register({ email: 'invalid' }))
.rejects.toThrow(ValidationError)
})
Example 2: Agent Refactoring Code
// Agent receives: "Make this code testable"
// Step 1: Identify issue (testability-patterns.md)
// → Mixed logic and side effects
// Step 2: Apply Pattern 1: Extract Pure Functions
// Before:
class OrderService {
async processOrder(order) {
let total = 0
for (const item of order.items) {
total += item.price * item.quantity
}
await this.db.save({ ...order, total })
}
}
// After:
export function calculateOrderTotal(order) {
return order.items.reduce((sum, item) => sum + item.price * item.quantity, 0)
}
class OrderService {
async processOrder(order) {
const total = calculateOrderTotal(order)
await this.db.save({ ...order, total })
}
}
// Step 3: Write tests (black-box-testing.md)
describe('calculateOrderTotal', () => {
it.each([
[{ items: [{ price: 10, quantity: 2 }] }, 20],
[{ items: [{ price: 15, quantity: 3 }] }, 45],
])('calculates %o as %d', (order, expected) => {
expect(calculateOrderTotal(order)).toBe(expected)
})
})
🔗 External Resources
- Vitest Documentation - Official docs
- Testing Library - React/DOM testing
- MSW - API mocking
- @faker-js/faker - Test data generation
📋 Agent Checklist
When generating tests, ensure:
- [ ] Test follows F.I.R.S.T principles
- [ ] Test uses AAA structure
- [ ] Test uses black box approach
- [ ] External dependencies are mocked
- [ ] Error scenarios are covered
- [ ] Async operations handled correctly
- [ ] Test is fast (< 100ms), isolated, and repeatable
🎯 Common Agent Tasks
Task: Generate Unit Test
- Read index.md → Identify test type
- Apply first-principles.md → F.I.R.S.T
- Structure with aaa-pattern.md
- Mock using test-doubles.md
- Reference cheatsheet.md for syntax
Task: Generate Component Test
- Read component-testing.md
- Use Testing Library queries
- Test user interactions
- Handle async operations
- Cover error states
Task: Refactor for Testability
- Read testability-patterns.md
- Identify pattern (extract, inject, wrap)
- Apply refactoring
- Generate tests for refactored code
Task: Review Test Quality
- Check F.I.R.S.T compliance
- Verify AAA structure
- Ensure black box approach
- Validate mock usage
- Check error coverage
📖 Skill Metadata
Version: 1.0.0 Type: Testing guidance Framework: Vitest Language: TypeScript/JavaScript Integration: typescript-coder agent, architecture-patterns skill Status: Production ready (core files complete)
Files: 20+ markdown documents Categories: Principles (3), Strategies (2), Patterns (7), Refactoring (1), Quick Reference (2)
💡 Quick Decision Trees
"What test should I write?"
Is it a new feature?
└─ YES → Unit test (black box) + [index.md](index.md#new-feature)
Is it a bug fix?
└─ YES → Regression test + [index.md](index.md#bug-fix)
Is it async code?
└─ YES → [async-testing.md](patterns/async-testing.md)
Is it a React component?
└─ YES → [component-testing.md](patterns/component-testing.md)
Is it an API client?
└─ YES → [api-testing.md](patterns/api-testing.md)
Is it complex logic?
└─ YES → Extract pure function + black box test
"How do I make this testable?"
Mixed logic and side effects?
└─ [testability-patterns.md](refactoring/testability-patterns.md#pattern-1)
Hard-coded dependencies?
└─ [testability-patterns.md](refactoring/testability-patterns.md#pattern-2)
Complex private method?
└─ [testability-patterns.md](refactoring/testability-patterns.md#pattern-3)
Time-dependent code?
└─ [testability-patterns.md](refactoring/testability-patterns.md#pattern-5)
This is the master reference for AI agents. For human-friendly navigation, see README.md.
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (16,121 bytes)
- 📎 README.md (6,666 bytes)