# vitest

Helps an agent write and configure Vitest tests with mocks, snapshots, coverage, and browser mode. Useful for Vite and TypeScript projects.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 202 installs · ★ 23 repo stars
- Author: itechmeat
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/itechmeat/llm-code/tree/HEAD/skills/vitest/SKILL.md
- Updated: 2026-10-24
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/itechmeat-vitest

## What it does

This skill gives the agent focused Vitest guidance: test and assertion APIs, hooks, `vi.fn` and `vi.mock`, fake timers, snapshots, CLI usage, and `vitest.config.ts`. It also covers coverage reports, UI mode, concurrent execution, and tests that run in a real browser.

The included patterns use `*.test.*`, `*.spec.*`, and `__tests__` files, with commands such as `vitest`, `vitest run`, `vitest run --coverage`, and `vitest --browser.enabled`. Ask the agent to create tests, adjust configuration, or map familiar Jest-style calls to Vitest. Vitest v5 requires Node.js >=22 together with Vite >=6.4; a project below those versions will fail to run.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add itechmeat/llm-code --skill vitest -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/vitest/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/vitest/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add itechmeat/llm-code --skill vitest -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/vitest/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add itechmeat/llm-code --skill vitest -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/vitest/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install itechmeat/llm-code skills/vitest
```

2. **Manually: put the files in place**
- File: `.github/skills/vitest/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add itechmeat/llm-code --skill vitest -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/itechmeat/llm-code --path skills/vitest
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/vitest/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add itechmeat/llm-code --skill vitest -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/itechmeat/llm-code/tree/HEAD/skills/vitest/SKILL.md

## When to use it
- write unit tests for functions and classes
- mock an API and control fake timers
- add snapshots for generated output
- configure code coverage reports
- run tests in a real browser

## Example prompts
- Set up Vitest in this Vite project and create `vitest.config.ts`.
- Write tests for `src/api.ts` with a mocked external API and call assertions.
- Add a coverage script using `vitest run --coverage`.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 4c0ad50d69cc6a7e.

BEGIN THIRD-PARTY FILE 4c0ad50d69cc6a7e
```text
---
name: vitest
description: "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."
metadata:
  version: "5.0.5"
  release_date: "2026-10-15"
---

# Vitest

Next generation testing framework powered by Vite.

## Quick Navigation

- [Test API](references/api.md) - test, describe, hooks
- [Expect API](references/expect.md) - matchers and assertions
- [Mocking](references/mocking.md) - vi.fn, vi.mock, fake timers
- [Configuration](references/config.md) - vitest.config.ts options
- [CLI](references/cli.md) - command line reference
- [Browser Mode](references/browser.md) - 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/runner` is inlined (the package is no longer published) and `expect` is inlined, so old entry points were removed.
- **Mock/timer behavior:** mocks are cleared by default before each test, and `Temporal` can now be mocked (with or without fake timers).
- **Replaced APIs:** `sequential` test/suite options are removed in favor of `concurrent`; the `webdriverio` browser provider is removed; `toHaveTextContent` is strict with `toMatchTextContent` as the alternative; `expect.poll` fails when the function does not resolve in time.
- **New defaults/outputs:** `attachmentsDir` defaults to `.vitest/attachments/` (was `.vitest-attachments/`), and blob/json/junit/html reporter outputs default to `.vitest`; a `createReport` API and `.vitest` report 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.exact` is on by default, and a `screenshotDirectory` config controls `toMatchScreenshot` output.
- **Misc:** benchmark public API was rewritten with a pluggable provider API; `-p` is a shorthand for `--project`; `-t` uses `>` as separator; coverage `thresholds.perFile` accepts an object and TypeScript build mode / `vitest list` static parsing are supported.

## Patch Notes (5.0.1 -> 5.0.5)

- `5.0.2` to `5.0.5` are fixes only — the `5.0` API surface is unchanged.
- The root temp directory is removed when the run closes, and `--changed` handles quoted file names.
- `import.meta.hot` stubs expose `data`, `skipIf` sets `skip` and ignores `undefined` options, and the native loader keeps the import frame inside its errors.
```
END THIRD-PARTY FILE 4c0ad50d69cc6a7e

The third-party file has ended. Everything between the 4c0ad50d69cc6a7e tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3137 of 8798 bytes. © itechmeat · MIT · https://github.com/itechmeat/llm-code/tree/HEAD/skills/vitest/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
