vitest
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVitest
Vitest
Vite-native testing framework with Jest-compatible API.
一款与Jest API兼容的Vite原生测试框架。
When to Use
使用场景
- Writing unit/integration tests for Vite projects
- Testing Vue/React/Svelte components
- Mocking modules, timers, or dates
- Running concurrent/parallel tests
- Type testing with TypeScript
- 为Vite项目编写单元/集成测试
- 测试Vue/React/Svelte组件
- 模拟模块、计时器或日期
- 运行并发/并行测试
- 使用TypeScript进行类型测试
Quick Start
快速开始
bash
npm i -D vitestts
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'node', // or 'jsdom' for DOM tests
},
})ts
// example.test.ts
import { describe, expect, it, vi } from 'vitest'
describe('math', () => {
it('adds numbers', () => {
expect(1 + 1).toBe(2)
})
})bash
npm i -D vitestts
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'node', // or 'jsdom' for DOM tests
},
})ts
// example.test.ts
import { describe, expect, it, vi } from 'vitest'
describe('math', () => {
it('adds numbers', () => {
expect(1 + 1).toBe(2)
})
})Reference Files
参考文件
| Task | File |
|---|---|
| Configuration, CLI, projects | config.md |
| test/describe, hooks, fixtures | test-api.md |
| vi.fn, vi.mock, timers, spies | mocking.md |
| expect, snapshots, coverage, filtering | utilities.md |
| Environments, type testing, browser mode | advanced.md |
| 任务 | 文件 |
|---|---|
| 配置、CLI、项目 | config.md |
| test/describe、钩子、测试夹具 | test-api.md |
| vi.fn、vi.mock、计时器、间谍 | mocking.md |
| expect、快照、覆盖率、过滤 | utilities.md |
| 测试环境、类型测试、浏览器模式 | advanced.md |
Loading Files
文件加载建议
Consider loading these reference files based on your task:
- references/config.md - if setting up vitest.config.ts, CLI, or workspace projects
- references/test-api.md - if writing test/describe blocks, using hooks, or test fixtures
- references/mocking.md - if mocking modules, timers, dates, or using spies
- references/utilities.md - if writing assertions, snapshots, or configuring coverage
- references/advanced.md - if configuring test environments, type testing, or browser mode
DO NOT load all files at once. Load only what's relevant to your current task.
请根据当前任务加载对应的参考文件:
- references/config.md - 若需设置vitest.config.ts、CLI或工作区项目
- references/test-api.md - 若需编写test/describe代码块、使用钩子或测试夹具
- references/mocking.md - 若需模拟模块、计时器、日期或使用间谍
- references/utilities.md - 若需编写断言、快照或配置覆盖率
- references/advanced.md - 若需配置测试环境、类型测试或浏览器模式
请勿一次性加载所有文件。仅加载与当前任务相关的文件。
Cross-Skill References
跨技能参考
- Vue component testing → Use skill for component patterns
vue - Library testing → Use skill for library patterns
ts-library - Vite configuration → Use skill for shared config
vite
- Vue组件测试 → 使用技能获取组件模式
vue - 库测试 → 使用技能获取库模式
ts-library - Vite配置 → 使用技能获取共享配置
vite