vitest

Write, configure, and run Vitest unit tests with Vite-native tooling.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/falentio/cimi --skill vitest-falentio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/falentio/cimi/tree/main/.agents/skills/vitest
Command: npx skills add https://github.com/falentio/cimi --skill vitest-falentio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? It provides structured guidance for writing and running tests with Vitest, covering configuration, mocking, coverage, filtering, and advanced features so you avoid digging through scattered documentation. ## Core Features & Use Cases - Test Authoring: Use the test/describe/expect APIs, hooks, parameterized tests, fixtures, and lifecycle hooks with correct v4/v5 syntax. - Mocking & Utilities: Mock functions, modules, timers, dates, globals, and environment variables with vi utilities including vi.when and vi.hoisted. - Configuration & Execution: Configure environments (node, jsdom, happy-dom), coverage providers, projects for monorepos, sharding, reporters, and CLI filtering. - Use Case: When migrating a Jest test suite to Vitest, use this Skill to update config files, replace jest.mock calls with vi.mock, set up coverage thresholds, and configure CI sharding. ## Quick Start Use the vitest skill to help me write a test file with mocked API calls and configure coverage for my TypeScript 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 do I migrate from Jest to Vitest?

Vitest provides a Jest-compatible API, so most test files work by replacing jest imports with vitest equivalents like vi.fn and vi.spyOn. Update your config to vitest.config.ts and adjust coverage settings, since v4 removed coverage.all and requires explicit coverage.include.

Does Vitest support testing DOM code without a browser?

Yes, Vitest supports jsdom and happy-dom environments configured via the environment option or a per-file @vitest-environment comment. For real browser testing, use Vitest Browser Mode with the Playwright provider instead.

How do I run only specific tests in Vitest?

Filter by file path as a CLI argument, by test name with -t or --testNamePattern, or by declared tags with --tagsFilter. You can also use test.only in development, vitest --changed for modified files, and vitest related for tests importing specific files.

Why did my Vitest config break after upgrading to v4?

Vitest v4 removed poolOptions, the workspace option, and coverage.all, and changed the default pool to forks. Move pool settings to top-level options like maxWorkers, replace vitest.workspace.ts with test.projects, and define coverage.include explicitly.

How do I split Vitest tests across CI machines?

Use the --shard flag with index and count, such as vitest run --shard=1/3, on each machine with the blob reporter. Then merge results with vitest --merge-reports to produce a unified report including coverage.