AgentSkillsCN

tdd

TDD(测试驱动开发)的规则与模式。当您:(1) 编写单元测试;(2) 确定测试目标;(3) 遵循TDD开发周期时,可使用此技能。支持Expo、React Native、React Router、NestJS等项目,并搭配Vitest或Jest进行测试。

SKILL.md
--- frontmatter
name: tdd
description: "TDD (Test-Driven Development) rules and patterns. Use when: (1) Writing unit tests, (2) Determining test targets, (3) Following TDD cycle. Supports Expo, React Native, React Router, NestJS using Vitest/Jest."

TDD Skill

TDD rules and patterns for Node/TypeScript/React projects.


Test Target Rules

Must Test

PatternDescription
*.service.tsService functions
*.helper.ts, *.util.tsHelper/utility functions
*.tsx (components)React components
loader, actionRoute loaders/actions
*.schema.tsZod schemas
use*.tsCustom hooks

Exclude from Testing

PatternReason
*.d.tsType declarations only
**/types.ts, **/types/**Type definitions only
**/*.port.tsInterface definitions only
**/index.tsBarrel files (re-exports)
*.config.tsConfiguration files
**/constants.ts, **/const.tsStatic values only
**/components/ui/**shadcn/ui auto-generated
**/*.css, **/*.scssStyle files

Naming Convention

Source → Test path mapping:

Source PathTest Path
app/services/auth.service.ts__tests__/services/auth.service.test.ts
app/components/Button.tsx__tests__/components/Button.test.tsx
app/domain/user/user.schema.ts__tests__/domain/user/user.schema.test.ts

Pattern: Replace root folder with __tests__/ and add .test before extension.


TDD Cycle

Red → Green → Refactor

  1. Red - Write a failing test
  2. Green - Write minimal code to pass
  3. Refactor - Improve code (keep tests passing)

AAA Pattern

All tests follow AAA (Arrange-Act-Assert) pattern:

PhaseRoleExample
ArrangePrepare test data and environmentMocking, input creation
ActExecute test targetFunction call, event trigger
AssertVerify resultsexpect statements

Framework Test Environment

FrameworkTest RunnerNote
ExpoJestVitest NOT supported
React NativeJestVitest NOT supported
React Router v7Vitest/JestVitest recommended
NestJSJestOfficial default

Test Utility Structure

PathPurpose
__tests__/fixtures/Mock data builders
__tests__/utils/Test helper functions

Rules:

  1. No inline helpers in test files - use shared locations
  2. Check existing utilities before creating new ones
  3. Support overrides parameter for customization

Code Examples

Based on detected framework, read the corresponding reference file (paths relative to .claude/skills/tdd/):

Note: Reference examples use English test descriptions for universal accessibility. When writing actual tests, follow the Output Language Rules below.


Output Language Rules

ItemLanguage
Test descriptions (it, describe)Korean
Variable/function namesEnglish
Code commentsKorean

Quality Checklist

Before completing tests:

  • Test file follows naming convention
  • All tests have Korean descriptions
  • AAA pattern followed
  • Mocks initialized in beforeEach
  • No any type in test code
  • Shared helpers in __tests__/fixtures/ or __tests__/utils/
  • All tests pass