dist/plugins/web-testing-vitest/skills/web-testing-vitest/SKILL.md
Vitest test runner - configuration, assertions, mocking (vi.fn, vi.mock, vi.spyOn), fake timers, snapshot testing, coverage, workspace projects
npx skillsauth add agents-inc/skills web-testing-vitestInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Quick Guide: Vitest is a fast, Vite-native test runner. Use
describe/it/expectfor test structure,vi.fn()for mocks,vi.mock()for module mocking,vi.spyOn()for spying. Co-locate tests with code. Use network-level API mocking over module-level mocks. Vitest v4 is current stable (requires Vite 6+, Node 20+).
<critical_requirements>
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST co-locate tests with code in feature-based structure - NOT in separate test directories)
(You MUST use network-level API mocking - NOT module-level mocks where possible)
(You MUST use named constants for test data - no magic strings or numbers in test files)
(You MUST use vi.fn() for mocks and vi.spyOn() for spying - NEVER manually replace functions)
(You MUST use the v3+ test options syntax: test("name", { timeout: 10_000 }, () => {}) - NOT as third argument)
</critical_requirements>
Auto-detection: Vitest, vi.fn, vi.mock, vi.spyOn, describe, it, expect, test, beforeEach, afterEach, vi.useFakeTimers, vitest.config, defineConfig, coverage, snapshot, mockResolvedValue, mockRejectedValue
When to use:
When NOT to use:
Key patterns covered:
Detailed Resources:
Vitest is a Vite-native test runner designed for speed and developer experience. It provides Jest-compatible APIs with native ESM support, TypeScript out of the box, and Vite's transform pipeline.
Core Principles:
When to use Vitest:
When NOT to use Vitest:
Write unit tests for pure functions with no side effects. Focus on clear input/output behavior.
What to test:
See examples/core.md for pure function test examples.
Use Vitest with network-level API mocking to test components with their API integration layer.
When Integration Tests Make Sense:
Key Pattern:
__tests__/ directories co-located with codeSee examples/integration.md for integration test examples.
Co-locate tests with code in feature-based structure. Tests live next to what they test.
Direct Co-location (Recommended):
src/
features/
auth/
components/
login-form.tsx
login-form.test.tsx # Test next to component
hooks/
use-auth.ts
use-auth.test.ts # Test next to hook
Alternative: __tests__/ Subdirectories:
src/features/auth/
components/
login-form.tsx
__tests__/
login-form.test.tsx
E2E Test Organization:
tests/
e2e/
auth/
login-flow.spec.ts
register-flow.spec.ts
checkout/
checkout-flow.spec.ts
File Naming Convention:
*.test.tsx / *.test.ts for unit and integration testsChoose one pattern and be consistent across the codebase.
</patterns><red_flags>
High Priority Issues:
vi.mock) instead of network-level - breaks when import structure changes, doesn't test serializationMedium Priority Issues:
Gotchas & Edge Cases:
test("name", { timeout: 10_000 }, () => {}) NOT test("name", () => {}, { timeout: 10_000 })vi.fn().mock.invocationCallOrder starts at 1 in v4 instead of 0vi.restoreAllMocks() only affects manual spies in v4, not automocks - use vi.resetAllMocks() for full reset</red_flags>
<critical_reminders>
All code must follow project conventions in CLAUDE.md
(You MUST co-locate tests with code in feature-based structure - NOT in separate test directories)
(You MUST use network-level API mocking - NOT module-level mocks where possible)
(You MUST use named constants for test data - no magic strings or numbers in test files)
(You MUST use vi.fn() for mocks and vi.spyOn() for spying - NEVER manually replace functions)
(You MUST use the v3+ test options syntax: test("name", { timeout: 10_000 }, () => {}) - NOT as third argument)
Failure to follow these rules will result in fragile tests that break on refactoring and false confidence from poorly structured test suites.
</critical_reminders>
development
Material Design component library for Vue 3
development
VitePress 1.x — Vue-powered static site generator for documentation sites, built on Vite
tools
Docusaurus 3.x documentation framework — site configuration, docs/blog plugins, sidebars, versioning, MDX, swizzling, and deployment
development
TanStack Form patterns - useForm, form.Field, validators, arrays, linked fields, createFormHook, type safety