vitest

Write, mock, and run Vitest unit tests with Vite-native configuration.

Updated May 28, 2026
One-click install
npx skills add https://github.com/qbstabletampa-creator/firmware-foundation-studios --skill vitest-qbstabletampa-creator
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/qbstabletampa-creator/firmware-foundation-studios/tree/main/archive/apps/manna-catch/.agents/skills/vitest
Command: npx skills add https://github.com/qbstabletampa-creator/firmware-foundation-studios --skill vitest-qbstabletampa-creator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and writing fast unit tests in a Vite-based project requires knowing Vitest's configuration options, mocking APIs, coverage setup, and test filtering, 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 & Snapshots: Provides patterns for vi.fn, vi.spyOn, module mocking, fake timers, and inline or file snapshots. - Coverage, Filtering & Projects: Explains V8/Istanbul coverage, CLI filtering, sharding for CI, and multi-project workspace configuration. - Use Case: When adding tests to a Vite + TypeScript app, ask for a vitest.config.ts with jsdom environment, coverage thresholds, and a mocked API module, and get working code immediately. ## Quick Start Use the vitest skill to write a test suite with mocked fetch 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 with an existing Vite config?▼

Add a test property to vite.config.ts with a Vitest types reference, or create a separate vitest.config.ts which takes priority. Use mergeConfig from vitest/config to combine both files when needed.

How to mock modules in Vitest with vi.mock?▼

Call vi.mock with the module path and a factory returning mocked exports; it is hoisted above imports automatically. Use vi.doMock for non-hoisted dynamic mocking, or { spy: true } to keep real implementations while tracking calls.

Vitest vs Jest for a Vite project?▼

Vitest shares Vite's config, transformers, and plugins, so tests use the same pipeline as the app with no duplicate configuration. It offers a Jest-compatible API, making most Jest suites portable with minimal changes.

Does Vitest support jsdom and browser testing?▼

Yes, set environment to jsdom or happy-dom in config, or use a // @vitest-environment comment per file. For real browsers, Vitest Browser Mode runs tests in Chromium, Firefox, or WebKit via Playwright.

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

Why is vi.mock not working with my variables?▼

vi.mock calls are hoisted to the top of the file, so they cannot reference variables declared later. Wrap such variables in vi.hoisted so they are initialized before the mock factory executes.