Back to Skills

vitest

Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.

189stars17forksUpdated 8/3/2026

Security Assessment

Safe(97/100)
Security Score97/100

About vitest

This skill is a comprehensive best-practices reference for the Vitest testing framework, the Vite-powered test runner. It packages 44 rules across 8 categories prioritized by impact, aiming to solve the recurring problems of flaky, slow, and unreliable JavaScript/TypeScript test suites. It gives an AI agent or a developer a structured checklist for writing new tests, debugging failures, configuring test environments, and reviewing test code in pull requests.

The content is organized so the highest-leverage areas come first: Async Patterns and Test Setup & Isolation are marked CRITICAL, followed by Mocking Patterns and Performance (HIGH), then Snapshot Testing, Environment configuration, Assertions, and Test Organization. Each rule has a short slug (for example async-await-assertions, setup-restore-mocks, mock-vi-mock-hoisting, perf-happy-dom) and a dedicated reference file with explanations and incorrect-vs-correct code examples. The material covers awaiting async assertions, fake timers, vi.waitFor polling, cleanup in afterEach, restoring mocks, choosing vi.spyOn versus vi.mock, pool selection, sharding, happy-dom over jsdom, inline snapshots, and matcher selection. A companion AGENTS.md compiles everything into one automation-friendly guide.

The target users are frontend and full-stack engineers writing Vitest tests, teams migrating from Jest, and AI coding agents maintaining test suites. Typical use cases include speeding up CI, eliminating flaky async tests, and enforcing consistent testing conventions during code review. It explicitly excludes TDD methodology, MSW-based API mocking, and Jest-specific APIs, deferring those to sibling skills.

FAQ

What does this skill cover?

It provides 44 Vitest best-practice rules across 8 categories (async, setup/isolation, mocking, performance, snapshots, environment, assertions, organization), each with explanations and code examples in the references/ directory.

When should I use it?

When writing new Vitest tests, debugging flaky or slow tests, setting up test configuration, reviewing test code in PRs, migrating from Jest to Vitest, or optimizing CI test performance.

Does it cover TDD or MSW mocking?

No. It explicitly excludes TDD methodology (see the test-tdd skill), API mocking with MSW (see the test-msw skill), and Jest-specific APIs.

How is the content prioritized?

Rules are ranked by impact: Async Patterns and Test Setup & Isolation are CRITICAL, Mocking and Performance are HIGH, and Snapshot/Environment/Assertions/Organization range from MEDIUM to LOW.

Is there a machine-readable entry point?

Yes. SKILL.md offers a quick-reference index and AGENTS.md is a compiled comprehensive guide optimized for AI agents and LLMs.

All Files

51 files
CHANGELOG.md0.7 KB
View
README.md3.3 KB
View
AGENTS.md9.3 KB
View
metadata.json0.9 KB
View
references/assert-one-assertion-concept.md2.6 KB
View
references/async-concurrent-expect.md1.9 KB
View
assets/templates/_template.md0.9 KB
View
references/assert-edge-cases.md2.3 KB
View
references/async-act-wrapper.md2.4 KB
View
references/async-return-promises.md1.5 KB
View
references/env-setup-files.md2.3 KB
View
references/_sections.md1.9 KB
View
references/assert-toequal-vs-tobe.md2.1 KB
View
references/async-fake-timers.md2.0 KB
View
references/env-per-file-override.md2.1 KB
View
references/mock-msw-network.md2.6 KB
View
references/assert-expect-assertions.md2.3 KB
View
references/async-await-assertions.md1.3 KB
View
references/async-waitfor-polling.md1.8 KB
View
references/mock-avoid-overmocking.md2.8 KB
View
references/mock-type-safety.md2.4 KB
View
references/assert-specific-matchers.md2.1 KB
View
references/async-error-handling.md2.1 KB
View
references/env-globals-config.md1.8 KB
View
references/mock-implementation-not-value.md2.3 KB
View
references/org-describe-nesting.md2.4 KB
View
references/env-browser-api-mocking.md2.2 KB
View
references/mock-clear-between-tests.md2.1 KB
View
references/mock-vi-mock-hoisting.md2.1 KB
View
references/perf-bail-fast-fail.md1.7 KB
View
references/perf-sharding.md2.0 KB
View
references/mock-spyon-vs-mock.md2.4 KB
View
references/org-test-naming.md2.0 KB
View
references/perf-pool-selection.md1.9 KB
View
references/setup-beforeeach-cleanup.md1.9 KB
View
references/snap-describe-intent.md2.1 KB
View
references/org-file-colocation.md1.7 KB
View
references/perf-happy-dom.md1.9 KB
View
references/setup-beforeall-expensive.md2.3 KB
View
references/snap-avoid-large.md2.3 KB
View
SKILL.md5.0 KB
View
references/org-test-skip-only.md1.8 KB
View
references/perf-run-mode-ci.md1.6 KB
View
references/setup-reset-modules.md2.5 KB
View
references/snap-inline-over-file.md1.9 KB
View
references/perf-disable-isolation.md2.0 KB
View
references/setup-avoid-shared-state.md2.5 KB
View
references/setup-test-factories.md2.8 KB
View
references/snap-stable-serialization.md2.3 KB
View
references/setup-restore-mocks.md2.1 KB
View
references/snap-review-updates.md1.8 KB
View

Install vitest

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill