web-testing-vitest
Vitest Test Runner Patterns
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>
CRITICAL: Before Using This Skill
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)