vitest

Write, mock, and run unit tests with the Vitest framework powered by Vite.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and maintaining a fast, modern JavaScript/TypeScript test suite is difficult when juggling configuration, mocking, coverage, and environments. This Skill provides structured guidance for the Vitest testing framework so you can write tests, mock dependencies, and configure coverage 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 & Snapshots: Guides module mocking with vi.mock, spies, fake timers, stubbed globals, and inline or file-based snapshot testing. - Coverage, Filtering & Projects: Explains V8/Istanbul coverage setup, test filtering by name or tags, sharding for CI, and multi-project monorepo configurations. - Use Case: You are migrating a Jest suite to Vitest in a Vite monorepo. Use this Skill to configure jsdom environments per project, mock API modules with vi.mock, and enforce 80% coverage thresholds in CI. ## Quick Start Use the vitest skill to write a test file 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 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, spread the result of importOriginal and override specific exports. Use vi.doMock for non-hoisted dynamic mocking with await import.

How to set up code coverage in Vitest?▼

Install @vitest/coverage-v8 or @vitest/coverage-istanbul, then run vitest run --coverage. Configure the provider, reporters, include/exclude patterns, and thresholds under the coverage key in vitest.config.ts.

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

Vitest provides a Jest-compatible API, so most test suites work as a drop-in replacement. It shares config, transformers, and plugins with your Vite app, and supports globals mode so describe, it, and expect work without imports.

Does Vitest support testing DOM code without a browser?▼

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

Why is my vi.mock factory not seeing 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.

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, and vitest related to run tests importing specific source files.