Wrap a class with mock definitions
Wrap a function with mock definitions
Construct a type with the properties of T except for those in type K.
Provides a way to add Jasmine-compatible matchers into your Jest context.
Advances all timers by msToRun milliseconds. All pending "macro-tasks" that have been queued via setTimeout() or setInterval(), and would be executed within this timeframe will be executed.
Advances all timers by the needed milliseconds so that only the next timeouts/intervals will run. Optionally, you can provide steps, so it will run steps amount of next timeouts/intervals.
Disables automatic mocking in the module loader.
Enables automatic mocking in the module loader.
Clears the mock.calls and mock.instances properties of all mocks. Equivalent to calling .mockClear() on every mocked function.
Removes any pending timers from the timer system. If any timers have been scheduled, they will be cleared and will never have the opportunity to execute in the future.
Indicates that the module system should never return a mocked version of the specified module, including all of the specificied module's dependencies.
Disables automatic mocking in the module loader.
Mocks a module with an auto-mocked version when it is being required.
Indicates that the module system should never return a mocked version of the specified module from require() (e.g. that it should always return the real module).
Enables automatic mocking in the module loader.
Use the automatic mocking system to generate a mocked version of the given module.
Returns the number of fake timers still left to run.
Returns whether the given function is a mock function.
Creates a sandbox registry for the modules that are loaded inside the callback function.. This is useful to isolate specific modules for every test so that local module state doesn't conflict between tests.
Mocks a module with an auto-mocked version when it is being required.
Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not.
Resets the state of all mocks. Equivalent to calling .mockReset() on every mocked function.
Resets the module registry - the cache of all required modules. This is useful to isolate modules where local state might conflict between tests.
Resets the module registry - the cache of all required modules. This is useful to isolate modules where local state might conflict between tests.
available since Jest 21.1.0 Restores all mocks back to their original value. Equivalent to calling .mockRestore on every mocked function. Beware that jest.restoreAllMocks() only works when mock was created with jest.spyOn; other mocks will require you to manually restore them.
Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with jest-circus!
Exhausts tasks queued by setImmediate().
Exhausts the micro-task queue (usually interfaced in node via process.nextTick).
Exhausts the macro-task queue (i.e., all tasks queued by setTimeout() and setInterval()).
Executes only the macro-tasks that are currently pending (i.e., only the tasks that have been queued by setTimeout() or setInterval() up to this point). If any of the currently pending macro-tasks schedule new macro-tasks, those new tasks will not be executed by this call.
(renamed to advanceTimersByTime
in Jest 21.3.0+) Executes only the macro
task queue (i.e. all tasks queued by setTimeout() or setInterval() and setImmediate()).
Explicitly supplies the mock object that the module system should return for the specified module.
Set the default timeout interval for tests and before/after hooks in milliseconds. Note: The default timeout interval is 5 seconds if this method is not called.
Creates a mock function similar to jest.fn but also tracks calls to object[methodName]
Note: By default, jest.spyOn also calls the spied method. This is different behavior from most other test libraries.
Indicates that the module system should never return a mocked version of the specified module from require() (e.g. that it should always return the real module).
Instructs Jest to use fake versions of the standard timer functions.
Instructs Jest to use the real versions of the standard timer functions.
Wrap an object or a module with mock definitions
jest.mock("../api"); import * as api from "../api";
const mockApi = api as jest.Mocked;
api.MyApi.prototype.myApiMethod.mockImplementation(() => "test");