agentsclimarketplace

Vitest testing

Skill aiskillstore/marketplace/skills/adammanuel-dev/vitest-testing

Security-audited skills for Claude, Codex & Claude Code. One-click install, quality verified.

Install
npx -y skills add aiskillstore/marketplace --skill vitest-testing

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

What its author says it does

Copied from the file, not written here

**AI-friendly comprehensive testing guidance for Vitest with practical patterns and behavior-driven development.**

SKILL.md

15.7 KB, as published. Nobody here has run it

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:

FilePurposeWhen to Use
first-principles.mdF.I.R.S.T quality attributesEvery test
aaa-pattern.mdArrange-Act-Assert structureStructuring tests
bdd-integration.mdGiven/When/Then with AAABusiness-focused tests

Testing Strategies /strategies/

Approaches for different testing scenarios:

FilePurposeWhen to Use
black-box-testing.mdTesting via public APIsDefault approach (99% of tests)
implementation-details.mdWhen to test internalsRare exceptions only

Practical Patterns /patterns/

Ready-to-use patterns for common scenarios:

FilePurposeWhen to Use
test-doubles.mdMocks, stubs, spies, fakesIsolating dependencies
async-testing.mdTesting promises, async/awaitAsync operations
error-testing.mdTesting exceptions, edge casesError scenarios
component-testing.mdReact/Vue component patternsUI components
api-testing.mdHTTP clients, REST APIsAPI integration
performance-testing.mdBenchmarks, load testingPerformance-critical code
test-data.mdFactories, builders, fixturesTest data management

Refactoring for Testability /refactoring/

Transform untestable code into testable code:

FilePurposeWhen to Use
testability-patterns.mdExtract pure functions, DI, etc.Code hard to test

Quick Reference /quick-reference/

Fast lookups and decision aids:

FilePurposeWhen to Use
cheatsheet.mdSyntax, matchers, mockingQuick syntax lookup
jest-to-vitest.mdMigration from JestMigrating 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

  1. F.I.R.S.T Principles - Understand quality attributes
  2. AAA Pattern - Learn test structure
  3. Cheatsheet - Basic syntax
  4. Test Doubles - Mocking basics

For Intermediate Developers

  1. Black Box Testing - Strategy
  2. BDD Integration - Business focus
  3. Async Testing - Handle promises
  4. Component Testing - UI testing

For Advanced Developers

  1. Testability Patterns - Design for testability
  2. Implementation Details - Rare exceptions
  3. Performance Testing - Benchmarking
  4. 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: '[email protected]' })

    // ASSERT
    expect(mockDb.users.create).toHaveBeenCalled()
    expect(mockEmailer.sendWelcome).toHaveBeenCalledWith('[email protected]')
  })
})

// 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


πŸ“‹ Agent Checklist

When generating tests, ensure:


🎯 Common Agent Tasks

Task: Generate Unit Test

  1. Read index.md β†’ Identify test type
  2. Apply first-principles.md β†’ F.I.R.S.T
  3. Structure with aaa-pattern.md
  4. Mock using test-doubles.md
  5. Reference cheatsheet.md for syntax

Task: Generate Component Test

  1. Read component-testing.md
  2. Use Testing Library queries
  3. Test user interactions
  4. Handle async operations
  5. Cover error states

Task: Refactor for Testability

  1. Read testability-patterns.md
  2. Identify pattern (extract, inject, wrap)
  3. Apply refactoring
  4. Generate tests for refactored code

Task: Review Test Quality

  1. Check F.I.R.S.T compliance
  2. Verify AAA structure
  3. Ensure black box approach
  4. Validate mock usage
  5. 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.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.