write-tests — Claude Code command: tests and install
Creates unit, integration, end-to-end, and component tests with mocks. Use it when a file needs a test plan and framework-specific checks.
npx claude-code-templates@latest --command testing/write-testsWhat write-tests does
The command takes a target file or test mode through $ARGUMENTS, including --unit, --integration, --e2e, and --component. It inspects code structure, dependency complexity, and edge cases, then builds a test strategy and writes checks for failures, async behavior, and coverage.
It can use Read, Write, Edit, and Bash. Before writing tests, it looks for Jest or Vitest configuration, existing .test.* and .spec.* files, and coverage settings. If no coverage configuration is found, that setup still needs to be handled. Listed framework support includes Jest/Vitest, React Testing Library, Vue Test Utils, Angular TestBed, Cypress, and Playwright integration.
What it helps with
- break down a target file into testable functions
- write unit and integration tests
- mock dependencies and build test doubles
- cover errors, edge cases, and cleanup
- add end-to-end or component tests
Example prompts for the agent
- Run
/write-testsforsrc/auth.tsand create unit tests. - Use
/write-tests --integrationto testsrc/api/orders.ts. - Create a component test for
src/components/Checkout.vuewith/write-tests --component.
How to install write-tests
1claude-code-templates
npx claude-code-templates@latest --command testing/write-tests2Manually: put the files in place
.claude/commands/write-tests.mdCall it with /write-tests. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/write-tests.mdCall it with /prompts:write-tests. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/write-tests.prompt.mdManually: put the files in place
.gemini/commands/write-tests.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about write-tests
How do I install write-tests in Claude Code?
Run npx claude-code-templates@latest --command testing/write-tests, then use .claude/commands/write-tests.md.
What does write-tests do?
It reviews the target code and existing project test patterns, plans the test structure, creates mocks, and writes unit, integration, end-to-end, or component tests. It also checks the coverage setup.
Which testing frameworks does write-tests support?
The listed options are Jest/Vitest, React Testing Library, Vue Test Utils, Angular TestBed, Cypress, and Playwright integration.
Source text
write-tests.md · MIT
--- allowed-tools: Read, Write, Edit, Bash argument-hint: "[target-file] | [test-type] | --unit | --integration | --e2e | --component" description: Write comprehensive unit and integration tests with proper mocking and coverage --- # Write Tests Write comprehensive unit and integration tests with framework-specific best practices: **$ARGUMENTS** ## Current Testing Context - Test framework: !`find . -name "jest.config.*" -o -name "*.test.*" | head -1 && echo "Jest/Vitest detected" || echo "Detect framework"` - Target file: Analysis of $ARGUMENTS for test requirements and complexity - Project patterns: !`find . -name "*.test.*" -o -name "*.spec.*" | head -3` existing test patterns - Coverage setup: !`grep -l "coverage" package.json jest.config.* 2>/dev/null | head -1 || echo "Setup needed"` ## Task Execute comprehensive test writing with framework-specific optimizations and best practices: **Test Focus**: Use $ARGUMENTS to specify target file, unit tests, integration tests, e2e tests, or component tests **Test Writing Framework**: 1. **Code Analysis** - Analyze target code structure, identify testable functions, assess dependency complexity, evaluate edge cases 2. **Test Strategy Design** - Plan test organization, design test hierarchies, identify mock requirements, optimize test isolation 3. **Framework Integration** - Setup framework-specific patterns, configure test utilities, implement proper assertions, optimize test performance 4. **Mock Implementation** - Design dependency mocks, implement test doubles, create factory functions, setup async handling 5. **Test Case Generation** - Write unit tests, integration tests, edge cases, error scenarios, performance tests, snapshot tests 6. **Quality Assurance** - Ensure test maintainability, optimize execution speed, validate coverage, implement proper cleanup **Advanced Features**: Property-based testing, contract testing, visual regression testing, accessibility testing, performance benchmarking. **Framework Support**: Jest/Vitest, React Testing Library, Vue Test Utils, Angular TestBed, Cypress, Playwright integration. **Output**: Comprehensive test suite with unit tests, integration tests, proper mocking, test utilities, and coverage optimization.
© davila7 · MIT · davila7/claude-code-templates