vitest

Write, configure, and run Vitest unit tests with mocking, coverage, and fixtures.

1|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/TierOne-Studio/spa-velocity --skill vitest-tierone-studio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/TierOne-Studio/spa-velocity/tree/main/.ruler/skills/vitest
Command: npx skills add https://github.com/TierOne-Studio/spa-velocity --skill vitest-tierone-studio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and maintaining a fast, Vite-native test suite requires knowing Vitest's configuration options, APIs, and mocking utilities, which are spread across extensive documentation. This Skill consolidates that knowledge so you can write tests, configure coverage, mock modules, and structure multi-project workspaces without leaving your workflow. ## Core Features & Use Cases - Test Authoring: Covers the test/describe/expect APIs, lifecycle hooks, parameterized tests with test.each and test.for, and custom fixtures via test.extend. - Mocking & Utilities: Guides module mocking with vi.mock, spying with vi.spyOn, fake timers, date mocking, and environment variable stubbing. - Coverage & Execution: Explains V8 and Istanbul coverage providers, thresholds, sharding for CI, concurrent tests, and test filtering by name, file, or tags. - Use Case: You need to add tests to a React component library. Use this Skill to configure jsdom as the test environment, write component tests with expect assertions, mock API calls with vi.mock, and enforce an 80% coverage threshold in CI. ## Quick Start Use the vitest skill to help me write a test file with mocked API calls and configure coverage thresholds in my vitest.config.ts.

Frequently Asked Questions about vitest

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I mock a module in Vitest?

Use vi.mock with a factory function, which is hoisted to the top of the file before imports run. For partial mocks, call importOriginal inside the factory and spread the actual module. Use vi.doMock for non-hoisted dynamic mocking with await import.

How to set up code coverage in Vitest?

Install @vitest/coverage-v8 and run vitest run --coverage, or set coverage.enabled to true in vitest.config.ts. V8 is the default faster provider; Istanbul offers broader compatibility. Configure reporters, include patterns, and thresholds under the coverage key.

Does Vitest support jsdom for testing DOM code?

Yes, set environment to 'jsdom' in your config or add a // @vitest-environment jsdom comment at the top of a test file. happy-dom is a faster alternative with fewer APIs. Install jsdom or happy-dom as a dev dependency first.

Vitest vs Jest: can I migrate my existing tests?

Vitest provides a Jest-compatible API, so most test suites work as drop-in replacements using the same describe, test, and expect functions. It adds native ESM and TypeScript support and shares your Vite config, transformers, and plugins.

Why is vi.mock not working with my variables?

vi.mock calls are hoisted above imports, so they cannot reference variables declared later in the file. Wrap shared mock values in vi.hoisted so they are defined before the mock factory executes.

How do I run only specific tests in Vitest?

Use vitest -t "pattern" to filter by test name, pass a file path or filename substring as a positional argument, or add test.only to focus a single test. The --changed flag runs tests affected by uncommitted changes, and --tags filters by custom tags.