スキル一覧に戻る
DaveHudson

tdd

by DaveHudson

0🍴 0📅 2026年1月11日
GitHubで見るManusで実行

SKILL.md


name: tdd description: Test-Driven Development workflow and patterns. Auto-loads when writing tests, creating components with tests, or following TDD methodology.

TDD workflow for React/TypeScript development using Vitest and Testing Library.

For testing patterns, see testing-patterns.md. For Storybook patterns, see storybook-patterns.md.


RED-GREEN-REFACTOR Workflow

ALWAYS follow this order:

Phase 1: RED (Write Failing Test)

import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ComponentName } from "./ComponentName";

describe("ComponentName", () => {
  it("renders without crashing", () => {
    render(<ComponentName />);
    expect(screen.getByRole("...")).toBeInTheDocument();
  });

  it("handles user interactions", async () => {
    const user = userEvent.setup();
    const handleClick = vi.fn();
    render(<ComponentName onClick={handleClick} />);
    await user.click(screen.getByRole("button"));
    expect(handleClick).toHaveBeenCalledTimes(1);
  });
});

Run test. Expected: Tests FAIL (component doesn't exist)

Phase 2: GREEN (Minimal Implementation)

"use client"; // Only if client component

interface ComponentNameProps {
  onClick?: () => void;
}

export function ComponentName({ onClick }: ComponentNameProps) {
  return (
    <div>
      <button onClick={onClick}>Action</button>
    </div>
  );
}

Run test again. Expected: All tests PASS.

Phase 3: REFACTOR

Improve code while keeping tests green:

  • Extract reusable patterns
  • Improve naming and readability
  • Ensure 80%+ test coverage

Component Scaffolding

For every component, create three files:

ComponentName/
├── ComponentName.tsx           # Implementation
├── ComponentName.test.tsx      # Tests (write first!)
└── ComponentName.stories.tsx   # Storybook story

Coverage Requirements

Target: 80%+ on all metrics

bun run test:coverage

TDD Mindset

  • Test behavior, not implementation - What it does, not how
  • One assertion per test - Clear failure messages
  • Descriptive test names - Documents expected behavior
  • Isolate tests - No shared state between tests
  • Fast feedback - Run tests in watch mode

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です