vitest

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and maintaining a Vitest test suite involves many moving parts—configuration, mocking, coverage, fixtures, environments, and CI sharding—and getting any of them wrong leads to flaky or slow tests. This Skill provides accurate, version-aware guidance (including v4/v5 breaking changes) for every part of the Vitest workflow. ## Core Features & Use Cases - Test Authoring: Covers the test/describe/expect APIs, hooks, parameterized tests, concurrent tests, and custom fixtures via test.extend and test.override. - Mocking & Utilities: Documents vi.fn, vi.spyOn, module mocking with vi.mock/vi.doMock, fake timers, vi.when conditional mocking, and global/env stubbing. - Coverage, Filtering & CI: Explains V8/Istanbul coverage setup, thresholds, test filtering by name/tags/changed files, sharding with blob reports, and reporter configuration. - Use Case: You are migrating a Jest suite to Vitest 5 and need to update config (poolOptions removal, projects instead of workspace), rewrite benchmarks to the new context-based bench fixture, and set up sharded CI runs with merged reports. ## Quick Start Use the vitest skill to help me configure vitest.config.ts with jsdom environment, coverage thresholds, and a mocked API module for my test suite.

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

How do I set up code coverage in Vitest?

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

What changed in Vitest v4 and v5 configuration?

v4 removed poolOptions (use top-level maxWorkers), removed workspace in favor of projects, and made forks the default pool. v5 removed test.sequential and describe.sequential (use { concurrent: false }) and moved bench to a test-context fixture.

Does Vitest support testing TypeScript types?

Yes, Vitest supports type testing through expectTypeOf and assertType in .test-d.ts files. Enable it with typecheck.enabled in config and run it with vitest typecheck or the --typecheck flag.

How do I run Vitest tests in parallel 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.

Why do my Vitest fake timers not work with async code?

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