本文へスキップ
Skillpedia
テスト6.0k · #14447

vitest

できること

このスキルは、Viteプロジェクトと一緒に動くテストツールVitestで、自動テストを書いて実行する方法を説明します。Jestに似た書き方で、すばやくテストしたい開発者のためのものです。

使う場面

  • ✓関数やコンポーネントのユニットテストを書く必要があるとき。
  • ✓モック、スパイ、スナップショットテストを追加したいとき。
  • ✓テストのカバレッジを設定したり、実行するテストを選んだりしたいとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/antfu/skills/blob/main/skills/vitest/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル