Agent skill

testing-tdd-london-mock-management

Sub-skill of testing-tdd-london: Mock Management (+2).

Stars 4
Forks 4

Install this agent skill to your Project

npx add-skill https://github.com/vamseeachanta/workspace-hub/tree/main/.claude/skills/_archive/development/testing/testing-tdd-london/mock-management

SKILL.md

Mock Management (+2)

Mock Management

  • Keep mocks simple and focused on single behavior
  • Verify interactions, not implementation details
  • Use jest.fn() for behavior verification
  • Avoid over-mocking internal details
  • Reset mocks between tests

Contract Design

  • Define clear interfaces through mock expectations
  • Focus on object responsibilities and collaborations
  • Use mocks to DRIVE design decisions
  • Keep contracts minimal and cohesive

Common Pitfalls

typescript
// BAD: Over-mocking internal details
const mock = {
  _internalState: {},
  _privateMethod: jest.fn()  // Don't mock private methods
};

// GOOD: Mock only public interface
const mock = {
  publicMethod: jest.fn().mockReturnValue(expectedResult)
};

// BAD: Verifying too many implementation details
expect(mock.method).toHaveBeenCalledTimes(3);  // Fragile

// GOOD: Verify essential behavior
expect(mock.method).toHaveBeenCalledWith(expectedArgs);

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results