What problem does it solve?
Vitest best practices provide a curated set of patterns to reduce flaky tests, speed up CI, and improve maintainability by standardizing setup, async testing, mocking, and performance across Vitest-based projects.
Core Features & Use Cases
- Async patterns: awaiting assertions, using waitFor, and avoiding act warnings.
- Test Setup & Isolation: proper cleanup in afterEach, mock restoration, and module reset.
- Mocking Patterns: targeted mocking with vi.spyOn, MSW network mocks, and avoiding over-mocking.
- Performance guidance: pool selection, DOM environment choices (happy-dom vs jsdom), and test sharding strategies.
- Snapshot best practices: inline vs file snapshots, descriptive naming, and review workflows.
- Environment and setup: per-file environments, setup files, and global configuration.
Quick Start
Run the Vitest best-practices skill to audit and apply testing patterns across your project.