vitest

SKILL.md

Vitest Skill

Vitest is a blazing-fast unit test framework built on top of Vite. It shares the same config, transforms, and module resolution as your Vite project, giving you zero-config testing for most setups.

Quick Start

Minimum setup:

npm install -D vitest
// vitest.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    environment: 'node',
  },
})

First test (src/math.test.ts):

import { describe, it, expect } from 'vitest'
import { add } from './math'

describe('add', () => {
  it('returns the sum of two numbers', () => {
    expect(add(1, 2)).toBe(3)
  })
})
npx vitest        # watch mode
npx vitest run    # single run (CI)

When This Skill Activates

  • User asks to write a test for a function, component, or module
  • User asks how to configure Vitest or integrate it into an existing Vite project
  • User's tests are failing and they need help diagnosing the error
  • User asks about mocking, spying, or stubbing in Vitest
  • User wants to measure or enforce test coverage

Behavior Guidelines

  1. Prefer Vitest-native imports — import describe, it, expect, vi, etc. from 'vitest', not from @jest/* packages.
  2. Respect the existing config — read vitest.config.ts or vite.config.ts before suggesting configuration changes.
  3. Match the project's test style — check existing test files for naming conventions (*.test.ts vs *.spec.ts, it vs test) and follow them.
  4. Use vi for all mocking — never suggest jest.fn(), jest.mock(), etc.
  5. Run tests to verify — after writing or modifying tests, suggest running npx vitest run to confirm they pass.

References Loading Guide

Load additional context files based on what the user needs:

Situation Load
Questions about vitest.config.ts, environments, globals, setupFiles references/config.md
Questions about describe, it, test, expect, hooks references/api.md
Questions about vi.fn(), vi.mock(), vi.spyOn(), timers, globals references/mocking.md
Questions about coverage providers, thresholds, --coverage flag references/coverage.md

Read only what is relevant to the current question. Do not preload all files unless the user's question spans multiple areas.

Weekly Installs
1
First Seen
Mar 1, 2026
Installed on
amp1
cline1
opencode1
cursor1
kimi-cli1
codex1