| name | testing-tdd-london-mock-management |
| description | Sub-skill of testing-tdd-london: Mock Management (+2). |
| version | 1.0.0 |
| category | development |
| type | reference |
| scripts_exempt | true |
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
const mock = {
_internalState: {},
_privateMethod: jest.fn()
};
const mock = {
publicMethod: jest.fn().mockReturnValue(expectedResult)
};
expect(mock.method).toHaveBeenCalledTimes(3);
expect(mock.method).toHaveBeenCalledWith(expectedArgs);