Skip to main content
command

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.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --command testing/write-tests
Open on GitHub

What 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-tests for src/auth.ts and create unit tests.
  • Use /write-tests --integration to test src/api/orders.ts.
  • Create a component test for src/components/Checkout.vue with /write-tests --component.

How to install write-tests

1claude-code-templates

npx claude-code-templates@latest --command testing/write-tests

2Manually: put the files in place

.claude/commands/write-tests.md

Call it with /write-tests. For all projects use ~/.claude/commands/

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

Similar slash commands

All slash commands for Testing and QA →

From the same set495

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor