UNPKG

wait-for-expect

Version:

Wait for expectation to be true, useful for integration and end to end testing

34 lines (32 loc) 1.08 kB
"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 = typeof jest !== "undefined" && // @ts-ignore setTimeout.clock != null && // @ts-ignore typeof setTimeout.clock.Date === "function"; if (usingJestFakeTimers) { jest.useRealTimers(); } var callbackReturnValue = callback(); if (usingJestFakeTimers) { jest.useFakeTimers(); } return callbackReturnValue; } function getSetTimeoutFn() { return runWithRealTimers(function () { return globalObj.setTimeout; }); }