Skip to content
test-gen logo

Test Gen

test-gen

Generates failing tests before implementation using test-driven development (TDD) with Vitest in TypeScript/Next.js projects. Writes unit test stubs covering happy path, edge cases, and error conditions, then confirms they fail. Use when writing tests first, starting TDD, doing red-green-refactor...

blackbearhq/claude-config0installs3stars

SKILL.md

Full skill instructions

Generate tests for a TypeScript/​Next.js project using Vitest following TDD (red-green-refactor).

Workflow: Before implementation (red phase)

  1. Read the requirement or issue description
  2. Find existing test patterns — glob **/​*.test.ts **/​*.spec.ts — and match their style
  3. Write failing tests covering happy path, edge cases, and error conditions
  4. Run npm run test:run -- --testPathPattern=<file> — confirm all new tests fail
  5. Report which tests fail and what behavior they expect

Workflow: After refactoring (verify green)

  1. Run npm run test:run -- --testPathPattern=<file> — confirm existing tests still pass
  2. Add tests for any new code paths introduced during refactoring
  3. Report results

Example test structure

import { describe, it, expect } from 'vitest'
import { calculateDiscount } from '../​utils/​pricing'

describe('calculateDiscount', () => {
  it('should apply percentage discount to subtotal', () => {
    expect(calculateDiscount(100, 0.2)).toBe(80)
  })

  it('should return original price when discount is zero', () => {
    expect(calculateDiscount(100, 0)).toBe(100)
  })

  it('should throw when discount exceeds 100%', () => {
    expect(() => calculateDiscount(100, 1.5)).toThrow()
  })
})

Rules

  • Descriptive names: should [expected behavior] when [condition]
  • Mock external dependencies (APIs, DB), not internal logic
  • One assertion per concept — keep tests focused
  • Always run with --testPathPattern=<file>, never the full suite
  • Model escalation: default Haiku. Escalate to Sonnet for complex domain logic (multi-step auth, transaction rollbacks, distributed state)