MCPcopy
hub / github.com/jestjs/jest / runAllTimers

Method runAllTimers

packages/jest-fake-timers/src/legacyFakeTimers.ts:205–243  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

203 }
204
205 runAllTimers(): void {
206 this._checkFakeTimers();
207 this.runAllTicks();
208 this.runAllImmediates();
209
210 // Only run a generous number of timers and then bail.
211 // This is just to help avoid recursive loops
212 let i;
213 for (i = 0; i < this._maxLoops; i++) {
214 const nextTimerHandleAndExpiry = this._getNextTimerHandleAndExpiry();
215
216 // If there are no more timer handles, stop!
217 if (nextTimerHandleAndExpiry === null) {
218 break;
219 }
220
221 const [nextTimerHandle, expiry] = nextTimerHandleAndExpiry;
222 this._now = expiry;
223 this._runTimerHandle(nextTimerHandle);
224
225 // Some of the immediate calls could be enqueued
226 // during the previous handling of the timers, we should
227 // run them as well.
228 if (this._immediates.length > 0) {
229 this.runAllImmediates();
230 }
231
232 if (this._ticks.length > 0) {
233 this.runAllTicks();
234 }
235 }
236
237 if (i === this._maxLoops) {
238 throw new Error(
239 `Ran ${this._maxLoops} timers, and there are still more! ` +
240 "Assuming we've hit an infinite recursion and bailing out...",
241 );
242 }
243 }
244
245 runOnlyPendingTimers(): void {
246 // We need to hold the current shape of `this._timers` because existing

Callers

nothing calls this directly

Calls 5

_checkFakeTimersMethod · 0.95
runAllTicksMethod · 0.95
runAllImmediatesMethod · 0.95
_runTimerHandleMethod · 0.95

Tested by

no test coverage detected