Node.js · Middle · Question 55 of 75
How do you mock a function with the built-in test runner?
- 1Mocks are not supported in
node:test - ✓Correct answer:
const fn = mock.fn()fromnode:test, then checkfn.mock.calls - 3
jest.fn()works innode:testwithout imports
Explanation
node:test also has mock.method for object methods, mock.timers for fake timers and module mocking.