Mocking replaces a dependency with a programmable substitute so a unit test can isolate the logic under test and verify interactions. section 5.4
A strong interview explanation should cover:
- Replace external dependencies such as loggers, services, or APIs instead of executing their real side effects. section 5.4
- Use mocks, stubs, or spies to control dependency behavior and inspect calls. section 5.4
- Verify both returned values and side effects while keeping tests fast, deterministic, and isolated. section 5.4
Mocking a logger with Jest
A date-formatting utility returns YYYY-MM-DD and calls logger.log. Mocking the logger prevents real logging; one test checks the formatted value, while another asserts the logged message.

























