vitest

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and maintaining a JavaScript or TypeScript test suite involves many decisions: configuration, environments, mocking strategies, coverage thresholds, and CI sharding. This Skill provides structured, version-accurate Vitest guidance so you write correct tests and configs without digging through documentation. ## Core Features & Use Cases - Test Authoring: Covers the test/describe/expect APIs, lifecycle hooks, parameterized tests, and custom fixtures with test.extend. - Mocking & Utilities: Module mocking with vi.mock, spies, fake timers, conditional mocking with vi.when, and environment stubbing. - Configuration & Scale: Vite config integration, multi-project workspaces, coverage with V8 or Istanbul, reporters, filtering, and CI sharding with blob report merging. - Use Case: You are migrating a monorepo test suite to Vitest 5. Use this Skill to configure projects per package, set up jsdom environments for DOM tests, and shard runs across CI machines with merged coverage reports. ## Quick Start Use the vitest skill to write a test file with mocked API calls and fake timers for my src/utils/retry.ts module.

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 above imports so the mock applies before the module loads. For partial mocks, call importOriginal inside the factory and spread the actual exports. Use vi.doMock for non-hoisted dynamic mocking with await import.

How to configure Vitest coverage with V8 or Istanbul?▼

Install @vitest/coverage-v8 or @vitest/coverage-istanbul, then set coverage.provider in the test config and run vitest run --coverage. In v4, define coverage.include explicitly to report uncovered files, since coverage.all was removed.

Vitest vs Jest for TypeScript projects?▼

Vitest provides a Jest-compatible API while sharing Vite's config, transformers, and plugins, giving native ESM and TypeScript support without extra setup. Its watch mode reruns only affected tests based on the module graph, which suits Vite-based projects.

Does Vitest support running tests in a real browser?▼

Yes, Vitest Browser Mode runs tests in real browsers via providers like Playwright. In v4 the provider is an object such as playwright(), instances specify browsers like chromium, and test context imports from vitest/browser.

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 projects, and set coverage.include explicitly.

How do I run only specific tests or projects in Vitest?▼

Filter by file path or line number as CLI arguments, by test name with -t, or by declared tags with --tagsFilter expressions like "db && !flaky". Use --project to run named projects, and vitest related to run tests importing specific files.