Skip to content
cccskills
FreePublished on GitHub

unit-vitest

Use this skill when writing unit tests, mocking dependencies, testing pure functions, or measuring coverage with Vitest. Trigger words: ユニットテスト, 単体テスト, Vitest, モック, テストを書く, カバレッジ, describe, it, expect, vi.mock.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md2.0 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

ユニットテスト(Vitest)

いつ使うか

  • 純粋関数・バリデーション・ユーティリティのロジックを検証するとき。
  • 依存(DB・外部 API)をモックして単体で速くテストするとき。

やること

  • 1 テスト 1 振る舞い。AAA(Arrange / Act / Assert)で書く。
  • 入出力の対応を表で考え、境界値・異常系を必ず含める。
  • 外部依存は vi.mock で差し替え、ロジックだけを検証する。
  • Zod スキーマは「通る値/弾く値」の両方をテストする。
  • カバレッジは目安(ユニット ≥80%)だが、数値より重要パスの網羅を優先。

守るルール

  • ✅ 境界値・空・異常系を含める。
  • ✅ 依存はモックして単体を高速・決定的に保つ。
  • ✅ テスト名は日本語で「何を期待するか」を表す。
  • ❌ 実装の内部実装に密結合したテストにしない(振る舞いを検証)。
  • ❌ ランダム/時刻に依存して落ちるテストを書かない(固定/注入する)。

典型例(コード片)

// lib/price.test.ts
import { describe, it, expect } from 'vitest';
import { applyDiscount } from './price';

describe('applyDiscount', () => {
  it('10% 割引を正しく計算する', () => {
    expect(applyDiscount(1000, 0.1)).toBe(900);
  });
  it('割引率が範囲外なら例外', () => {
    expect(() => applyDiscount(1000, 1.5)).toThrow();
  });
});

アンチパターン

  • 1 テストに複数の振る舞いを詰め込み、失敗箇所が分からない。
  • 正常系だけ書いて境界・異常系を無視する。
  • Date.now() を直接使い、実行時刻でテストが揺れる。

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Use this skill when creating or reviewing Next.js Route Handlers (app/api), adding rate limiting, input validation, or auth to API endpoints. Trigger words: API ルート, Route Handler, app/api, エンドポイント, レート制限, 入力検証, CORS, ヘッダー, 認証付き API, hardening.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when implementing full-text search, autocomplete, or vector/semantic search and RAG with MongoDB Atlas. Trigger words: 全文検索, あいまい検索, オートコンプリート, ベクトル検索, セマンティック検索, 類似検索, Atlas Search, $search, $vectorSearch, RAG, embedding.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when implementing sign-in, sessions, authorization checks, or protecting routes and Server Actions. Trigger words: 認証, ログイン, サインイン, セッション, 認可, 権限チェック, Better Auth, Auth.js, 保護, ミドルウェア, getSession.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when starting a new session, opening this project for the first time, or when you need to recall the project's tech stack, hard rules, and which other skills exist. Trigger words: セッション開始, このプロジェクト, 全体像, どのスキル, 何から, getting started, overview.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when setting up or modifying CI pipelines, GitHub Actions workflows, or automated checks (lint, typecheck, test, build) for this project. Trigger words: CI, GitHub Actions, ワークフロー, パイプライン, 自動テスト, lint チェック, typecheck, ビルド検証, .github/workflows.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when writing end-to-end tests, browser automation, or verifying user flows in a real browser. Trigger words: E2E, Playwright, ブラウザテスト, ユーザーフロー, 結合テスト, シナリオテスト, ログインテスト, getByRole, expect.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

See all skills by Akira-Papa

Report a problem with this skill