Use when writing unit/integration tests for Vite projects - configure vitest.config.ts, write test suites with describe/it, create mock implementations with vi.fn and vi.mock, set up code coverage thresholds, and run tests in parallel
Detected risks:
The Vitest skill provides a Vite-native testing framework designed to simplify unit and integration testing within Vite projects. It offers a Jest-compatible API that allows developers to configure test environments, write test suites, mock modules, and manage code coverage with minimal setup. By integrating seamlessly with modern JavaScript frameworks, Vitest addresses the challenge of efficiently testing frontend and backend components while maintaining compatibility with TypeScript and DOM-based tests.
Vitest includes several key capabilities: configuration through vitest.config.ts, writing test suites using describe and it blocks, creating mocks with vi.fn and vi.mock, handling timers and spies, setting coverage thresholds, and executing tests in parallel. The framework supports testing of Vue, React, and Svelte components and provides utilities for assertions, snapshots, and filtering tests. It also allows for type testing with TypeScript and can run in different environments, including Node and jsdom, making it versatile for both server-side and browser-like testing scenarios.
This skill is particularly useful for frontend developers, full-stack engineers, and teams working on Vite-based projects who need a reliable and efficient testing solution. It suits developers aiming to maintain high code quality, implement robust unit and integration tests, and perform advanced mocking and coverage analysis. By leveraging Vitest, users can accelerate test-driven development workflows and ensure consistent behavior across complex applications while integrating easily with existing Vite configurations.
Install Vitest using 'npm i -D vitest' and create a vitest.config.ts file to configure globals and environment settings. For example, set 'environment' to 'node' for server tests or 'jsdom' for DOM-related tests.
Yes, Vitest supports TypeScript type testing and works with Vue, React, and Svelte components, allowing you to write typed tests and component-specific test suites.
You can create mock implementations using 'vi.fn' for functions and 'vi.mock' for modules. Vitest also supports mocking timers, dates, and using spies for detailed test behavior verification.
Yes, Vitest is designed to execute tests in parallel, which helps speed up test runs, especially for large projects with many test suites.
Vitest requires a Vite project setup and works best in Node or jsdom environments. Browser-specific tests may need jsdom configuration, and TypeScript tests require proper type setup.
Quick Setup:
.claude/skills/Repository
onmax/nuxt-skills