vitest

Configure and diagnose Vitest 4 unit testing workflows for Vite projects.

15|2|Updated May 23, 2026
One-click install
npx skills add https://github.com/VKirill/antigravity-for-claude-code --skill vitest-vkirill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/VKirill/antigravity-for-claude-code/tree/main/skills/vitest
Command: npx skills add https://github.com/VKirill/antigravity-for-claude-code --skill vitest-vkirill

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Vitest 4 expertise prevents flaky, hard-to-debug test suites by guiding you through correct configuration, mocking, snapshots, browser mode, coverage, and v3→v4 breaking changes.

Core Features & Use Cases

  • Vitest 4 configuration: set up vitest.config.ts (environment, globals, setupFiles, discovery, timeouts) and use v4 pool syntax (pool + poolOptions).
  • Mocking done safely: use vi.mock, vi.fn, vi.spyOn, hoisting rules, vi.importActual, and typed helpers like vi.mocked.
  • Snapshots + coverage that actually match: handle snapshot v2 differences, update snapshots correctly, and choose coverage providers (v8 vs istanbul) with thresholds.
  • Multi-environment testing: use the projects API (monorepos and browser-vs-node scenarios) and avoid the obsolete workspace key.

Example: You upgraded to Vitest 4 and your monorepo tests start failing due to pool config changes, workspace being ignored, and spy state behaving differently; this skill routes you to the exact reference sections and migration steps to fix configuration and test isolation quickly.

Quick Start

Ask: "Configure Vitest 4 for a Vite project with jsdom, globals disabled, setupFiles, correct pool settings, and enable coverage with thresholds."

Frequently Asked Questions about vitest

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

FAQPage Schema
How do I configure Vitest 4 for a Vite project with jsdom, setupFiles, and correct pool settings?

Configure Vitest 4 by defining environment and `setupFiles` in `vitest.config.ts` using the flattened `pool` and `poolOptions` syntax.

Why does my test suite fail after migrating to Vitest 4 in a monorepo?

Monorepo test failures during v3→v4 migration usually stem from the `workspace` key being replaced by the `projects` API, altered pool config, and changed spy isolation semantics.

What is the correct way to use mocking in Vitest 4?

Vitest 4 mocking relies on `vi.mock`, `vi.fn`, and `vi.spyOn` while respecting hoisting rules, utilizing `vi.importActual` for unmocked logic and `vi.mocked` for typed helpers.

How do I handle snapshot v2 differences and enable coverage thresholds in Vitest?

Handle snapshot v2 differences by correctly updating snapshots, and configure coverage by selecting `v8` or `istanbul` providers with defined thresholds in `vitest.config.ts`.

Can I test multiple environments like browser and Node in Vitest 4?

Yes, you can test multi-environment scenarios in Vitest 4 by utilizing the `projects` API, which replaces the obsolete `workspace` key to support browser and Node configurations.

Why are my spy variables behaving differently after upgrading to Vitest 4?

Spy state behaves differently in Vitest 4 due to updated spy isolation semantics, a v3→v4 breaking change that alters how `vi.spyOn` state is shared across test scopes.