test-ts
Installation
SKILL.md
TypeScript Test Skill
Generate unit tests by analyzing the source file's functions, branches, and logic flow.
Commands
| Command | Description |
|---|---|
/test-ts create <path> |
Create tests for a file, folder, or module |
/test-ts update <path> |
Update existing tests |
<path> can be:
- A file:
utils.tsor#File - A folder:
src/lib/or#Folder - A module name:
auth,user-service
Tip: Use Kiro's #File or #Folder context to quickly reference paths.
Workflow
Step 1: Analyze Source File
Read the source file and identify:
- All exported functions/classes/hooks
- All code branches (if/else, ternary, switch, try/catch)
- All async operations (Promise, async/await)
- All dependencies that need mocking
- All possible error paths
Step 2: Create Test Plan
For each function/method found:
- List all execution paths
- Identify inputs that trigger each path
- Determine expected outputs for each path
- Note edge cases (null, undefined, empty, boundary)
Step 3: Generate Tests
Create tests that cover every path identified in Step 2.
Coverage Target: 80%+
Every test file must cover:
- All exported functions
- All if/else branches
- All switch cases
- All try/catch blocks
- All async success/error paths
Consistent Pattern
import { describe, it, expect, beforeEach, vi } from 'vitest'
describe('[FileName]', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('[functionName]', () => {
// Test each execution path found in the function
it('should [expected behavior] when [condition]', () => {
// Arrange - setup
// Act - call function
// Assert - verify result
})
})
})
Naming Convention
- Test file:
[source-file].test.tsor[source-file].spec.ts - Describe block: Match source file/class name
- Test case:
should [action] when [condition]
Mocking
Mock all external dependencies:
vi.mock('[dependency-path]', () => ({
[exportName]: vi.fn(),
}))
Running Tests
pnpm test # Run all
pnpm test:coverage # With coverage report
Related skills
More from habonn/portal-skills
daily-commit-summary
|
26commit
Smart git commit workflow using Conventional Commits format with AI-generated commit message suggestions based on staged changes.
22skill-auditor
|
11e2e
Create or update Playwright E2E tests following the project's Page Object Model structure. Use /e2e create for new modules or /e2e update for existing ones.
6sprint-commit-summary
|
6test-go
Generate Go unit tests by analyzing source file flow and ensuring 80%+ coverage.
5