vitest
できること
このスキルは、Viteプロジェクトと一緒に動くテストツールVitestで、自動テストを書いて実行する方法を説明します。Jestに似た書き方で、すばやくテストしたい開発者のためのものです。
使う場面
- ✓関数やコンポーネントのユニットテストを書く必要があるとき。
- ✓モック、スパイ、スナップショットテストを追加したいとき。
- ✓テストのカバレッジを設定したり、実行するテストを選んだりしたいとき。
スキルのリンク
https://github.com/antfu/skills/blob/main/skills/vitest/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“価格計算の関数に対するVitestのユニットテストを書いてください。境界値のケースも含めてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、Vitestのtest、describe、expectの関数を使い、プロジェクトの設定に従います。ウォッチモードでは、変更の影響を受けたテストだけを再実行します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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 |
よくある質問
VitestはJestに似ていますか?
はい。APIはほとんどのJestのテストスイートと互換性があるため、多くのテストを簡単に移行できます。
テストのカバレッジを測れますか?
はい。V8またはIstanbulでカバレッジを収集できます。
TypeScriptに追加の設定が必要ですか?
いいえ。TypeScript、ESモジュール、JSXは追加の設定なしで動きます。
詳細
作者による元の説明
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
人気
- GitHubのスター
- 6.0k
- ランキング
- #14447
- ライセンス
- MIT
- 更新日
- 2026/10/30
コメント
- …
このリポジトリの他のスキル
antfu-create-pr
6.0kブランチから、変更内容と理由をわかりやすくまとめたGitHubのプルリクエストを、エージェントが開けるよう支援します。
antfu-issue-triage
6.0k開いているGitHubのissueとプルリクエストを整理し、重複や修正済みのものを見つけて、操作の前に確認を取るようエージェントを支援します。
antfu-query
6.0k計画やアイデアについて一度に一つずつ質問し、二人で明確でテスト済みの理解に至るまでエージェントが問いかけます。
antfu-simplify
6.0kコードの変更を、必要な部分だけを残した最小限の正しい形に減らすようエージェントを支援します。
似ているスキル
test-driven-development
311k機能や修正を作る前に、まず失敗するテストを書き、それが失敗するのを確認してから、合格させる最小のコードを書くようエージェントに教えます。
verification-before-completion
311kタスク、修正、ビルドが完了した、または合格したと主張する前に、実際のチェックを実行し、その出力を読むようエージェントに教えます。
migrate-to-shoehorn
310kテストファイル内の危険な型キャストを、shoehornライブラリに置き換え、テストが部分的なデータを使いつつ型チェックを通るようにします。