本文へ移動
cccskills
無料GitHub で公開

vitest

Assists with unit and integration testing using Vitest, a Vite-native test runner. Use when writing tests, configuring mocks, setting up coverage, or migrating from Jest. Trigger words: vitest, unit testing, test runner, vi.fn, vi.mock, test coverage, jest replacement.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md3.6 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Vitest

Overview

Vitest is a Vite-native test runner that provides a Jest-compatible API with native ESM support, instant watch mode via Vite's HMR, and shared Vite configuration for aliases, plugins, and transforms. It serves as a drop-in Jest replacement with significantly faster startup and execution.

Instructions

  • When writing tests, use describe() blocks to group related tests, it() or test() for individual cases, and follow the pattern of naming tests as behavior descriptions (e.g., "should return 404 when user not found").
  • When mocking, use vi.fn() for function mocks, vi.mock("./module") for module mocks, vi.useFakeTimers() for timer control, and vi.setSystemTime() for date mocking.
  • When setting up assertions, use toBe() for primitives, toEqual() for objects/arrays, and toMatchInlineSnapshot() for small expected outputs.
  • When configuring, define test settings in vite.config.ts under the test property or in a separate vitest.config.ts, choosing the appropriate environment (jsdom, happy-dom, node).
  • When measuring coverage, use @vitest/coverage-v8 with vitest --coverage and set minimum thresholds in CI with --coverage.thresholds.lines=80.
  • When testing in browsers, use @vitest/browser with Playwright or WebDriverIO providers for real DOM testing instead of jsdom simulation.
  • When working in monorepos, use vitest.workspace.ts for multi-project configuration that shares common settings.

Examples

Example 1: Test a service with API mocking

User request: "Write Vitest tests for a user service that calls an external API"

Actions:

  1. Mock the HTTP module with vi.mock() to intercept API calls
  2. Write tests for success, error, and edge cases using describe and it
  3. Assert responses with toEqual() and error handling with toThrow()
  4. Use beforeEach with vi.clearAllMocks() for test isolation

Output: Isolated unit tests for the user service with mocked external dependencies.

Example 2: Migrate from Jest to Vitest

User request: "Switch our test suite from Jest to Vitest"

Actions:

  1. Install vitest and add test config to vite.config.ts
  2. Replace jest.fn() with vi.fn() and jest.mock() with vi.mock()
  3. Update package.json scripts to use vitest and vitest --coverage
  4. Remove ts-jest, babel-jest, and Jest config files

Output: A Vitest-powered test suite with the same tests running faster with native ESM support.

Guidelines

  • Use describe blocks to group related tests; keep individual tests focused on one behavior.
  • Prefer toEqual() for objects/arrays and toBe() for primitives.
  • Mock external dependencies (HTTP, database), not internal modules; test real integration where possible.
  • Use beforeEach for test isolation, not beforeAll; shared state between tests causes flaky results.
  • Name tests as behavior descriptions: "should return 404 when user not found", not "test getUserById".
  • Use inline snapshots for small expected outputs; file snapshots for large/complex structures.
  • Run vitest --coverage in CI with a minimum threshold: --coverage.thresholds.lines=80.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Audit web pages and components for WCAG 2.2 accessibility compliance. Use when a user asks to check accessibility, find a11y issues, audit for WCAG compliance, fix screen reader problems, check color contrast, ensure keyboard navigation works, or prepare for accessibility regulations like the European Accessibility Act or ADA.

日本語の概要は準備中です。原文の説明を表示しています。

jaem1n207/synchronize-tab-scrolling192026年10月12日 更新

Perform thorough code reviews with actionable, prioritized feedback. Use when a user asks to review code, check code quality, find bugs, review a pull request, audit code for issues, or get feedback on implementation. Covers correctness, security, performance, readability, and best practices across languages.

日本語の概要は準備中です。原文の説明を表示しています。

jaem1n207/synchronize-tab-scrolling192026年10月12日 更新

eslint

無料

ESLint is the standard linting tool for JavaScript and TypeScript projects. It statically analyzes your code to find problems, enforce coding conventions, and catch bugs before they reach production. ESLint 9 introduced the flat config format, replacing the legacy `.eslintrc` system with a simpler, more composable `eslint.config.js` file. With a rich plugin ecosystem covering React, TypeScript, accessibility, and import ordering, ESLint is the backbone of code quality in modern web development.

日本語の概要は準備中です。原文の説明を表示しています。

jaem1n207/synchronize-tab-scrolling192026年10月12日 更新

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.

日本語の概要は準備中です。原文の説明を表示しています。

jaem1n207/synchronize-tab-scrolling192026年10月12日 更新

github

無料

GitHub patterns using gh CLI for pull requests, stacked PRs, code review, branching strategies, and repository automation. Use when working with GitHub PRs, merging strategies, or repository management tasks.

日本語の概要は準備中です。原文の説明を表示しています。

jaem1n207/synchronize-tab-scrolling192026年10月12日 更新

GitHub Actions workflow patterns for React Native iOS simulator and Android emulator cloud builds with downloadable artifacts. Use when setting up CI build pipelines or downloading GitHub Actions artifacts via gh CLI and GitHub API.

日本語の概要は準備中です。原文の説明を表示しています。

jaem1n207/synchronize-tab-scrolling192026年10月12日 更新

jaem1n207 のスキルをすべて見る

このスキルの問題を報告する