Install any skill in seconds. Free to start, no credit card required.
Get Started Free →**AI-friendly comprehensive testing guidance for Vitest with practical patterns and behavior-driven development.**
.claude/skills/aiskillstore-vitest-testing/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 259% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 241% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 260% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 287% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 249% | 0% |
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
/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 |
/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 |
/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/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/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 |
When writing tests:
typescript// 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:
typescript// Check if code is testable if (isHardToTest(code)) { // Apply testability patterns applyPattern(testabilityPatterns) // Reference: /skills/vitest-testing/refactoring/testability-patterns.md }
Check these aspects:
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)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 test1. 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 releasedThis skill follows these core beliefs:
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.
Every principle includes practical examples. Before/after refactoring shows impact. Complete examples provide working templates.
Code that's hard to test is poorly designed. Refactoring patterns transform untestable code. Testability improvements enhance overall code quality.
Fast, Isolated, Repeatable, Self-Checking, Timely tests create a valuable safety net that developers trust and maintain.
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 guideFiles Created: 20+ Coverage:
Integration:
typescript// 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) })
typescript// 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) }) })
When generating tests, ensure:
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)
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 testMixed 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.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 10,530 | 8,584 | -18% | 1 | 1 | 0% | 1,807 | 6,169 | +241% | 0 | 0 | — |
case-02 | pass→pass | 10,657 | 11,284 | +6% | 1 | 1 | 0% | 1,763 | 6,344 | +260% | 0 | 0 | — |
case-03 | pass→pass | 9,873 | 10,914 | +11% | 1 | 1 | 0% | 1,641 | 6,345 | +287% | 0 | 0 | — |
case-04 | fail→pass | 9,005 | 7,144 | -21% | 1 | 1 | 0% | 1,564 | 5,622 | +259% | 0 | 0 | — |
case-05 | pass→pass | 9,693 | 8,746 | -10% | 1 | 1 | 0% | 1,700 | 5,939 | +249% | 0 | 0 | — |
case-06 | pass→pass | 14,417 | 15,515 | +8% | 1 | 1 | 0% | 2,515 | 7,480 | +197% | 0 | 0 | — |
case-07 | pass→pass | 8,446 | 9,027 | +7% | 1 | 1 | 0% | 1,608 | 6,101 | +279% | 0 | 0 | — |
case-08 | pass→pass | 6,115 | 6,816 | +11% | 1 | 1 | 0% | 1,078 | 5,603 | +420% | 0 | 0 | — |
case-09 | pass→pass | 10,661 | 7,480 | -30% | 1 | 1 | 0% | 1,945 | 5,726 | +194% | 0 | 0 | — |
case-10 | pass→pass | 9,349 | 9,639 | +3% | 1 | 1 | 0% | 1,486 | 6,164 | +315% | 0 | 0 | — |
case-11 | pass→pass | 11,346 | 12,311 | +9% | 1 | 1 | 0% | 2,034 | 6,658 | +227% | 0 | 0 | — |
case-12 | pass→pass | 10,253 | 10,771 | +5% | 1 | 1 | 0% | 2,002 | 6,569 | +228% | 0 | 0 | — |
case-13 | pass→pass | 8,175 | 8,480 | +4% | 1 | 1 | 0% | 1,345 | 5,904 | +339% | 0 | 0 | — |
case-14 | pass→pass | 11,104 | 8,615 | -22% | 1 | 1 | 0% | 1,928 | 5,964 | +209% | 0 | 0 | — |
case-15 | pass→pass | 11,607 | 7,298 | -37% | 1 | 1 | 0% | 1,861 | 5,457 | +193% | 0 | 0 | — |
case-16 | pass→pass | 10,196 | 8,527 | -16% | 1 | 1 | 0% | 1,792 | 5,935 | +231% | 0 | 0 | — |
case-17 | pass→pass | 10,388 | 11,422 | +10% | 1 | 1 | 0% | 1,669 | 6,276 | +276% | 0 | 0 | — |
case-18 | pass→pass | 8,365 | 8,625 | +3% | 1 | 1 | 0% | 1,454 | 5,728 | +294% | 0 | 0 | — |
case-19 | pass→pass | 12,813 | 9,324 | -27% | 1 | 1 | 0% | 2,277 | 6,010 | +164% | 0 | 0 | — |
case-20 | fail→fail | 10,876 | 11,592 | +7% | 1 | 1 | 0% | 2,239 | 6,701 | +199% | 0 | 0 | — |
case-21 | fail→fail | 7,348 | 9,516 | +30% | 1 | 1 | 0% | 1,588 | 6,293 | +296% | 0 | 0 | — |
case-22 | fail→fail | 14,427 | 13,241 | -8% | 1 | 1 | 0% | 3,148 | 7,165 | +128% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +5 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.