namespace
test.jest
namespace jest
- type Mock<T extends (...args: any[]) => any = (...args: any[]) => any> = JestMock.Mock<T>
Constructs the type of a mock function, such as the return type of
jest.fn(). - type Replaced<T> = JestMock.Replaced<T>
Constructs the type of a replaced property.
- type Spied<T extends JestMock.ClassLike | (...args: any[]) => any> = JestMock.Spied<T>
Constructs the type of a spied class or function.
- type SpiedClass<T extends JestMock.ClassLike> = JestMock.SpiedClass<T>
Constructs the type of a spied class.
- type SpiedFunction<T extends (...args: any[]) => any> = JestMock.SpiedFunction<T>
Constructs the type of a spied function.
- type SpiedGetter<T> = JestMock.SpiedGetter<T>
Constructs the type of a spied getter.
- type SpiedSetter<T> = JestMock.SpiedSetter<T>
Constructs the type of a spied setter.
- milliseconds: number
Advance the fake clock and run the timers that come due.
- milliseconds: number): Promise<void>;
Like advanceTimersByTime, but runs promise jobs and one turn of the real event loop between timers, so it picks up timers that a callback schedules after an
await. Advance the fake clock to the next multiple of 16 milliseconds. That's when a faked
requestAnimationFrameruns its callbacks.- steps?: number
Advance the fake clock to the next timer and run every timer due at that time. Repeats
stepstimes. - steps?: number): Promise<void>;
Like advanceTimersToNextTimer, but runs promise jobs and one turn of the real event loop between timers.
- id: string
require()the real moduleidand return a copy where every function is a mock. - id: string,
Like mock, but the call isn't hoisted.
Returns the real time in milliseconds since the epoch, no matter what's faked.
- fn: unknown
Returns
trueiffnis a mock function or a spy. - id: string,
Replace the module
idwith the return value offactory. The call is hoisted above the file's imports.Without a factory, the module is replaced with the file of the same name in a
__mocks__directory. If there isn't one, it's replaced with a copy of the module where every function is a mock. - id: string): T;
require()the mocked version of the moduleid, even if it isn't mocked. Re-evaluate each module on its next
import()orrequire(). Mocked modules stay mocked, and their factories run again.Run the callbacks queued with a faked
setImmediate.Run the callbacks queued with a faked
process.nextTickorqueueMicrotask.Run timers until none are left. Throws after
timerLimittimers.Like runAllTimers, but runs promise jobs and one turn of the real event loop between timers.
Advance the fake clock to the last timer that's currently pending.
Like runOnlyPendingTimers, but runs promise jobs and one turn of the real event loop between timers.
- config: { mode: 'manual' | 'nextAsync' } | { delta: number; mode: 'interval' }
Choose how the fake clock moves when the test doesn't move it.
manual: it doesn't move. This is the default.nextAsync: each turn of the real event loop runs the next timer.interval: it advances bydeltamilliseconds (default 20) everydeltareal milliseconds.
Replace the timer functions on
globalThiswith fakes that use a fake clock. The clock only moves when the test moves it. A reference saved before this call, such asconst savedSetTimeout = setTimeout, stays real.The real timers are restored when the test file ends, unless a preload made this call at its top level.
Restore the real timer functions and clocks, and discard pending fake timers.