Test coverage improve

From Hey-Diga/dotclaude · View interactive version

Test coverage improve is an AI agent skill from the GitHub repository Hey-Diga/dotclaude. Analyze and improve test coverage for the codebase targeting 80%+. Use when coverage is low or after adding new untested code.

How to use this skill

Skill file

Test Coverage Enhancement Task

Please analyze and improve the test coverage for this codebase following the established testing strategy. Run npm test -- --coverage to get current coverage and target ≥80% coverage.

Use parallel subagents to run tests and improve coverage.

1. Coverage Analysis & Strategy

2. Project-Specific Testing Rules

Mocking Strategy (CRUCIAL)

// At top of test file:
jest.mock("@/lib/repositories/userRepository", () => ({
  getById: jest.fn(),
  updateName: jest.fn(),
}));
const mockUserRepository = require("@/lib/repositories/userRepository");

// In test:
mockUserRepository.getById.mockResolvedValue({ id: '1', name: 'Ana García' });

File Structure & Placement

3. Testing Patterns by File Type

Utility Functions (`src/lib/utils/`, `src/lib/services/`)

// Mock external libraries at module level
jest.mock("langfuse", () => ({
  Langfuse: jest.fn(),
  TextPromptClient: jest.fn(),
}));

// Mock console methods and restore in cleanup
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
afterAll(() => consoleLogSpy.mockRestore());

API Route Handlers (`app/api/`)

React Components (`src/components/`, `app/`)

4. Test Data & Edge Cases

Spanish Business Context

Use realistic Spanish business data matching the codebase:

const testData = {
  customers: [
    { name: "Ana García", phone: "+34611223344" },
    { name: "José María Fernández-Vázquez", phone: "+34612345678" },
  ],
  businesses: [
    { name: "Salon Bella", address: "Calle Mayor 1, Madrid" },
    { name: "Peluquería Ñoña & Coiffeur", services: ["corte", "peinado"] },
  ],
  specialChars: "¡Hola! ¿Cómo está usted?",
  emojis: "💇‍♀️✂️🎨",
};

Mandatory Edge Cases for All Functions

Test these scenarios comprehensively:

5. Environment & TypeScript Considerations

Environment Variables

// ✅ DO: Test actual behavior
expect(mockUtil.inspect).toHaveBeenCalledWith(testObj, {
  depth: null,
  colors: process.env.NODE_ENV === "development",
});

// ❌ DON'T: Mock NODE_ENV directly
// process.env.NODE_ENV = "development"; // TypeScript error

6. Test Quality Standards

Arrange-Act-Assert Structure

Descriptive Naming

Mock Cleanup

7. Implementation Checklist

For each file with coverage gaps:

8. Coverage Verification

After implementing tests:

Start by analyzing current coverage, then systematically address gaps while strictly following the mocking strategy and using realistic Spanish business data.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.