MockTracker
The MockTracker
class is used to manage mocking functionality. The test runner module provides a top level mock
export which is a MockTracker
instance. Each test also provides its own MockTracker
instance via the test context's mock
property.
Since
v19.1.0, v18.13.0
Functions
This function is used to create a mock on an existing object method. The following example demonstrates how a mock is created on an existing object method.
This function is used to mock the exports of ECMAScript modules, CommonJS modules, and Node.js builtin modules. Any references to the original module prior to mocking are not impacted.
This function restores the default behavior of all mocks that were previously created by this MockTracker
and disassociates the mocks from the MockTracker
instance. Once disassociated, the mocks can still be used, but the MockTracker
instance can no longer be used to reset their behavior or otherwise interact with them.
This function restores the default behavior of all mocks that were previously created by this MockTracker
. Unlike mock.reset()
, mock.restoreAll()
does not disassociate the mocks from the MockTracker
instance.