You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
1.0 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSetTimeoutFn = getSetTimeoutFn;
/* eslint-disable import/prefer-default-export */
/* eslint-env jest */
// Used to avoid using Jest's fake timers and Date.now mocks
// See https://github.com/TheBrainFamily/wait-for-expect/issues/4 and
// https://github.com/TheBrainFamily/wait-for-expect/issues/12 for more info
var globalObj = typeof window === "undefined" ? global : window; // Currently this fn only supports jest timers, but it could support other test runners in the future.
function runWithRealTimers(callback) {
var usingJestFakeTimers = // eslint-disable-next-line no-underscore-dangle
globalObj.setTimeout._isMockFunction && typeof jest !== "undefined";
if (usingJestFakeTimers) {
jest.useRealTimers();
}
var callbackReturnValue = callback();
if (usingJestFakeTimers) {
jest.useFakeTimers();
}
return callbackReturnValue;
}
function getSetTimeoutFn() {
return runWithRealTimers(function () {
return globalObj.setTimeout;
});
}