vitest-v4
БесплатноБез исполняемых скриптовНе проверенVitest 4+ testing with Vite. Use when configuring vitest.config.ts, writing unit/integration/browser tests, implementing mocks with vi.fn/vi.spyOn/vi.mock…
от nodnarbnitram★ 19 звёзд на GitHubОб этом скилле
Vitest 4 Testing Skill
Write, configure, and debug Vitest 4 test suites with Vite-native patterns.
Before You Start
This skill prevents 7+ common Vitest 4 mistakes and saves ~50% tokens.
| Metric | Without Skill | With Skill |
|---|---|---|
| Setup Time | ~90 min | ~30 min |
| Common Errors | 7+ | 0 |
| Token Usage | High (trial/error) | Low (known patterns) |
Known Issues This Skill Prevents
- Hanging agent runs from using watch mode instead of
vitest run - Broken coverage configs from using removed
coverage.allorcoverage.extensions - Browser Mode spying failures from sealed ESM namespace objects
- Mock leakage between tests from missing restore/reset config
- Invalid multi-project setup from using deprecated
workspaceterminology - Wrong APIs from mixing Jest helpers into Vitest tests
- Flaky browser interactions from using synthetic helpers instead of
vitest/browser - Slow or unstable large suites from choosing the wrong execution pool or isolation mode
Quick Start
Step 1: Configure Vitest 4 for agent-safe runs
// vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
restoreMocks: true,
clearMocks: true,
coverage: {
provider: 'v8',
include: ['src/**/*.{ts,tsx}'],
},
},
});
Why this matters: Vitest 4 removed coverage.all and coverage.extensions, and agent/CI environments need one-shot execution plus automatic mock cleanup.
Step 2: Write tests with Vitest APIs, not Jest APIs
import { describe, expect, it, vi } from 'vitest';
import { addUser } from './add-user';
import * as api from './api';
describe('addUser', () => {
it('returns the created user', async () => {
vi.spyOn(api, 'createUser').mockResolvedValue({ id: '1', name: 'Ada' });
await expect(addUser('Ada')).resolves.toEqual({ id: '1', name: 'Ada' });
});
});
Why this matters: vi is the supported mocking API. Mixing jest.fn() or Jest-only patterns causes confusing failures and poor autocomplete.
Import rule: Import
describe,it,expect, andvifromvitestunless the project explicitly enablesglobals: true.
Step 3: Use the correct runtime command
vitest run
vitest run --coverage
vitest run path/to/example.test.ts
Why this matters: vitest without run starts watch mode by default in development, which is a poor fit for agents, CI, and non-interactive verification.
Critical Rules
Always Do
- Use
vitest runorvitest --no-watchfor agent and CI workflows - Prefer
vi.mock(import('./module'))for type-safe module mocks - Configure
restoreMocks,clearMocks, ormockResetintentionally - Use
projectsfor multi-project configs; the rename began in Vitest 3.2 and older workspace-file usage is removed in Vitest 4 - Use a shared base config when multiple
projectsneed common settings; projects do not inherit root config unless you opt in - Use
coverage.includeto report on untested source files - Use
pageanduserEventfromvitest/browserin Browser Mode - Prefer
forkswhen native modules or runtime compatibility matter more than raw speed - Share
vitest.config.tsand the implementation file when asking AI to generate tests
Never Do
- Never use
jest.fn,jest.spyOn, or Jest-only globals in Vitest code - Never rely on removed
coverage.allorcoverage.extensionsin Vitest 4 - Never use plain watch mode for agent-driven verification
- Never use
vi.spyOnon native ESM exports in Browser Mode - Never forget that
vi.mock()is hoisted before the rest of the file executes - Never leave env/global stubs un-restored across tests
Common Mistakes
Wrong - removed coverage option:
export default defineConfig({
test: {
coverage: {
all: true,
},
},
});
Correct - use include globs:
export default defineConfig({
test: {
coverage: {
provider: 'v8',
include: ['src/**/*.{ts,tsx}'],
},
},
});
Why: Vitest 4 removed coverage.all and coverage.extensions; coverage.include is the supported way to include uncovered files.
Wrong - Browser Mode spy on sealed export:
import * as math from './math';
import { vi } from 'vitest';
vi.spyOn(math, 'add').mockReturnValue(10);
Correct - use spy-enabled module mock:
import { vi } from 'vitest';
vi.mock(import('./math'), { spy: true });
Why: Native browser ESM namespace objects are sealed, so direct spies on exports fail in Browser Mode.
Known Issues Prevention
| Issue | Root Cause | Solution |
|---|---|---|
| Tests never exit | Watch mode started in a non-interactive session | Use vitest run |
| Coverage report misses untested files | coverage.include not configured |
Add explicit source globs |
| Browser Mode spy throws o |
Установить vitest-v4 в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл vitest-v4?
Vitest 4+ testing with Vite. Use when configuring vitest.config.ts, writing unit/integration/browser tests, implementing mocks with vi.fn/vi.spyOn/vi.mock, setting up V8 or Istanbul coverage, or migrating from Jest or older Vitest workspace setups. Triggers on vitest, vitest.config.ts, vi.mock, browser mode, vitest/browser, projects, setupFiles, and toMatchScreenshot.
Как установить скилл vitest-v4?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл vitest-v4 запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic