Back to Testing & Quality Assurance

Vitest Testing Framework

testingvitestviteunit-testingjavascript
β˜… 4.9 (193)⭐ 5.3kπŸ“„ MITπŸ•’ 2026-05-01Source β†—

Install this skill

npx skills add antfu/skills

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

What this skill does

  • β€’Run unit tests with high-performance HMR-like speed
  • β€’Mock functions, modules, timers, and dates via vi utilities
  • β€’Execute tests in parallel using multi-threaded workers
  • β€’Generate code coverage reports using V8 or Istanbul
  • β€’Perform type-level validation using expectTypeOf and assertType

When to use it

  • βœ“You are maintaining a project using Vite or Nuxt
  • βœ“You need a fast, Jest-compatible environment for TypeScript code
  • βœ“You want to perform snapshot testing on UI components
  • βœ“You need to verify complex business logic with mocked dependencies

When not to use it

  • βœ•You are working in a non-Node.js, non-browser environment like pure Rust
  • βœ•You need end-to-end integration tests that require a full browser engine
  • βœ•Your project relies on legacy CJS-only build systems that conflict with Vite

How to invoke it

Example prompts that trigger this skill:

  • β€œRun the test suite for the current project”
  • β€œCreate a new test file for my component using Vitest syntax”
  • β€œMock the dependency in this test file”
  • β€œCheck the code coverage for the latest changes”
  • β€œFilter the test execution to only run files matching a specific pattern”

Example workflow

  1. Configure Vitest within the Vite project settings
  2. Define unit tests using the test and expect APIs
  3. Use vi.mock to isolate functions from external dependencies
  4. Run tests in watch mode to see immediate feedback
  5. Generate a coverage report to identify untested code paths

Prerequisites

  • –Node.js
  • –Vite

Pitfalls & limitations

  • !Config drift between Vite development and Vitest environment settings
  • !Incompatibility with certain non-standard ESM plugins
  • !Memory management overhead when running massive test suites in parallel

FAQ

Is Vitest compatible with Jest?
Yes, it provides a Jest-compatible API, allowing most existing Jest suites to be migrated to Vitest with minimal changes.
Can I use Vitest without Vite?
While it is built to share Vite's pipeline, it can be used standalone in most JavaScript projects.
How does it handle parallel execution?
Vitest utilizes a multi-threaded worker pool to run tests in parallel, significantly reducing total execution time.
Does it support type-level testing?
Yes, it includes specialized tools like expectTypeOf and assertType for verifying TypeScript code at the type level.

How it compares

Unlike manual testing or generic scripts, this agent manages the full Vitest lifecycle, including complex module resolution and mocking configurations that usually require significant boilerplate.

Source & trust

⭐ 5.3k starsπŸ“„ MITπŸ•’ Updated 2026-05-01πŸ›‘ network

From the source: β€œVitest is a next-generation testing framework powered by Vite. It provides a Jest-compatible API with native ESM, TypeScript, and JSX support out of the box. Vitest shares the same config, transformers, resolvers, and plugins with your Vite app. **Key Features:** - Vite-native: Uses Vite's transform…”

View the full SKILL.md source

Vitest is a next-generation testing framework powered by Vite. It provides a Jest-compatible API with native ESM, TypeScript, and JSX support out of the box. Vitest shares the same config, transformers, resolvers, and plugins with your Vite app.

**Key Features:**
- Vite-native: Uses Vite's transformation pipeline for fast HMR-like test updates
- Jest-compatible: Drop-in replacement for most Jest test suites
- Smart watch mode: Only reruns affected tests based on module graph
- Native ESM, TypeScript, JSX support without configuration
- Multi-threaded workers for parallel test execution
- Built-in coverage via V8 or Istanbul
- Snapshot testing, mocking, and spy utilities

> The skill is based on Vitest 3.x, generated at 2026-01-28.

## Core

| Topic | Description | Reference |
|-------|-------------|-----------|
| Configuration | Vitest and Vite config integration, defineConfig usage | [core-config](references/core-config.md) |
| CLI | Command line interface, commands and options | [core-cli](references/core-cli.md) |
| Test API | test/it function, modifiers like skip, only, concurrent | [core-test-api](references/core-test-api.md) |
| Describe API | describe/suite for grouping tests and nested suites | [core-describe](references/core-describe.md) |
| Expect API | Assertions with toBe, toEqual, matchers and asymmetric matchers | [core-expect](references/core-expect.md) |
| Hooks | beforeEach, afterEach, beforeAll, afterAll, aroundEach | [core-hooks](references/core-hooks.md) |

## Features

| Topic | Description | Reference |
|-------|-------------|-----------|
| Mocking | Mock functions, modules, timers, dates with vi utilities | [features-mocking](references/features-mocking.md) |
| Snapshots | Snapshot testing with toMatchSnapshot and inline snapshots | [features-snapshots](references/features-snapshots.md) |
| Coverage | Code coverage with V8 or Istanbul providers | [features-coverage](references/features-coverage.md) |
| Test Context | Test fixtures, context.expect, test.extend for custom fixtures | [features-context](references/features-context.md) |
| Concurrency | Concurrent tests, parallel execution, sharding | [features-concurrency](references/features-concurrency.md) |
| Filtering | Filter tests by name, file patterns, tags | [features-filtering](references/features-filtering.md) |

## Advanced

| Topic | Description | Reference |
|-------|-------------|-----------|
| Vi Utilities | vi helper: mock, spyOn, fake timers, hoisted, waitFor | [advanced-vi](references/advanced-vi.md) |
| Environments | Test environments: node, jsdom, happy-dom, custom | [advanced-environments](references/advanced-environments.md) |
| Type Testing | Type-level testing with expectTypeOf and assertType | [advanced-type-testing](references/advanced-type-testing.md) |
| Projects | Multi-project workspaces, different configs per project | [advanced-projects](references/advanced-projects.md) |

Quoted from antfu/skills for reference β€” see the original for the authoritative, latest version.

πŸ“„ Full skill instructions β€” original source: antfu/skills
Vitest is a unit testing framework built specifically for the Vite ecosystem. It provides an API consistent with Jest, making it easy to migrate existing projects while offering first-class support for modern standards like native ESM, TypeScript, and JSX. By sharing the same transformation pipeline as your Vite application, it offers rapid feedback loops during development. It handles complex testing requirements including parallel execution across multiple threads, sophisticated mocking of modules or timers, and deep code coverage reporting. The framework is suited for developers working on Vite-based applications or libraries who want a performant, low-configuration testing solution that integrates directly with their existing build setup and module resolution.

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/vitest/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/antfu/skills/vitest/SKILL.md
  • Cursor: ~/.cursor/skills/antfu/skills/vitest/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/antfu/skills/vitest/SKILL.md

πŸš€ Install with CLI:
npx skills add antfu/skills

Read the Master Guide: Mastering Agent Skills β†’

Recommended Rules

View more rules β†’

Recommended Workflows

View more workflows β†’

Recommended MCP Servers

View more MCP servers β†’

Take It Further

Maximize your productivity with these powerful resources

πŸ“‹

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
πŸ“–

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid testing & quality assurance issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under Testing & Quality Assurance and is published by antfu, maintained in antfu/skills.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.