vitest
Vitest testing patterns for reliable unit and integration tests. Focuses on critical business logic, edge cases, and mocking strategies for high-impact functions.
Introduction
This skill provides a structured approach to testing TypeScript applications using Vitest. It emphasizes a pragmatic testing philosophy where development effort is concentrated on high-value, high-risk code paths rather than chasing arbitrary coverage metrics. The skill assists AI coding agents in writing resilient tests for business logic, data transformations, Zod schemas, and complex utility functions, while providing clear patterns for mocking external services and handling asynchronous operations. It promotes a test-driven development workflow through standardized file organization, naming conventions, and helper functions like test data factories.
-
Implements effective mocking strategies using vi.mock and vi.spyOn to isolate units and verify service interactions.
-
Provides robust patterns for testing asynchronous functions, including error handling, network request simulations, and promise-based assertions.
-
Includes templates for validating Zod schemas and complex validation logic to prevent regressions in data integrity.
-
Offers structured guidance for defining test data factories to maintain cleaner, more maintainable test suites.
-
Configures standard CLI workflows for running tests, including watch mode, filtering by file, and generating coverage reports.
-
Use this skill when implementing new features or refactoring legacy modules to ensure core stability.
-
Prioritize tests for validation functions, complex business logic, and code where bugs are statistically likely to be costly.
-
Skip tests for trivial getters, setters, or pass-through functions to maintain a high signal-to-noise ratio in the CI/CD pipeline.
-
Always co-locate test files (e.g., source.ts and source.test.ts) to improve project discoverability and maintainability.
-
Remember to reset mocks in each test cycle using beforeEach and vi.clearAllMocks to prevent cross-test interference.
Repository Stats
- Stars
- 1
- Forks
- 0
- Open Issues
- 0
- Language
- JavaScript
- Default Branch
- main
- Sync Status
- Idle
- Last Synced
- May 3, 2026, 07:31 PM