← ClaudeAtlas

tdd-vitest-typescriptlisted

Test-Driven Development (TDD) using Vitest and TypeScript. Use when the user requests help with TDD, writing tests before code, test-first development, Vitest test setup, TypeScript testing patterns, unit testing, integration testing, or following the Red-Green-Refactor cycle with Vitest.
aiskillstore/marketplace · ★ 329 · Testing & QA · score 79
Install: claude install-skill aiskillstore/marketplace
# TDD with Vitest and TypeScript Guide Claude through Test-Driven Development workflows using Vitest and TypeScript. ## Core TDD Cycle: Red-Green-Refactor Always follow this three-phase cycle: 1. **Red**: Write a failing test that defines desired behavior 2. **Green**: Write minimal code to make the test pass 3. **Refactor**: Improve code quality while keeping tests green ### Workflow Pattern ```typescript // 1. RED: Write the test first describe('Calculator', () => { it('adds two numbers', () => { const calc = new Calculator(); expect(calc.add(2, 3)).toBe(5); }); }); // Run test → Watch it fail (Red) // 2. GREEN: Implement minimal code class Calculator { add(a: number, b: number): number { return a + b; } } // Run test → Watch it pass (Green) // 3. REFACTOR: Improve if needed while keeping tests green ``` ## Vitest Setup and Configuration ### Basic Vitest Config Create `vitest.config.ts`: ```typescript import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { globals: true, environment: 'node', // or 'jsdom' for DOM testing coverage: { provider: 'v8', reporter: ['text', 'json', 'html'], }, }, }); ``` ### TypeScript Configuration Ensure `tsconfig.json` includes: ```json { "compilerOptions": { "types": ["vitest/globals"], "esModuleInterop": true, "skipLibCheck": true } } ``` ## Test File Organization ### Naming Conventions - Test files: `*.test.ts` or `*.spec.ts` -