@testing-library/dom
Advanced tools
Comparing version 7.29.5 to 7.29.6
@@ -10,3 +10,4 @@ "use strict"; | ||
exports.checkContainerType = checkContainerType; | ||
exports.TEXT_NODE = exports.jestFakeTimersAreEnabled = exports.setTimeout = exports.setImmediate = exports.clearTimeout = void 0; | ||
exports.jestFakeTimersAreEnabled = jestFakeTimersAreEnabled; | ||
exports.TEXT_NODE = exports.setTimeout = exports.setImmediate = exports.clearTimeout = void 0; | ||
const globalObj = typeof window === 'undefined' ? global : window; // Constant node.nodeType for text nodes, see: | ||
@@ -20,6 +21,12 @@ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType#Node_type_constants | ||
function runWithRealTimers(callback) { | ||
return _runWithRealTimers(callback).callbackReturnValue; | ||
// istanbul ignore else | ||
if (typeof jest !== 'undefined') { | ||
return runWithJestRealTimers(callback).callbackReturnValue; | ||
} // istanbul ignore next | ||
return callback(); | ||
} | ||
function _runWithRealTimers(callback) { | ||
function runWithJestRealTimers(callback) { | ||
const timerAPI = { | ||
@@ -32,12 +39,8 @@ clearImmediate, | ||
setTimeout | ||
}; // istanbul ignore else | ||
if (typeof jest !== 'undefined') { | ||
jest.useRealTimers(); | ||
} | ||
}; | ||
jest.useRealTimers(); | ||
const callbackReturnValue = callback(); | ||
const usedJestFakeTimers = Object.entries(timerAPI).some(([name, func]) => func !== globalObj[name]); | ||
const usedFakeTimers = Object.entries(timerAPI).some(([name, func]) => func !== globalObj[name]); | ||
if (usedJestFakeTimers) { | ||
if (usedFakeTimers) { | ||
var _timerAPI$setTimeout; | ||
@@ -50,12 +53,18 @@ | ||
callbackReturnValue, | ||
usedJestFakeTimers | ||
usedFakeTimers | ||
}; | ||
} | ||
const jestFakeTimersAreEnabled = () => Boolean(_runWithRealTimers(() => {}).usedJestFakeTimers); // we only run our tests in node, and setImmediate is supported in node. | ||
function jestFakeTimersAreEnabled() { | ||
// istanbul ignore else | ||
if (typeof jest !== 'undefined') { | ||
return runWithJestRealTimers(() => {}).usedFakeTimers; | ||
} // istanbul ignore next | ||
return false; | ||
} // we only run our tests in node, and setImmediate is supported in node. | ||
// istanbul ignore next | ||
exports.jestFakeTimersAreEnabled = jestFakeTimersAreEnabled; | ||
function setImmediatePolyfill(fn) { | ||
@@ -62,0 +71,0 @@ return globalObj.setTimeout(fn, 0); |
@@ -45,5 +45,5 @@ "use strict"; | ||
const overallTimeoutTimer = (0, _helpers.setTimeout)(handleTimeout, timeout); | ||
const usingFakeTimers = (0, _helpers.jestFakeTimersAreEnabled)(); | ||
const usingJestFakeTimers = (0, _helpers.jestFakeTimersAreEnabled)(); | ||
if (usingFakeTimers) { | ||
if (usingJestFakeTimers) { | ||
checkCallback(); // this is a dangerous rule to disable because it could lead to an | ||
@@ -102,3 +102,3 @@ // infinite loop. However, eslint isn't smart enough to know that we're | ||
if (!usingFakeTimers) { | ||
if (!usingJestFakeTimers) { | ||
clearInterval(intervalId); | ||
@@ -105,0 +105,0 @@ observer.disconnect(); |
{ | ||
"name": "@testing-library/dom", | ||
"version": "7.29.5", | ||
"version": "7.29.6", | ||
"description": "Simple and complete DOM testing utilities that encourage good testing practices.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2973122
24859