| name | vitest-testing |
| description | **AI-friendly comprehensive testing guidance for Vitest with practical patterns and behavior-driven development.** |
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
Most Referenced Patterns
📚 Skill Organization
Core Principles /principles/
Foundation concepts that guide all testing decisions:
Testing Strategies /strategies/
Approaches for different testing scenarios:
Practical Patterns /patterns/
Ready-to-use patterns for common scenarios:
Refactoring for Testability /refactoring/
Transform untestable code into testable code:
Quick Reference /quick-reference/
Fast lookups and decision aids:
🤖 Agent Integration Points
For typescript-coder Agent
When writing tests:
const testType = checkDecisionTree(codeType)
ensureTestsAreFast()
ensureTestsAreIsolated()
testThroughPublicAPI()
When refactoring:
if (isHardToTest(code)) {
applyPattern(testabilityPatterns)
}
For Code Review Agents
Check these aspects:
🎯 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
describe('UserService.register', () => {
it('creates user and sends welcome email', async () => {
const mockDb = { users: { create: vi.fn().mockResolvedValue({...}) } }
const mockEmailer = { sendWelcome: vi.fn() }
const service = new UserService(mockDb, mockEmailer)
const user = await service.register({ email: 'test@example.com' })
expect(mockDb.users.create).toHaveBeenCalled()
expect(mockEmailer.sendWelcome).toHaveBeenCalledWith('test@example.com')
})
})
(, () => {
service = (mockDb, mockEmailer)
(service.({ : }))
..()
})
Example 2: Agent Refactoring Code
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 })
}
}
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 })
}
}
describe('calculateOrderTotal', {
it.([
[{ : [{ : , : }] }, ],
[{ : [{ : , : }] }, ],
])(, {
((order)).(expected)
})
})
🔗 External Resources
📋 Agent Checklist
When generating tests, ensure:
🎯 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.