agentleFS
Hey-DigaHey-Diga/dotclaude/skills/test-coverage-improve/SKILL.md

test-coverage-improve

Skill17 starsChanged 9 months agoMITView on GitHub

Analyze and improve test coverage for the codebase targeting 80%+. Use when coverage is low or after adding new untested code.

  • Reads credentials

The file

Show its rules and text

We split this skill into the rules it gives an agent

19 rules. About 0 are common, 10 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use parallel subagents to run tests and improve coverage.

    line 11
  2. Very specific:

    Run npm test -- --coverage to identify gaps in coverage

    line 14
  3. Very specific:

    NEVER mock @prisma/client: - if errors occur, mock the specific repository instead

    line 23
  4. Very specific:

    Place tests in __tests__/unit/ for utility functions and services

    line 38
  5. Very specific:

    Place tests in __tests__/integration/ for components and API handlers

    line 39
  6. Distinctive:

    Test request/response flow with different HTTP methods

    line 59
  7. Distinctive:

    Verify error handling and proper status codes

    line 60
  8. Very specific:

    Use @testing-library/react for user interactions

    line 64
  9. Distinctive:

    Test via user actions and observable output

    line 65
  10. Distinctive:

    Test accessibility and responsive behavior

    line 67
  11. Distinctive:

    Use realistic Spanish business data matching the codebase:

    line 72
  12. Distinctive:

    Test these scenarios comprehensively:

    line 89
  13. Distinctive:

    Assert: Verify expected outcomes and side effects

    line 119
  14. Very specific:

    Use clear describe blocks that explain the component/function context

    line 122
  15. Very specific:

    Write it/test descriptions that read like specifications

    line 123
  16. Very specific:

    Always restore spies and mocks in afterAll or afterEach

    line 127
  17. Very specific:

    Run npm test -- --coverage to verify improvement

    line 147
  18. Distinctive:

    Ensure coverage meets ≥80% threshold

    line 148
  19. Distinctive:

    Start by analyzing current coverage, then systematically address gaps while strictly following the mocking strategy and using realistic …

    line 152

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  • Run npm test -- --coverage to identify gaps in coverage
  • Focus on files in src/lib/utils/, src/lib/services/, app/api/, and src/components/
  • NEVER test repositories in src/lib/repositories/ - these should remain untested
  • Prioritize critical business logic and complex functions

2. Project-Specific Testing Rules

Mocking Strategy (CRUCIAL)

  • NEVER import or use @prisma/client directly in test files
  • NEVER mock @prisma/client - if errors occur, mock the specific repository instead
  • ALWAYS mock repository modules used by code under test:
// 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

  • Place tests in __tests__/unit/ for utility functions and services
  • Place tests in __tests__/integration/ for components and API handlers
  • Tests can also be co-located with source files (*.test.tsx)

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/)

  • Mock repository dependencies (never Prisma directly)
  • Test request/response flow with different HTTP methods
  • Verify error handling and proper status codes
  • Mock authentication/authorization where needed

React Components (src/components/, app/)

  • Use @testing-library/react for user interactions
  • Test via user actions and observable output
  • Mock API calls and external services
  • Test accessibility and responsive behavior

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:

  • null and undefined values
  • Empty objects {} and arrays []
  • Complex nested objects with multiple levels
  • Objects with special characters and emojis
  • Circular references (for inspection utilities)
  • Functions within objects
  • Large data sets (performance considerations)

5. Environment & TypeScript Considerations

Environment Variables

  • AVOID direct assignment to process.env.NODE_ENV (TypeScript read-only)
  • USE expect.any(Boolean) for environment-dependent behavior
// ✅ 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

  • Arrange: Set up test data and mocks
  • Act: Execute the function/behavior being tested
  • Assert: Verify expected outcomes and side effects

Descriptive Naming

  • Use clear describe blocks that explain the component/function context
  • Write it/test descriptions that read like specifications
  • Group related tests logically

Mock Cleanup

  • Always restore spies and mocks in afterAll or afterEach
  • Isolate tests to avoid shared state
  • Clear mocks between tests when needed

7. Implementation Checklist

For each file with coverage gaps:

  • Check if it's a repository (skip if yes)
  • Identify uncovered lines, branches, and functions
  • Mock all external dependencies appropriately
  • Write tests covering happy path and edge cases
  • Use Spanish business context in test data
  • Follow AAA pattern with clear descriptions
  • Test error handling and boundary conditions
  • Verify mock calls with expected parameters
  • Clean up mocks and spies properly

8. Coverage Verification

After implementing tests:

  • Run npm test -- --coverage to verify improvement
  • Ensure coverage meets ≥80% threshold
  • Focus on statement, branch, and function coverage
  • Address any remaining critical gaps

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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.