vitest

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and maintaining a fast, Vite-native test suite requires knowing Vitest's configuration options, APIs, and mocking utilities, which are spread across extensive documentation. This Skill consolidates that knowledge so you can write tests, configure coverage, and debug test setups without leaving your workflow. ## 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, date mocking, and environment variable stubbing. - Configuration & Scale: Explains vitest.config.ts setup, coverage with V8 or Istanbul, multi-project workspaces, sharding for CI, and test environments like jsdom and happy-dom. - Use Case: You need to add unit tests to a Vite + TypeScript project with 80% coverage thresholds and mocked API calls. This Skill provides the exact config, mock patterns, and CLI commands to achieve it. ## Quick Start Use the vitest skill to help me write a test suite with mocked API calls and coverage configuration for my Vite project.

Frequently Asked Questions about vitest

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

FAQPage Schema
How do I configure Vitest in a Vite project?▼

Add a test property to vite.config.ts with a reference to vitest/config types, or create a separate vitest.config.ts using defineConfig from vitest/config. Common options include environment, setupFiles, include patterns, and coverage settings.

How to mock modules and functions in Vitest?▼

Use vi.mock with a factory function to replace module exports, noting it is hoisted above imports. For functions, use vi.fn for standalone mocks and vi.spyOn to intercept existing object methods while optionally keeping implementations.

Vitest vs Jest: can I migrate my existing tests?▼

Vitest provides a Jest-compatible API, so most test suites work as drop-in replacements with the same describe, test, and expect syntax. It adds native ESM and TypeScript support through Vite's transformation pipeline without extra configuration.

Does Vitest support code coverage reporting?▼

Yes, Vitest supports coverage via the V8 provider by default or Istanbul for broader compatibility. Enable it with the --coverage flag or coverage.enabled in config, and set thresholds for lines, functions, branches, and statements.

Why do my Vitest mocks leak between tests?▼

Mocks persist unless cleared, causing cross-test pollution. Enable clearMocks, restoreMocks, or mockReset in your config, or call vi.clearAllMocks and vi.restoreAllMocks in afterEach hooks to reset state.

How do I run Vitest tests in a browser-like environment?▼

Set environment to jsdom or happy-dom in your config, or add a // @vitest-environment jsdom comment at the top of individual test files. For real browser testing, enable Vitest Browser Mode with Playwright as the provider.