write-tests

A command that generates a focused test suite for a source file using the project's existing test runner and conventions. A test runner is the tool that executes automated tests.

In plain words
What is it for?
Use it when a source file needs production-quality tests. It can account for runners such as Vitest, Jest, node:test, Mocha, Ava, and Playwright, plus common web-testing helpers.
Why use it?
It avoids guessing the project's tooling and helps new tests fit its dependencies, configuration, helpers, and style. It asks before adding a test dependency when none is installed.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/khaledsaeed18/dotclaude/write-tests
Clone the repo
git clone --depth 1 https://github.com/KhaledSaeed18/dotclaude

Made for: Claude Code.

Per session 41 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 974 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00041 $0.00974
Opus 5 $0.00020 $0.00487
Sonnet 5 $0.00008 $0.00195
Haiku 4.5 $0.00004 $0.00097

Measured 2d ago against content hash 2ebb3a76227b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

write-tests scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude-plugin/plugins/testing/commands/write-tests.md · 60 lines

How it starts

The opening of the file, as written. The whole thing — 60 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Context

  • Target file: $1
  • Runner override (optional): $2
  • Project manifest (detect runner, scripts, and deps from here):

!cat package.json

Task

Write a thorough, idiomatic test suite for $1. If no file path was given in the arguments above, ask for one and stop.

Follow this procedure:

1. Detect the toolchain — don't assume

From the manifest above (and config files if needed), determine the runner and libraries already in use. Respect $2 if the user named a runner; otherwise infer:

  • Runner: vitest, jest, node:test, mocha, ava, or @playwright/test. Check devDependencies and the test script.
  • Helpers in play: @testing-library/react + @testing-library/jest-dom (React), supertest (Express/HTTP), @nestjs/testing (NestJS), msw (network mocking).
  • Config: vitest.config.*, jest.config.*, tsconfig paths/aliases, setupTests files.

If the project has no test runner installed, do not invent one silently: state what you'd add (default to Vitest for Vite/Next/library code, Jest where it's already the ecosystem norm) and ask before adding a dependency.

2. Mirror existing conventions

Find sibling tests with Glob/Grep (**/*.{test,spec}.{ts,tsx,js,jsx}) and read one or two. Match their file location (__tests__/ vs co-located *.test.ts), import style, naming, and setup/teardown patterns. New tests should look like they were written by whoever wrote the existing ones.

3. Understand the unit under test

Read $1 in full. Identify every exported function/component/class, its inputs, outputs, side effects, dependencies to mock (network, DB, clock, randomness, filesystem), and the branches that need coverage.

4. Write meaningful tests

  • Cover behavior, not implementation. Assert observable outputs and effects; don't pin internal calls unless the contract is the call itself.
  • Per unit, cover: the happy path, boundary/edge cases (empty, zero, negative, large, unicode), and error/failure paths (throws, rejections, invalid input).
  • Structure each test Arrange–Act–Assert with a description that reads as a behavior (it("returns 401 when the token is missing")).
  • Determinism is non-negotiable: fake timers for time, seed or stub randomness, no real network/DB/filesystem — mock at the boundary (msw, supertest, in-memory fakes). No sleep, no ordering assumptions, no shared mutable state between tests.
  • Stack specifics:
    • React (Testing Library): query by role/label/text, never by test-id unless unavoidable; assert what the user sees; use userEvent for interaction; wrap async UI in findBy/waitFor. Don't test internal state.
    • Express: drive HTTP with supertest against the app instance; assert status, body, and headers; cover auth and validation failures.
    • NestJS: build a Test.createTestingModule, provide mocked providers, and test services in isolation; for controllers, mock the service layer.
  • Keep each test independent and runnable in any order.

Read the full file on GitHub · 60 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 60 lines · 41 tokens per session scan A 2ebb3a76227b

Subscribe to this mod's changes

write-tests is a command published in the GitHub repository KhaledSaeed18/dotclaude (4 stars, last pushed 7d ago), licensed MIT. It adds 41 tokens to every session and 974 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.