How to install
Full guide →Copy, then save as a .md file in .claude/commands/ (project) or ~/.claude/commands/ (global). Invoke with /<name>.
Target: .claude/commands/<name>.md
Content
1---
2name: Write TypeScript Tests
3description: Generate comprehensive unit tests for a TypeScript file
4---
5
6Analyze the file at $ARGUMENTS and write thorough unit tests for it.
7
8## Instructions
9
101. Identify every exported function, class, and type
112. For each unit, write test cases covering:
12 - Happy path with typical inputs
13 - Edge cases (empty strings, zero, null/undefined where applicable)
14 - Error conditions and thrown exceptions
153. Use `describe` blocks to group tests by function name
164. Use `it` / `test` with descriptive names that read as sentences
175. Mock external dependencies (network, filesystem, DB) with `vi.mock` or `jest.mock`
186. Aim for >90% branch coverage
19
20## Output format
21
22Create a file alongside the source named `<filename>.test.ts`.
23Use `vitest` if a `vitest.config` exists, otherwise `jest`.
24
25## Example
26
27```typescript
28import { describe, it, expect, vi } from "vitest"
29import { slugify, formatCount } from "./utils"
30
31describe("slugify", () => {
32 it("converts spaces to hyphens", () => {
33 expect(slugify("Hello World")).toBe("hello-world")
34 })
35 it("strips special characters", () => {
36 expect(slugify("Héllo! World?")).toBe("hllo-world")
37 })
38 it("truncates to 80 chars", () => {
39 expect(slugify("a".repeat(100))).toHaveLength(80)
40 })
41})
42
43describe("formatCount", () => {
44 it("returns raw number below 1000", () => {
45 expect(formatCount(999)).toBe("999")
46 })
47 it("formats thousands with k suffix", () => {
48 expect(formatCount(1500)).toBe("1.5k")
49 })
50})
51```
52