Chuyển đến nội dung
Skillpedia
Kiểm thử6.0k · #14447

vitest

Skill này làm gì

Skill này giải thích cách viết và chạy các bài kiểm thử tự động bằng Vitest, một công cụ kiểm thử hoạt động với dự án Vite. Skill dành cho lập trình viên muốn kiểm thử nhanh theo phong cách giống Jest.

Khi nào nên dùng

  • ✓Khi bạn cần viết kiểm thử đơn vị cho hàm hoặc component.
  • ✓Khi bạn muốn thêm mock, spy hoặc kiểm thử snapshot.
  • ✓Khi bạn muốn thiết lập độ phủ kiểm thử hoặc chọn kiểm thử nào sẽ chạy.

Liên kết skill

https://github.com/antfu/skills/blob/main/skills/vitest/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/antfu/skills/blob/main/skills/vitest/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Viết các bài kiểm thử đơn vị Vitest cho hàm tính giá của tôi, bao gồm cả các trường hợp biên.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent dùng các hàm test, describe và expect của Vitest và làm theo cấu hình của dự án. Ở chế độ theo dõi, Vitest chỉ chạy lại các bài kiểm thử bị ảnh hưởng bởi thay đổi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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 5.1.0-beta.1, generated at 2026-10-23.

Core

Topic Description Reference
Configuration Vitest and Vite config integration, defineConfig usage core-config
CLI Command line interface, commands and options core-cli
Test API test/it function, modifiers like skip, only, concurrent core-test-api
Describe API describe/suite for grouping tests and nested suites core-describe
Expect API Assertions with toBe, toEqual, matchers and asymmetric matchers core-expect
Hooks beforeEach, afterEach, beforeAll, afterAll, aroundEach core-hooks

Features

Topic Description Reference
Mocking Mock functions, modules, timers, dates with vi utilities features-mocking
Snapshots Snapshot testing with toMatchSnapshot and inline snapshots features-snapshots
Coverage Code coverage with V8 or Istanbul providers features-coverage
Test Context Test fixtures, context.expect, test.extend for custom fixtures features-context
Concurrency Concurrent tests, parallel execution, sharding features-concurrency
Filtering Filter tests by name, file patterns, tags features-filtering
Test Tags Label tests with tags to filter runs and apply shared options features-test-tags
Reporters Built-in reporters, default selection, CI/output config features-reporters
Benchmarking Write benchmarks with the bench fixture (Tinybench) features-benchmarking

Advanced

Topic Description Reference
Vi Utilities vi helper: mock, spyOn, fake timers, hoisted, waitFor advanced-vi
Environments Test environments: node, jsdom, happy-dom, custom advanced-environments
Type Testing Type-level testing with expectTypeOf and assertType advanced-type-testing
Projects Multi-project workspaces, different configs per project advanced-projects
Câu hỏi thường gặp

Vitest có giống Jest không?

Có. API của Vitest tương thích với hầu hết các bộ kiểm thử Jest, nên nhiều bài kiểm thử có thể chuyển sang dễ dàng.

Vitest có đo độ phủ kiểm thử không?

Có. Độ phủ có thể được thu thập bằng V8 hoặc Istanbul.

Có cần thiết lập thêm cho TypeScript không?

Không. TypeScript, ES module và JSX hoạt động mà không cần cấu hình thêm.

Chi tiết

Mô tả gốc của tác giả

Vitest fast unit testing framework powered by Vite with Jest-compatible API. Use when writing tests, mocking, configuring coverage, or working with test filtering and fixtures.

repo: antfu/skills

Độ phổ biến

Sao GitHub
6.0k
Vị trí xếp hạng
#14447
Giấy phép
MIT
Cập nhật
30/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự