AgentSkillsCN

kitz-table-testing

当创建测试用例、参数化测试,或编写带有@kitz/test的.test.ts文件时使用。触发条件:表格驱动测试、vitest、test.each,或参数化测试模式。

SKILL.md
--- frontmatter
name: kitz-table-testing
description: Use when creating test cases, parameterized tests, or writing .test.ts files with @kitz/test. Triggers on table-driven testing, vitest, test.each, or parameterized test patterns.

Table-Driven Testing

Keywords: vitest, test.each, parameterized, snapshot, table-driven, @kitz/test

Conventions are defined as checks in ~/.claude/checks/kitz.quality.md. Run /review @kitz to evaluate.

Import

typescript
import { Test } from '@kitz/test'

Function Mode

Types are inferred from the function signature:

typescript
// Basic - input/output pairs
Test.on(add)
  .cases(
    [[2, 3], 5],
    [[-1, 1], 0],
    [[0, 0], 0],
  )
  .test()

// Snapshot mode - no expected output
Test.on(parseValue)
  .cases(
    [['42']],
    [['hello']],
  )
  .test()

Describe Mode

For custom types or grouping:

typescript
Test.describe('Transform')
  .inputType<string>()
  .outputType<string>()
  .cases(
    ['hello', 'HELLO'],
    ['world', 'WORLD'],
  )
  .test(({ input, output }) => {
    expect(input.toUpperCase()).toBe(output)
  })

Chained Describes

Use for nested groupings:

typescript
Test.describe('String > uppercase', [
  ['hello', 'HELLO'],
])
  .describe('String > lowercase', [
    ['HELLO', 'hello'],
  ])
  .test(({ input, output }) => {
    // runs for each describe block
  })

Matrix Testing

Cartesian product of inputs:

typescript
Test.on(format)
  .matrix({
    locale: ['en', 'fr', 'de'],
    currency: ['USD', 'EUR'],
    amount: [100, 1000],
  })
  .test()

Output Transformation

Transform expected outputs before comparison:

typescript
Test.on(serialize)
  .cases(
    [{ a: 1 }, '{"a":1}'],
  )
  .onOutput(JSON.parse) // parse expected before comparing
  .test()

Custom Assertions

Override default assertion:

typescript
Test.on(approximateCalc)
  .cases(
    [[1.1], 1],
    [[2.9], 3],
  )
  .test(({ input, output, actual }) => {
    expect(actual).toBeCloseTo(output, 0)
  })