A test double substitutes for a production dependency so unit tests can control interactions, avoid external side effects, and verify return values or calls. section 5.4
Use test doubles to:
- Replace slow, unpredictable, or externally connected dependencies. section 5.4
- Verify side effects such as whether a logger received the expected message. section 5.4
- Keep the test focused on the function or component under test. section 5.4
Mocking an external logger with Jest
A date-formatting utility calls logger.log after producing a date string. jest.mock('../utils/logger') replaces the real logger; the test checks both the formatted result and the expected logger call.








