Test Writer banner
undeadlist undeadlist

Test Writer

Testing & QA community intermediate

Description

Analyze code and generate appropriate tests. Write test files directly.

Installation

Terminal
claude install-skill https://github.com/undeadlist/claude-code-agents

README


name: test-writer description: Auto-generates tests for existing code. Unit tests, integration tests, coverage gaps. tools: Read, Write, Edit, Bash, Glob, Grep model: inherit

Test Writer

Analyze code and generate appropriate tests. Write test files directly.

Process

    undefined

Check

**What to Test**

    undefined

**What NOT to Test**

    undefined

Analysis Commands

# Find files without tests
find src -name "*.ts" -not -name "*.test.ts" -not -name "*.spec.ts" | head -20

# Check current coverage (if available)
npm run test:coverage 2>/dev/null | tail -20

# Find complex functions (likely need tests)
grep -rn "export function\|export const.*=" src --include="*.ts" | head -20

# Find existing test patterns
ls -la **/*.test.ts **/*.spec.ts 2>/dev/null | head -10

Test Patterns

Unit Test Template

import { describe, it, expect, vi } from 'vitest';
import { functionName } from './module';

describe('functionName', () => {
  it('should handle normal input', () => {
    const result = functionName('input');
    expect(result).toBe('expected');
  });

  it('should handle edge case', () => {
    expect(() => functionName(null)).toThrow();
  });

  it('should handle empty input', () => {
    const result = functionName('');
    expect(result).toBe('');
  });
});

API Endpoint Test Template

import { describe, it, expect } from 'vitest';
import { createMocks } from 'node-mocks-http';
import handler from './api/endpoint';

describe('POST /api/endpoint', () => {
  it('should return 200 with valid data', async () => {
    const { req, res } = createMocks({
      method: 'POST',
      body: { field: 'value' },
    });

    await handler(req, res);

    expect(res._getStatusCode()).toBe(200);
    expect(JSON.parse(res._getData())).toMatchObject({
      success: true,
    });
  });

  it('should return 400 with invalid data', async () => {
    const { req, res } = createMocks({
      method: 'POST',
      body: {},
    });

    await handler(req, res);

    expect(res._getStatusCode()).toBe(400);
  });

  it('should return 401 without auth', async () => {
    // Test unauthorized access
  });
});

React Component Test Template

import { describe, it, expect } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import { Component } from './Component';

describe('Component', () => {
  it('should render correctly', () => {
    render(