vitest

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

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/samline/forms --skill vitest-samline
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/samline/forms/tree/main/.agents/skills/vitest
Command: npx skills add https://github.com/samline/forms --skill vitest-samline

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and maintaining a fast, modern test suite requires deep knowledge of Vitest's configuration options, mocking APIs, coverage providers, and advanced features like fixtures and projects, which are spread across extensive documentation. ## Core Features & Use Cases - Test Authoring: Covers the test/describe/expect APIs, lifecycle hooks, parameterized tests, and Jest-compatible assertions with native ESM and TypeScript support. - Mocking & Utilities: Provides patterns for vi.fn, vi.spyOn, module mocking, fake timers, stubbed globals, and environment variables. - Coverage, Filtering & Projects: Explains V8/Istanbul coverage setup, test filtering by name or tags, sharding for CI, and multi-project workspace configurations. - Use Case: When migrating a Jest test suite to Vitest, use this Skill to configure vitest.config.ts, rewrite mocks with vi utilities, and set up coverage thresholds in one pass. ## Quick Start Use the vitest skill to write a test file with mocked API calls and configure coverage for my project.

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, spread the result of importOriginal and override specific exports; use vi.doMock for non-hoisted dynamic mocking with await import.

How to set up code coverage in Vitest?▼

Install @vitest/coverage-v8 or @vitest/coverage-istanbul, then run vitest with the --coverage flag or set coverage.enabled in the config. Configure reporters, include/exclude patterns, and thresholds under the test.coverage option.

Is Vitest compatible with Jest test suites?▼

Vitest provides a Jest-compatible API, so most test suites using describe, it, expect, and jest.mock-style patterns work as drop-in replacements. Mocks use the vi helper instead of jest, and configuration moves into vitest.config.ts or vite.config.ts.

Does Vitest support testing DOM code without a browser?▼

Yes, set the environment option to jsdom or happy-dom in the config, or add a // @vitest-environment comment per file. jsdom offers fuller browser API simulation while happy-dom runs faster with fewer APIs.

Why do my Vitest fake timers not trigger async callbacks?▼

Synchronous advanceTimersByTime does not await promise callbacks inside timers. Use await vi.advanceTimersByTimeAsync or vi.runAllTimersAsync so microtasks scheduled by timer callbacks resolve before assertions run.

How do I run only specific tests in Vitest?▼

Pass a filename pattern as a CLI argument, use -t or --testNamePattern for test names, or add test.only in the file. You can also filter by tags with --tags, by changed files with --changed, or list matches without running via vitest list.