
vitest
Vitest testing framework: Vite-powered tests, Jest-compatible API, mocking, snapshots, coverage, browser mode, and TypeScript support. Use when writing or configuring tests with Vitest, setting up mocking/snapshots, configuring coverage, or running browser-mode tests. Keywords: Vitest, testing, Vite, Jest, mocking, coverage.
- Installs
- 199
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/itechmeat/llm-code --skill vitest- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads vitest automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Vitest
Next generation testing framework powered by Vite.
Quick Navigation
- Test API - test, describe, hooks
- Expect API - matchers and assertions
- Mocking - vi.fn, vi.mock, fake timers
- Configuration - vitest.config.ts options
- CLI - command line reference
- Browser Mode - real browser testing
When to Use
- Testing Vite-based applications (shared config)
- Need Jest-compatible API with native ESM support
- Component testing in real browser
- Fast watch mode with HMR
- TypeScript testing without extra config
- Parallel test execution
Installation
Install: npm install -D vitest. Requires Node.js >=22 and Vite >=6.4 in v5.
Release Highlights (5.0.0)
- Requirements: Node.js >=22 and Vite >=6.4 are required.
@vitest/runneris inlined (the package is no longer published) andexpectis inlined, so old entry points were removed. - Mock/timer behavior: mocks are cleared by default before each test, and
Temporalcan now be mocked (with or without fake timers). - Replaced APIs:
sequentialtest/suite options are removed in favor ofconcurrent; thewebdriveriobrowser provider is removed;toHaveTextContentis strict withtoMatchTextContentas the alternative;expect.pollfails when the function does not resolve in time. - New defaults/outputs:
attachmentsDirdefaults to.vitest/attachments/(was.vitest-attachments/), and blob/json/junit/html reporter outputs default to.vitest; acreateReportAPI and.vitestreport directory convention are introduced. - Projects: inline projects extend the root config by default, nested projects are supported, distinct projects share one Vite server, and the config file is no longer looked up from ancestor directories (parent dirs no longer apply).
- Browser: locator objects replace locator strings,
locators.exactis on by default, and ascreenshotDirectoryconfig controlstoMatchScreenshotoutput. - Misc: benchmark public API was rewritten with a pluggable provider API;
-pis a shorthand for--project;-tuses>as separator; coveragethresholds.perFileaccepts an object and TypeScript build mode /vitest liststatic parsing are supported.
Release Highlights (4.1.0 -> 4.1.6)
- New control-flow hooks:
aroundEachandaroundAll. - Test metadata expands with tags,
meta, and improvedtest.extendtype inference. - CLI adds
--detect-async-leaks, richer--updatemodes, and static collection forvitest list. - Browser mode grows Playwright persistent contexts,
userEvent.wheel, and stronger trace/artifact handling. - Mocking/timers add disposable
doMock(),mockThrow/mockThrowOnce, andsetTickMode. 4.1.4adds experimental ARIA snapshots,filterMetafor the JSON reporter, and exposesassertionas a public experimental field.4.1.5adds coverageinstrumentersupport and improves reporter/UI behavior around large snapshots and HTML output.4.1.6tightens browser screenshot path resolution and fixessequence.concurrenthandling for concurrent test scheduling.
Quick Start
// sum.js
export function sum(a, b) {
return a + b;
}
// sum.test.js
import { expect, test } from "vitest";
import { sum } from "./sum.js";
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
// package.json
{
"scripts": {
"test": "vitest",
"test:run": "vitest run",
"coverage": "vitest run --coverage"
}
}
Configuration
// vitest.config.ts (recommended)
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: true, // Enable global test APIs
environment: "jsdom", // Browser-like environment
include: ["**/*.{test,spec}.{js,ts,jsx,tsx}"],
coverage: {
provider: "v8",
reporter: ["text", "html"],
},
},
});
Or extend Vite config:
// vite.config.ts
/// <reference types="vitest/config" />
import { defineConfig } from "vite";
export default defineConfig({
test: {
// test options
},
});
Test File Naming
By default, tests must contain .test. or .spec. in filename:
sum.test.jssum.spec.ts__tests__/sum.js
Key Commands
# Watch mode (default)
vitest
# Single run
vitest run
# With coverage
vitest run --coverage
# Filter by file/test name
vitest sum
vitest -t "should add"
# UI mode
vitest --ui
# Browser tests
vitest --browser.enabled
Common Patterns
Basic Test
import { describe, it, expect, beforeEach } from "vitest";
describe("Calculator", () => {
let calc: Calculator;
beforeEach(() => {
calc = new Calculator();
});
it("adds numbers", () => {
expect(calc.add(1, 2)).toBe(3);
});
it("throws on invalid input", () => {
expect(() => calc.add("a", 1)).toThrow();
});
});
Mocking
import { vi, expect, test } from "vitest";
import { fetchUser } from "./api";
vi.mock("./api", () => ({
fetchUser: vi.fn(),
}));
test("uses mocked API", async () => {
vi.mocked(fetchUser).mockResolvedValue({ name: "John" });
const user = await fetchUser(1);
expect(fetchUser).toHaveBeenCalledWith(1);
expect(user.name).toBe("John");
});
Snapshot Testing
import { expect, test } from "vitest";
test("matches snapshot", () => {
const result = generateConfig();
expect(result).toMatchSnapshot();
});
// Inline snapshot (auto-updates)
test("inline snapshot", () => {
expect({ foo: "bar" }).toMatchInlineSnapshot();
});
Async Testing
import { expect, test } from "vitest";
test("async/await", async () => {
const result = await fetchData();
expect(result).toBeDefined();
});
test("resolves", async () => {
await expect(Promise.resolve("ok")).resolves.toBe("ok");
});
test("rejects", async () => {
await expect(Promise.reject(new Error())).rejects.toThrow();
});
Fake Timers
import { vi, expect, test, beforeEach, afterEach } from "vitest";
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
test("advances time", () => {
const callback = vi.fn();
setTimeout(callback, 1000);
vi.advanceTimersByTime(1000);
expect(callback).toHaveBeenCalled();
});
Jest Migration
Most Jest code works with minimal changes:
- import { jest } from '@jest/globals'
+ import { vi } from 'vitest'
- jest.fn()
+ vi.fn()
- jest.mock('./module')
+ vi.mock('./module')
- jest.useFakeTimers()
+ vi.useFakeTimers()
Key differences:
- Use
viinstead ofjest - Globals not enabled by default (add
globals: true) vi.mockis hoisted (usevi.doMockfor non-hoisted)- No
jest.requireActual(usevi.importActual)
Environment Selection
// vitest.config.ts
{
test: {
environment: 'jsdom', // or 'happy-dom', 'node', 'edge-runtime'
}
}
// Per-file (docblock at top)
/** @vitest-environment jsdom */
TypeScript
// tsconfig.json
{
"compilerOptions": {
"types": ["vitest/globals"]
}
}
References
See references/ directory for detailed documentation on:
- Test API and hooks
- All expect matchers
- Mocking functions and modules
- Configuration options
- CLI commands
- Browser mode testing
Links
FAQ
What does the vitest skill do?
Vitest testing framework: Vite-powered tests, Jest-compatible API, mocking, snapshots, coverage, browser mode, and TypeScript support. Use when writing or configuring tests with Vitest, setting up mocking/snapshots, configuring coverage, or running browser-mode tests. Keywords: Vitest, testing, Vite, Jest, mocking, coverage.
How do I install vitest?
Run npx skills add https://github.com/itechmeat/llm-code --skill vitest in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/vitest/ (personal) or .claude/skills/vitest/ (project).
Which AI agents can use vitest?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is vitest safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains vitest?
It is published by itechmeat in itechmeat/llm-code. It has 199 recorded installs.
More from itechmeat/llm-code
react-testing-library
itechmeat/llm-code
React Testing Library: user-centric component testing with queries, user-event simulation, async utilities, and accessibility-first API. Use when writing React component tests, selecting elements by role/label/text, simulating user events, or testing async UI behavior. Keywords: React Testing Library, @testing-library/react, user-event, queries, render.
openspec
itechmeat/llm-code
OpenSpec artifact-driven workflow. Covers OPSX commands, schemas, project config. Use when applying the artifact-driven workflow (OPSX), planning or reviewing changes based on artifact dependencies, or working with OPSX commands and schema/template resolution. Keywords: OPSX, artifact graph, /opsx:.
mantine-dev
itechmeat/llm-code
Open the skill to read its SKILL.md instructions.
social-writer
itechmeat/llm-code
Open the skill to read its SKILL.md instructions.
base-ui
itechmeat/llm-code
Base UI unstyled React components. Covers forms, menus, overlays, composition. Use when building accessible, unstyled React UI components with @base-ui/react, composing with render props, or implementing custom-styled form controls, menus, and overlays. Keywords: @base-ui/react, render props, unstyled components.
refine-dev
itechmeat/llm-code
Open the skill to read its SKILL.md instructions.
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work