vitest

Write and configure unit and integration tests for Vite projects using Vitest.

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/Aveer/skills --skill vitest-aveer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/Aveer/skills/tree/main/skills/vitest
Command: npx skills add https://github.com/Aveer/skills --skill vitest-aveer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up and writing tests in Vite-based projects requires knowing Vitest's configuration options, test API, mocking system, and coverage tooling, which are spread across extensive documentation and vary by version. ## Core Features & Use Cases - Configuration Guidance: Set up vitest.config.ts with environments, projects, coverage thresholds, sharding, and CLI options. - Test Authoring Patterns: Write test suites with describe/it, lifecycle hooks, fixtures, parameterized tests, and concurrent execution. - Mocking & Assertions: Create mocks with vi.fn, vi.mock, vi.spyOn, fake timers, stubbed globals, and use the full expect API including snapshots and custom matchers. - Use Case: When adding tests to a Vue or React component library, load the mocking reference to stub API calls with vi.mock, then configure jsdom environment and coverage thresholds in vitest.config.ts. ## Quick Start Ask the AI to write Vitest unit tests with mocked dependencies for a specific source file in your Vite project.

Frequently Asked Questions about vitest

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

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

Create a vitest.config.ts file using defineConfig from 'vitest/config' and set test options like globals and environment. You can also add a test block directly to an existing vite.config.ts or merge both configs with mergeConfig.

How to mock modules and functions in Vitest?▼

Use vi.fn() for mock functions, vi.spyOn() for spying on object methods, and vi.mock() for module mocking, which is hoisted to the top of the file. Partial mocks use importOriginal to spread the actual module and override specific exports.

Does Vitest support testing DOM components?▼

Yes, Vitest supports DOM testing through the jsdom or happy-dom environments, configured via the environment option or per-file with the @vitest-environment comment. It also offers browser mode with Playwright for real browser testing.

How do I run Vitest tests in parallel or across CI machines?▼

Use test.concurrent for parallel tests within a file and fileParallelism with pool options for parallel files. For CI, split runs with --shard=1/3 across machines and merge results using --merge-reports.

Why do my Vitest mocks leak between tests?▼

Mock state persists unless cleared. Call mockClear, mockReset, or mockRestore on individual mocks, or enable clearMocks, restoreMocks, and unstubGlobals in the test config to reset automatically between tests.

Can Vitest test TypeScript types?▼

Yes, Vitest supports type testing through .test-d.ts files using expectTypeOf and assertType. Run them with vitest typecheck or vitest --typecheck to validate type-level assertions separately from runtime tests.