Add to Claude Code
343 addsInstall this Claude Code skill.
Name: Write TypeScript Tests
Save to: ~/.claude/skills/write-typescript-tests.md
---
---
name: Write TypeScript Tests
description: Generate comprehensive unit tests for a TypeScript file
---
Analyze the file at $ARGUMENTS and write thorough unit tests for it.
## Instructions
1. Identify every exported function, class, and type
2. For each unit, write test cases covering:
- Happy path with typical inputs
- Edge cases (empty strings, zero, null/undefined where applicable)
- Error conditions and thrown exceptions
3. Use `describe` blocks to group tests by function name
4. Use `it` / `test` with descriptive names that read as sentences
5. Mock external dependencies (network, filesystem, DB) with `vi.mock` or `jest.mock`
6. Aim for >90% branch coverage
## Output format
Create a file alongside the source named `<filename>.test.ts`.
Use `vitest` if a `vitest.config` exists, otherwise `jest`.
## Example
```typescript
import { describe, it, expect, vi } from "vitest"
import { slugify, formatCount } from "./utils"
describe("slugify", () => {
it("converts spaces to hyphens", () => {
expect(slugify("Hello World")).toBe("hello-world")
})
it("strips special characters", () => {
expect(slugify("Héllo! World?")).toBe("hllo-world")
})
it("truncates to 80 chars", () => {
expect(slugify("a".repeat(100))).toHaveLength(80)
})
})
describe("formatCount", () => {
it("returns raw number below 1000", () => {
expect(formatCount(999)).toBe("999")
})
it("formats thousands with k suffix", () => {
expect(formatCount(1500)).toBe("1.5k")
})
})
```
Paste into Claude Code to add this skill.
How to add
Full guide →Click Add, then paste into Claude Code. Claude will save it to the right location for you.
Target: .claude/commands/<name>.md