Testing Tdd London Mock Management

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

vamseeachanta Updated

File contents

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

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

vamseeachanta/workspace-hub/tree/main/.agents/skills/_archive/development/testing/testing-tdd-london/mock-management commit 3379d555fb

Frequently asked questions

npx skillmds@latest add vamseeachanta/testing-tdd-london-mock-management