Writes unit tests for a component, hook, or utility. Loads repo test patterns and writes tests covering happy path, edge cases, and error states in the project's established style. Use when adding test coverage for a component, hook, or utility function.
Arguments: $ARGUMENTS — path to the file or component to test
Call test-context with the given path argument. It writes its output to a timestamped file and echoes the full path — read that file to get structured test conventions for this repo.
Read the file(s) to be tested. Understand:
# Look for existing test file
find . -name "$(basename $TARGET .ts).test.ts" -o -name "$(basename $TARGET .tsx).test.tsx" 2>/dev/null
If tests exist: read them. Determine what's missing, not what to replace.
Before writing, list what will be tested:
Test plan for {file}:
Happy path:
- [ ] {scenario}
- [ ] {scenario}
Edge cases:
- [ ] {scenario}
- [ ] {scenario}
Error states:
- [ ] {scenario}
NOT testing (implementation details / framework behavior):
- {list}
Get confirmation from user if test plan is non-obvious, then proceed.
Using the test context from Step 1:
Rules:
waitFor usage)# Run just the new test file
pnpm test {test-file-path} --run 2>&1 | tail -30
If tests fail: diagnose and fix before reporting success.
✅ Unit tests written for {file}
Coverage added:
- {scenario tested}
- {scenario tested}
Test file: {path}
REPO=$(git remote get-url origin 2>/dev/null | sed 's/.*\///' | sed 's/\.git//')
BRANCH=$(git branch --show-current 2>/dev/null | sed 's/\//-/g')
TS=$(date +%Y%m%d-%H%M%S)-$$
mkdir -p ~/.claude/skill-output/$REPO/$BRANCH
Write this report to ~/.claude/skill-output/$REPO/$BRANCH/write-unit-tests-report-$TS.md.