Vitest Unit Testing
Write fast unit tests with Vitest — the Vite-native test runner. Generates test suites with mocking, spying, snapshot testing, code coverage, and in-source testing with native ESM and TypeScript support.
This skill helps you build comprehensive unit test suites with Vitest. It generates test files with proper mocking (vi.mock, vi.spyOn), creates snapshot tests, configures code coverage thresholds, implements test fixtures, and sets up watch mode for TDD workflows. Native ESM support means no transpilation issues.
When to use
Use when writing unit tests for TypeScript/JavaScript projects, migrating from Jest for faster test execution, implementing TDD workflows, or setting up coverage reporting in CI.
Examples
Mock external dependencies
Set up module and API mocking for isolated tests
Write Vitest tests for a service that calls external APIs — mock the HTTP client, test success and error paths, and verify retry logic
Coverage configuration
Set up coverage thresholds and reporting
Configure Vitest with 80% coverage thresholds for branches, lines, and functions — fail CI if coverage drops below threshold