vitest

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

1|Updated Jun 30, 2026
One-click install
npx skills add https://github.com/trutoman/Conjuros --skill vitest-trutoman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/trutoman/Conjuros/tree/main/.agents/skills/vitest
Command: npx skills add https://github.com/trutoman/Conjuros --skill vitest-trutoman

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, reference-backed guidance for the Vitest testing framework so you can write correct tests and configuration without digging through documentation. ## Core Features & Use Cases - Test Authoring: Covers the test/describe/expect APIs, lifecycle hooks, parameterized tests with test.each and test.for, and custom fixtures via test.extend. - Mocking & Utilities: Guides module mocking with vi.mock, spying with vi.spyOn, fake timers, stubbed globals and environment variables. - Configuration & Scale: Explains vitest.config.ts setup, jsdom/happy-dom environments, multi-project workspaces, coverage with V8 or Istanbul, and CI sharding with report merging. - Use Case: You need to migrate a Jest suite to Vitest, add coverage thresholds, and split tests across three CI machines. The Skill walks you through config migration, coverage provider setup, and shard/merge-report commands. ## Quick Start Ask the assistant to help you write a Vitest test file with mocked API calls and coverage configuration for your 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, call importOriginal inside the factory and spread the actual module. Use vi.doMock for non-hoisted dynamic mocking with await import.

How do I set up code coverage in Vitest?

Install @vitest/coverage-v8 or @vitest/coverage-istanbul, then run vitest run --coverage. Configure the provider, reporters, include patterns, and thresholds under test.coverage in vitest.config.ts to enforce minimum line and branch percentages.

Vitest vs Jest: can I migrate an existing test suite?

Vitest provides a Jest-compatible API, so most test files using describe, it, expect, and jest-style matchers work with minimal changes. Replace jest.mock with vi.mock and jest.fn with vi.fn, and reuse your Vite config for transforms and aliases.

Does Vitest support testing DOM code without a browser?

Yes, set test.environment to jsdom or happy-dom in the config, or add a // @vitest-environment jsdom comment per file. For real browser testing, enable Vitest Browser Mode with Playwright as the provider.

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 specific source files.

Why does vi.mock not see my variables?

vi.mock calls are hoisted above imports, so top-level variables are undefined inside the factory. Wrap shared values in vi.hoisted so they are initialized before the mock factory executes.