vitest

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Vitest is a next-generation testing framework powered by Vite. It provides a Jest-compatible API with native ESM, TypeScript, and JSX support out of the box. Vitest shares the same config, transformers, resolvers, and plugins with your Vite app.
Key Features:
  • Vite-native: Uses Vite's transformation pipeline for fast HMR-like test updates
  • Jest-compatible: Drop-in replacement for most Jest test suites
  • Smart watch mode: Only reruns affected tests based on module graph
  • Native ESM, TypeScript, JSX support without configuration
  • Multi-threaded workers for parallel test execution
  • Built-in coverage via V8 or Istanbul
  • Snapshot testing, mocking, and spy utilities
The skill is based on Vitest 3.x, generated at 2026-01-28.
Vitest 是由 Vite 驱动的下一代测试框架。它提供与 Jest 兼容的 API,原生支持 ESM、TypeScript 和 JSX,无需额外配置。Vitest 与你的 Vite 应用共享相同的配置、转换器、解析器和插件。
核心特性:
  • 基于Vite原生:使用Vite的转换流水线实现类HMR的快速测试更新
  • 兼容Jest:可直接替代大多数Jest测试套件
  • 智能监听模式:基于模块图谱仅重新运行受影响的测试
  • 原生支持ESM、TypeScript和JSX,无需配置
  • 多线程工作器支持并行测试执行
  • 通过V8或Istanbul提供内置覆盖率统计
  • 支持快照测试、模拟和间谍工具
本技能基于 Vitest 3.x 版本生成,生成日期为2026年1月28日。

Core

核心功能

TopicDescriptionReference
ConfigurationVitest and Vite config integration, defineConfig usagecore-config
CLICommand line interface, commands and optionscore-cli
Test APItest/it function, modifiers like skip, only, concurrentcore-test-api
Describe APIdescribe/suite for grouping tests and nested suitescore-describe
Expect APIAssertions with toBe, toEqual, matchers and asymmetric matcherscore-expect
HooksbeforeEach, afterEach, beforeAll, afterAll, aroundEachcore-hooks
主题描述参考文档
配置Vitest 与 Vite 配置集成,defineConfig 的使用core-config
命令行界面(CLI)命令行界面,命令及选项core-cli
测试APItest/it 函数,skip、only、concurrent 等修饰符core-test-api
Describe API使用 describe/suite 分组测试及嵌套测试套件core-describe
Expect API包含 toBe、toEqual、匹配器和非对称匹配器的断言core-expect
钩子函数beforeEach、afterEach、beforeAll、afterAll、aroundEachcore-hooks

Features

扩展功能

TopicDescriptionReference
MockingMock functions, modules, timers, dates with vi utilitiesfeatures-mocking
SnapshotsSnapshot testing with toMatchSnapshot and inline snapshotsfeatures-snapshots
CoverageCode coverage with V8 or Istanbul providersfeatures-coverage
Test ContextTest fixtures, context.expect, test.extend for custom fixturesfeatures-context
ConcurrencyConcurrent tests, parallel execution, shardingfeatures-concurrency
FilteringFilter tests by name, file patterns, tagsfeatures-filtering
主题描述参考文档
模拟使用 vi 工具类实现模拟函数、模块、计时器、日期features-mocking
快照测试使用 toMatchSnapshot 和内联快照进行快照测试features-snapshots
覆盖率通过 V8 或 Istanbul 提供代码覆盖率统计features-coverage
测试上下文测试夹具、context.expect、test.extend 自定义夹具features-context
并发并发测试、并行执行、分片features-concurrency
过滤按名称、文件模式、标签过滤测试features-filtering

Advanced

进阶功能

TopicDescriptionReference
Vi Utilitiesvi helper: mock, spyOn, fake timers, hoisted, waitForadvanced-vi
EnvironmentsTest environments: node, jsdom, happy-dom, customadvanced-environments
Type TestingType-level testing with expectTypeOf and assertTypeadvanced-type-testing
ProjectsMulti-project workspaces, different configs per projectadvanced-projects
主题描述参考文档
Vi 工具类vi 辅助工具:mock、spyOn、假计时器、hoisted、waitForadvanced-vi
测试环境测试环境:node、jsdom、happy-dom、自定义环境advanced-environments
类型测试使用 expectTypeOf 和 assertType 进行类型级测试advanced-type-testing
多项目多项目工作区,每个项目可配置不同的设置advanced-projects