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.
Best use case
vitest is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
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.
Teams using vitest should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/vitest/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How vitest Compares
| Feature / Agent | vitest | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
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.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
SKILL.md Source
# Vitest Best Practices Comprehensive performance optimization and best practices guide for Vitest testing framework. Contains 44 rules across 8 categories, prioritized by impact to guide test writing, refactoring, and code review. ## When to Apply Reference these guidelines when: - Writing new Vitest tests - Debugging flaky or slow tests - Setting up test configuration - Reviewing test code in PRs - Migrating from Jest to Vitest - Optimizing CI/CD test performance ## Rule Categories by Priority | Priority | Category | Impact | Prefix | |----------|----------|--------|--------| | 1 | Async Patterns | CRITICAL | `async-` | | 2 | Test Setup & Isolation | CRITICAL | `setup-` | | 3 | Mocking Patterns | HIGH | `mock-` | | 4 | Performance | HIGH | `perf-` | | 5 | Snapshot Testing | MEDIUM | `snap-` | | 6 | Environment | MEDIUM | `env-` | | 7 | Assertions | LOW-MEDIUM | `assert-` | | 8 | Test Organization | LOW | `org-` | ## Quick Reference ### 1. Async Patterns (CRITICAL) - `async-await-assertions` - Await async assertions to prevent false positives - `async-return-promises` - Return promises from test functions - `async-fake-timers` - Use fake timers for time-dependent code - `async-waitfor-polling` - Use vi.waitFor for async conditions - `async-concurrent-expect` - Use test context expect in concurrent tests - `async-act-wrapper` - Await user events to avoid act warnings - `async-error-handling` - Test async error handling properly ### 2. Test Setup & Isolation (CRITICAL) - `setup-beforeeach-cleanup` - Clean up state in afterEach hooks - `setup-restore-mocks` - Restore mocks after each test - `setup-avoid-shared-state` - Avoid shared mutable state between tests - `setup-beforeall-expensive` - Use beforeAll for expensive one-time setup - `setup-reset-modules` - Reset modules when testing module state - `setup-test-factories` - Use test factories for complex test data ### 3. Mocking Patterns (HIGH) - `mock-vi-mock-hoisting` - Understand vi.mock hoisting behavior - `mock-spyon-vs-mock` - Choose vi.spyOn vs vi.mock appropriately - `mock-implementation-not-value` - Use mockImplementation for dynamic mocks - `mock-msw-network` - Use MSW for network request mocking - `mock-avoid-overmocking` - Avoid over-mocking - `mock-type-safety` - Maintain type safety in mocks - `mock-clear-between-tests` - Clear mock state between tests ### 4. Performance (HIGH) - `perf-pool-selection` - Choose the right pool for performance - `perf-disable-isolation` - Disable test isolation when safe - `perf-happy-dom` - Use happy-dom over jsdom when possible - `perf-sharding` - Use sharding for CI parallelization - `perf-run-mode-ci` - Use run mode in CI environments - `perf-bail-fast-fail` - Use bail for fast failure in CI ### 5. Snapshot Testing (MEDIUM) - `snap-inline-over-file` - Prefer inline snapshots for small values - `snap-avoid-large` - Avoid large snapshots - `snap-stable-serialization` - Ensure stable snapshot serialization - `snap-review-updates` - Review snapshot updates before committing - `snap-describe-intent` - Name snapshot tests descriptively ### 6. Environment (MEDIUM) - `env-per-file-override` - Override environment per file when needed - `env-setup-files` - Use setup files for global configuration - `env-globals-config` - Configure globals consistently - `env-browser-api-mocking` - Mock browser APIs not available in test environment ### 7. Assertions (LOW-MEDIUM) - `assert-specific-matchers` - Use specific matchers over generic ones - `assert-edge-cases` - Test edge cases and boundaries - `assert-one-assertion-concept` - Test one concept per test - `assert-expect-assertions` - Use expect.assertions for async tests - `assert-toequal-vs-tobe` - Choose toBe vs toEqual correctly ### 8. Test Organization (LOW) - `org-file-colocation` - Colocate test files with source files - `org-describe-nesting` - Use describe blocks for logical grouping - `org-test-naming` - Write descriptive test names - `org-test-skip-only` - Use skip and only appropriately ## How to Use Read individual reference files for detailed explanations and code examples: - [Section definitions](references/_sections.md) - Category structure and impact levels - [Rule template](assets/templates/_template.md) - Template for adding new rules - [async-await-assertions](references/async-await-assertions.md) - Example rule file - [mock-vi-mock-hoisting](references/mock-vi-mock-hoisting.md) - Example rule file ## Related Skills - For TDD methodology, see `test-tdd` skill - For API mocking with MSW, see `test-msw` skill - For TypeScript testing patterns, see `typescript` skill ## Full Compiled Document For the complete guide with all rules expanded: `AGENTS.md`
Related Skills
wemp-operator
> 微信公众号全功能运营——草稿/发布/评论/用户/素材/群发/统计/菜单/二维码 API 封装
zsxq-smart-publish
Publish and manage content on 知识星球 (zsxq.com). Supports talk posts, Q&A, long articles, file sharing, digest/bookmark, homework tasks, and tag management. Use when publishing content to 知识星球, creating/editing posts, uploading files/images/audio, managing digests, batch publishing, or formatting content for 知识星球.
zoom-automation
Automate Zoom meeting creation, management, recordings, webinars, and participant tracking via Rube MCP (Composio). Always search tools first for current schemas.
zoho-crm-automation
Automate Zoho CRM tasks via Rube MCP (Composio): create/update records, search contacts, manage leads, and convert leads. Always search tools first for current schemas.
ziliu-publisher
字流(Ziliu) - AI驱动的多平台内容分发工具。用于一次创作、智能适配排版、一键分发到16+平台(公众号/知乎/小红书/B站/抖音/微博/X等)。当用户需要多平台发布、内容排版、格式适配时使用。触发词:字流、ziliu、多平台发布、一键分发、内容分发、排版发布。
zhihu-post-skill
> 知乎文章发布——知乎平台内容创作与发布自动化
zendesk-automation
Automate Zendesk tasks via Rube MCP (Composio): tickets, users, organizations, replies. Always search tools first for current schemas.
youtube-knowledge-extractor
This skill performs deep analysis of YouTube videos through **both information channels** Multimodal YouTube video analysis through both audio (transcript) and visual (frame extraction + image analysis) channels. Especially powerful for HowTo videos, tutorials, demos, and explainer videos where what is SHOWN (screenshots, UI demos, diagrams, code, physical actions) is just as important as what is SAID. Use this skill whenever a user wants to analyze, summarize, or create step-by-step guides from YouTube videos, or when they share a YouTube URL and want to understand what happens in the video. Triggers on requests like "Analyze this YouTube video", "Create a step-by-step guide from this video", "What does this video show?", "Summarize this tutorial", or any YouTube URL shared with analysis intent.
youtube-factory
Generate complete YouTube videos from a single prompt - script, voiceover, stock footage, captions, thumbnail. Self-contained, no external modules. 100% free tools.
youtube-automation
Automate YouTube tasks via Rube MCP (Composio): upload videos, manage playlists, search content, get analytics, and handle comments. Always search tools first for current schemas.
xlsx
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
xiaomo-assistant-template
小a助手配置模板。基于 xiaomo-starter-kit 改编,提供预配置的 OpenClaw 助手框架文件。当用户需要快速配置新助手、设置助手身份、创建助手配置文件时使用此技能。