vitest

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and maintaining fast unit tests in Vite-based projects requires knowing Vitest's API surface, configuration options, mocking utilities, and coverage setup, which are spread across extensive documentation. ## Core Features & Use Cases - Test Authoring: Covers the test/describe/expect APIs, lifecycle hooks, parameterized tests, and custom fixtures via test.extend. - Mocking & Utilities: Guides module mocking with vi.mock, spies, fake timers, stubbed globals, and environment variables. - Coverage, Filtering & Projects: Explains V8/Istanbul coverage configuration, test filtering by name or tags, sharding for CI, and multi-project workspaces. - Use Case: When adding tests to a TypeScript component, ask for a Vitest test suite with mocked API calls, fake timers, and coverage thresholds configured in vitest.config.ts. ## Quick Start Write a Vitest test file for my utils module that mocks the fetch call and runs with jsdom environment and coverage enabled.

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. For partial mocks, call importOriginal inside the factory and spread the actual module, overriding only specific exports with vi.fn.

How to configure code coverage in Vitest?

Enable coverage in vitest.config.ts under test.coverage with provider 'v8' or 'istanbul', then run vitest run --coverage. Install @vitest/coverage-v8 or @vitest/coverage-istanbul and set thresholds for lines, functions, branches, and statements.

What is the difference between jsdom and happy-dom in Vitest?

jsdom provides full browser API simulation including localStorage and complete DOM behavior, while happy-dom runs faster with fewer APIs. Set the environment in config or per file with the // @vitest-environment comment.

Does Vitest support running tests in parallel?

Yes, test files run in parallel across worker threads by default. Within a file, use test.concurrent or describe.concurrent for parallel tests, and use the context's expect for correct assertion tracking.

Why is my vi.mock factory not seeing my variables?

vi.mock calls are hoisted above imports, so regular variables are undefined at that point. Wrap shared values in vi.hoisted so they are initialized before the mock factory executes.

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 tags with --tags. Use test.only to focus a single test during development, and vitest related to run tests importing changed files.