vitest
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to use this skill
何时使用本技能
Use this skill whenever the user wants to:
- Set up Vitest in a Vite project
- Write unit tests and component tests
- Configure Vitest for different environments
- Use Vitest API and utilities
- Test Vue, React, or Svelte components
- Use browser mode for testing
- Set up visual regression testing
- Mock functions and modules
- Use snapshots for testing
- Configure test coverage
- Use Vitest UI
- Optimize test performance
- Debug tests
- Understand Vitest best practices
- Troubleshoot Vitest issues
当用户有以下需求时,可使用本技能:
- 在Vite项目中搭建Vitest
- 编写单元测试和组件测试
- 为不同环境配置Vitest
- 使用Vitest API及工具
- 测试Vue、React或Svelte组件
- 使用浏览器模式进行测试
- 搭建视觉回归测试
- 模拟函数和模块
- 使用快照进行测试
- 配置测试覆盖率
- 使用Vitest UI
- 优化测试性能
- 调试测试
- 了解Vitest最佳实践
- 排查Vitest问题
How to use this skill
如何使用本技能
This skill is organized to match the Vitest official documentation structure (https://vitest.dev/guide/, https://vitest.dev/api/, https://vitest.dev/config/). When working with Vitest:
-
Identify the topic from the user's request:
- Getting started/快速开始 →
examples/getting-started.md - Features/功能特性 →
examples/features.md - Component testing/组件测试 →
examples/component-testing.md - Browser mode/浏览器模式 →
examples/browser-mode.md - API/API 文档 →
api/ - Configuration/配置 →
examples/config/
- Getting started/快速开始 →
-
Load the appropriate example file from thedirectory:
examples/Getting Started (快速开始):- - Installation and first test
examples/getting-started.md
Features (功能特性):- - Key features and capabilities
examples/features.md - - Vitest UI
examples/ui.md - - Component testing
examples/component-testing.md - - Browser mode testing
examples/browser-mode.md - - Visual regression testing
examples/visual-regression-testing.md - - Trace view
examples/trace-view.md
Testing (测试):- - Test API (test, it, describe, etc.)
examples/test-api.md - - Mocking functions and modules
examples/mocking.md - - Snapshot testing
examples/snapshots.md - - Code coverage
examples/coverage.md
Configuration (配置):- - Basic configuration
examples/config/basic-config.md - - Environment configuration
examples/config/environment.md - - Browser mode configuration
examples/config/browser-config.md
-
Follow the specific instructions in that example file for syntax, structure, and best practicesImportant Notes:
- Vitest is designed for Vite projects
- Supports TypeScript, JSX, ESM out of the box
- Fast watch mode with HMR-like experience
- Compatible with Jest API
- Examples include both JavaScript and TypeScript versions
- Each example file includes key concepts, code examples, and key points
-
Reference API documentation in thedirectory when needed:
api/- - Test API reference
api/test-api.md - - vi utility functions
api/vi-utility.md - - Expect assertions
api/expect.md - - Mocking API
api/mocking.md
-
Use templates from thedirectory:
templates/- - Vitest configuration templates
templates/vitest-config.md - - Test example templates
templates/test-examples.md
本技能的组织结构与Vitest官方文档结构一致(https://vitest.dev/guide/、https://vitest.dev/api/、https://vitest.dev/config/)。使用Vitest时:
-
从用户需求中确定主题:
- 快速开始 →
examples/getting-started.md - 功能特性 →
examples/features.md - 组件测试 →
examples/component-testing.md - 浏览器模式 →
examples/browser-mode.md - API文档 →
api/ - 配置 →
examples/config/
- 快速开始 →
-
从目录中加载对应的示例文件:
examples/快速开始:- - 安装与首个测试
examples/getting-started.md
功能特性:- - 核心功能与能力
examples/features.md - - Vitest UI
examples/ui.md - - 组件测试
examples/component-testing.md - - 浏览器模式测试
examples/browser-mode.md - - 视觉回归测试
examples/visual-regression-testing.md - - 追踪视图
examples/trace-view.md
测试:- - 测试API(test、it、describe等)
examples/test-api.md - - 模拟函数和模块
examples/mocking.md - - 快照测试
examples/snapshots.md - - 代码覆盖率
examples/coverage.md
配置:- - 基础配置
examples/config/basic-config.md - - 环境配置
examples/config/environment.md - - 浏览器模式配置
examples/config/browser-config.md
-
遵循示例文件中的具体说明,包括语法、结构和最佳实践重要说明:
- Vitest专为Vite项目设计
- 原生支持TypeScript、JSX、ESM
- 具备类HMR体验的快速监视模式
- 兼容Jest API
- 示例包含JavaScript和TypeScript两种版本
- 每个示例文件都涵盖核心概念、代码示例和关键点
-
必要时参考目录中的API文档:
api/- - 测试API参考
api/test-api.md - - vi工具函数
api/vi-utility.md - - Expect断言
api/expect.md - - 模拟API
api/mocking.md
-
使用目录中的模板:
templates/- - Vitest配置模板
templates/vitest-config.md - - 测试示例模板
templates/test-examples.md
Doc mapping (one-to-one with https://vitest.dev/guide/, https://vitest.dev/api/, https://vitest.dev/config/)
Guide (指南):
- → https://vitest.dev/guide/getting-started.html
examples/getting-started.md - → https://vitest.dev/guide/features.html
examples/features.md - → https://vitest.dev/guide/ui.html
examples/ui.md - → https://vitest.dev/guide/testing-components.html
examples/component-testing.md - → https://vitest.dev/guide/browser.html
examples/browser-mode.md - → https://vitest.dev/guide/visual-regression.html
examples/visual-regression-testing.md - → https://vitest.dev/guide/trace-view.html
examples/trace-view.md - → https://vitest.dev/guide/mocking.html
examples/mocking.md - → https://vitest.dev/guide/snapshot.html
examples/snapshots.md - → https://vitest.dev/guide/coverage.html
examples/coverage.md
Configuration (配置):
- → https://vitest.dev/config/
examples/config/basic-config.md - → https://vitest.dev/config/#environment
examples/config/environment.md - → https://vitest.dev/config/#browser
examples/config/browser-config.md
API Reference:
- → https://vitest.dev/api/
api/test-api.md - → https://vitest.dev/api/vi.html
api/vi-utility.md - → https://vitest.dev/api/expect.html
api/expect.md - → https://vitest.dev/api/vi.html
api/mocking.md
指南:
- → https://vitest.dev/guide/getting-started.html
examples/getting-started.md - → https://vitest.dev/guide/features.html
examples/features.md - → https://vitest.dev/guide/ui.html
examples/ui.md - → https://vitest.dev/guide/testing-components.html
examples/component-testing.md - → https://vitest.dev/guide/browser.html
examples/browser-mode.md - → https://vitest.dev/guide/visual-regression.html
examples/visual-regression-testing.md - → https://vitest.dev/guide/trace-view.html
examples/trace-view.md - → https://vitest.dev/guide/mocking.html
examples/mocking.md - → https://vitest.dev/guide/snapshot.html
examples/snapshots.md - → https://vitest.dev/guide/coverage.html
examples/coverage.md
配置:
- → https://vitest.dev/config/
examples/config/basic-config.md - → https://vitest.dev/config/#environment
examples/config/environment.md - → https://vitest.dev/config/#browser
examples/config/browser-config.md
API参考:
- → https://vitest.dev/api/
api/test-api.md - → https://vitest.dev/api/vi.html
api/vi-utility.md - → https://vitest.dev/api/expect.html
api/expect.md - → https://vitest.dev/api/vi.html
api/mocking.md
Examples and Templates
示例与模板
This skill includes detailed examples organized to match the official documentation structure. All examples are in the directory (see mapping above).
examples/To use examples:
- Identify the topic from the user's request
- Load the appropriate example file from the mapping above
- Follow the instructions, syntax, and best practices in that file
- Adapt the code examples to your specific use case
To use templates:
- Reference templates in directory for common scaffolding
templates/ - Adapt templates to your specific needs and coding style
本技能包含与官方文档结构匹配的详细示例,所有示例都位于目录中(见上述映射)。
examples/使用示例:
- 从用户需求中确定主题
- 根据上述映射加载对应的示例文件
- 遵循文件中的说明、语法和最佳实践
- 根据具体用例调整代码示例
使用模板:
- 参考目录中的模板进行常见脚手架搭建
templates/ - 根据具体需求和编码风格调整模板
Best Practices
最佳实践
- Use watch mode: Leverage Vitest's smart watch mode for faster feedback
- Organize tests: Group related tests with describe blocks
- Use TypeScript: Take advantage of native TypeScript support
- Mock effectively: Use vi.mock() for module mocking
- Test components: Use component testing for Vue/React components
- Use UI mode: Use flag for better test debugging experience
--ui - Optimize performance: Use test.only() during development
- 使用监视模式:利用Vitest的智能监视模式获取更快的反馈
- 组织测试:使用describe块对相关测试进行分组
- 使用TypeScript:利用原生TypeScript支持
- 高效模拟:使用vi.mock()进行模块模拟
- 测试组件:对Vue/React组件进行组件测试
- 使用UI模式:使用标志获得更好的测试调试体验
--ui - 优化性能:开发期间使用test.only()
Resources
资源
- Official Documentation: https://vitest.dev/
- Getting Started: https://vitest.dev/guide/
- API Reference: https://vitest.dev/api/
- Configuration: https://vitest.dev/config/
- GitHub Repository: https://github.com/vitest-dev/vitest
Keywords
关键词
Vitest, vitest, test framework, unit testing, component testing, Vite, Jest compatible, watch mode, HMR, TypeScript, ESM, mocking, snapshots, coverage, browser mode, visual regression testing, 测试框架, 单元测试, 组件测试, 监视模式, 热模块替换, 模拟, 快照, 覆盖率, 浏览器模式, 视觉回归测试
Vitest, vitest, test framework, unit testing, component testing, Vite, Jest compatible, watch mode, HMR, TypeScript, ESM, mocking, snapshots, coverage, browser mode, visual regression testing, 测试框架, 单元测试, 组件测试, 监视模式, 热模块替换, 模拟, 快照, 覆盖率, 浏览器模式, 视觉回归测试