@testing-library/dom
Advanced tools
Comparing version 6.2.0 to 6.3.0
@@ -109,5 +109,22 @@ 'use strict'; | ||
var globalObj = typeof window === 'undefined' ? global : window; // we only run our tests in node, and setImmediate is supported in node. | ||
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 = globalObj.setTimeout._isMockFunction && typeof jest !== 'undefined'; | ||
if (usingJestFakeTimers) { | ||
jest.useRealTimers(); | ||
} | ||
var callbackReturnValue = callback(); | ||
if (usingJestFakeTimers) { | ||
jest.useFakeTimers(); | ||
} | ||
return callbackReturnValue; | ||
} // we only run our tests in node, and setImmediate is supported in node. | ||
// istanbul ignore next | ||
function setImmediatePolyfill(fn) { | ||
@@ -117,6 +134,15 @@ return globalObj.setTimeout(fn, 0); | ||
var clearTimeoutFn = globalObj.clearTimeout; // istanbul ignore next | ||
function getTimeFunctions() { | ||
// istanbul ignore next | ||
return { | ||
clearTimeoutFn: globalObj.clearTimeout, | ||
setImmediateFn: globalObj.setImmediate || setImmediatePolyfill, | ||
setTimeoutFn: globalObj.setTimeout | ||
}; | ||
} | ||
var setImmediateFn = globalObj.setImmediate || setImmediatePolyfill; | ||
var setTimeoutFn = globalObj.setTimeout; | ||
var _runWithRealTimers = runWithRealTimers(getTimeFunctions), | ||
clearTimeoutFn = _runWithRealTimers.clearTimeoutFn, | ||
setImmediateFn = _runWithRealTimers.setImmediateFn, | ||
setTimeoutFn = _runWithRealTimers.setTimeoutFn; | ||
@@ -238,3 +264,5 @@ function newMutationObserver(onMutation) { | ||
var observer = newMutationObserver(onMutation); | ||
observer.observe(container, mutationObserverOptions); | ||
runWithRealTimers(function () { | ||
return observer.observe(container, mutationObserverOptions); | ||
}); | ||
@@ -1026,3 +1054,5 @@ function onDone(error, result) { | ||
// Only observe for mutations only if there is element while checking synchronously | ||
observer.observe(container, mutationObserverOptions); | ||
runWithRealTimers(function () { | ||
return observer.observe(container, mutationObserverOptions); | ||
}); | ||
} | ||
@@ -1079,3 +1109,5 @@ } catch (error) { | ||
}); | ||
observer.observe(container, mutationObserverOptions); | ||
runWithRealTimers(function () { | ||
return observer.observe(container, mutationObserverOptions); | ||
}); | ||
@@ -1697,2 +1729,10 @@ function onDone(error, result) { | ||
function fireEvent(element, event) { | ||
if (!event) { | ||
throw new Error("Unable to fire an event - please provide an event object."); | ||
} | ||
if (!element) { | ||
throw new Error("Unable to fire a \"" + event.type + "\" event - please provide a DOM element."); | ||
} | ||
return element.dispatchEvent(event); | ||
@@ -1709,2 +1749,6 @@ } | ||
createEvent[key] = function (node, init) { | ||
if (!node) { | ||
throw new Error("Unable to fire a \"" + key + "\" event - please provide a DOM element."); | ||
} | ||
var eventInit = _extends({}, defaultInit, {}, init); | ||
@@ -1711,0 +1755,0 @@ |
@@ -103,5 +103,22 @@ import _extends from '@babel/runtime/helpers/esm/extends'; | ||
var globalObj = typeof window === 'undefined' ? global : window; // we only run our tests in node, and setImmediate is supported in node. | ||
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 = globalObj.setTimeout._isMockFunction && typeof jest !== 'undefined'; | ||
if (usingJestFakeTimers) { | ||
jest.useRealTimers(); | ||
} | ||
var callbackReturnValue = callback(); | ||
if (usingJestFakeTimers) { | ||
jest.useFakeTimers(); | ||
} | ||
return callbackReturnValue; | ||
} // we only run our tests in node, and setImmediate is supported in node. | ||
// istanbul ignore next | ||
function setImmediatePolyfill(fn) { | ||
@@ -111,6 +128,15 @@ return globalObj.setTimeout(fn, 0); | ||
var clearTimeoutFn = globalObj.clearTimeout; // istanbul ignore next | ||
function getTimeFunctions() { | ||
// istanbul ignore next | ||
return { | ||
clearTimeoutFn: globalObj.clearTimeout, | ||
setImmediateFn: globalObj.setImmediate || setImmediatePolyfill, | ||
setTimeoutFn: globalObj.setTimeout | ||
}; | ||
} | ||
var setImmediateFn = globalObj.setImmediate || setImmediatePolyfill; | ||
var setTimeoutFn = globalObj.setTimeout; | ||
var _runWithRealTimers = runWithRealTimers(getTimeFunctions), | ||
clearTimeoutFn = _runWithRealTimers.clearTimeoutFn, | ||
setImmediateFn = _runWithRealTimers.setImmediateFn, | ||
setTimeoutFn = _runWithRealTimers.setTimeoutFn; | ||
@@ -232,3 +258,5 @@ function newMutationObserver(onMutation) { | ||
var observer = newMutationObserver(onMutation); | ||
observer.observe(container, mutationObserverOptions); | ||
runWithRealTimers(function () { | ||
return observer.observe(container, mutationObserverOptions); | ||
}); | ||
@@ -1020,3 +1048,5 @@ function onDone(error, result) { | ||
// Only observe for mutations only if there is element while checking synchronously | ||
observer.observe(container, mutationObserverOptions); | ||
runWithRealTimers(function () { | ||
return observer.observe(container, mutationObserverOptions); | ||
}); | ||
} | ||
@@ -1073,3 +1103,5 @@ } catch (error) { | ||
}); | ||
observer.observe(container, mutationObserverOptions); | ||
runWithRealTimers(function () { | ||
return observer.observe(container, mutationObserverOptions); | ||
}); | ||
@@ -1691,2 +1723,10 @@ function onDone(error, result) { | ||
function fireEvent(element, event) { | ||
if (!event) { | ||
throw new Error("Unable to fire an event - please provide an event object."); | ||
} | ||
if (!element) { | ||
throw new Error("Unable to fire a \"" + event.type + "\" event - please provide a DOM element."); | ||
} | ||
return element.dispatchEvent(event); | ||
@@ -1703,2 +1743,6 @@ } | ||
createEvent[key] = function (node, init) { | ||
if (!node) { | ||
throw new Error("Unable to fire a \"" + key + "\" event - please provide a DOM element."); | ||
} | ||
var eventInit = _extends({}, defaultInit, {}, init); | ||
@@ -1705,0 +1749,0 @@ |
@@ -605,2 +605,10 @@ "use strict"; | ||
function fireEvent(element, event) { | ||
if (!event) { | ||
throw new Error(`Unable to fire an event - please provide an event object.`); | ||
} | ||
if (!element) { | ||
throw new Error(`Unable to fire a "${event.type}" event - please provide a DOM element.`); | ||
} | ||
return element.dispatchEvent(event); | ||
@@ -619,2 +627,6 @@ } | ||
createEvent[key] = (node, init) => { | ||
if (!node) { | ||
throw new Error(`Unable to fire a "${key}" event - please provide a DOM element.`); | ||
} | ||
const eventInit = (0, _extends2.default)({}, defaultInit, {}, init); | ||
@@ -621,0 +633,0 @@ const { |
@@ -10,2 +10,3 @@ "use strict"; | ||
exports.newMutationObserver = newMutationObserver; | ||
exports.runWithRealTimers = runWithRealTimers; | ||
exports.setTimeout = exports.setImmediate = exports.clearTimeout = void 0; | ||
@@ -15,5 +16,22 @@ | ||
const globalObj = typeof window === 'undefined' ? global : window; // we only run our tests in node, and setImmediate is supported in node. | ||
const 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) { | ||
const usingJestFakeTimers = globalObj.setTimeout._isMockFunction && typeof jest !== 'undefined'; | ||
if (usingJestFakeTimers) { | ||
jest.useRealTimers(); | ||
} | ||
const callbackReturnValue = callback(); | ||
if (usingJestFakeTimers) { | ||
jest.useFakeTimers(); | ||
} | ||
return callbackReturnValue; | ||
} // we only run our tests in node, and setImmediate is supported in node. | ||
// istanbul ignore next | ||
function setImmediatePolyfill(fn) { | ||
@@ -23,9 +41,19 @@ return globalObj.setTimeout(fn, 0); | ||
const clearTimeoutFn = globalObj.clearTimeout; // istanbul ignore next | ||
function getTimeFunctions() { | ||
// istanbul ignore next | ||
return { | ||
clearTimeoutFn: globalObj.clearTimeout, | ||
setImmediateFn: globalObj.setImmediate || setImmediatePolyfill, | ||
setTimeoutFn: globalObj.setTimeout | ||
}; | ||
} | ||
const { | ||
clearTimeoutFn, | ||
setImmediateFn, | ||
setTimeoutFn | ||
} = runWithRealTimers(getTimeFunctions); | ||
exports.setTimeout = setTimeoutFn; | ||
exports.setImmediate = setImmediateFn; | ||
exports.clearTimeout = clearTimeoutFn; | ||
const setImmediateFn = globalObj.setImmediate || setImmediatePolyfill; | ||
exports.setImmediate = setImmediateFn; | ||
const setTimeoutFn = globalObj.setTimeout; | ||
exports.setTimeout = setTimeoutFn; | ||
@@ -32,0 +60,0 @@ function newMutationObserver(onMutation) { |
@@ -29,3 +29,3 @@ "use strict"; | ||
}); | ||
observer.observe(container, mutationObserverOptions); | ||
(0, _helpers.runWithRealTimers)(() => observer.observe(container, mutationObserverOptions)); | ||
@@ -32,0 +32,0 @@ function onDone(error, result) { |
@@ -51,3 +51,3 @@ "use strict"; | ||
// Only observe for mutations only if there is element while checking synchronously | ||
observer.observe(container, mutationObserverOptions); | ||
(0, _helpers.runWithRealTimers)(() => observer.observe(container, mutationObserverOptions)); | ||
} | ||
@@ -54,0 +54,0 @@ } catch (error) { |
@@ -31,3 +31,3 @@ "use strict"; | ||
const observer = (0, _helpers.newMutationObserver)(onMutation); | ||
observer.observe(container, mutationObserverOptions); | ||
(0, _helpers.runWithRealTimers)(() => observer.observe(container, mutationObserverOptions)); | ||
@@ -34,0 +34,0 @@ function onDone(error, result) { |
{ | ||
"name": "@testing-library/dom", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"description": "Simple and complete DOM testing utilities that encourage good testing practices.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -30,3 +30,3 @@ <div align="center"> | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-69-orange.svg?style=flat-square)](#contributors) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-72-orange.svg?style=flat-square)](#contributors) | ||
[![PRs Welcome][prs-badge]][prs] | ||
@@ -222,3 +222,8 @@ [![Code of Conduct][coc-badge]][coc] | ||
<td align="center"><a href="http://andrewhillcode.com"><img src="https://avatars1.githubusercontent.com/u/12396191?v=4" width="100px;" alt="Andrew Hill"/><br /><sub><b>Andrew Hill</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=andrewhillcode" title="Code">💻</a></td> | ||
<td align="center"><a href="https://amann.me"><img src="https://avatars1.githubusercontent.com/u/4038316?v=4" width="100px;" alt="Jan Amann"/><br /><sub><b>Jan Amann</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=amannn" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=amannn" title="Tests">⚠️</a></td> | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="https://github.com/brapifra"><img src="https://avatars3.githubusercontent.com/u/17855450?v=4" width="100px;" alt="Brais Piñeiro"/><br /><sub><b>Brais Piñeiro</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=brapifra" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=brapifra" title="Tests">⚠️</a></td> | ||
<td align="center"><a href="https://www.dominykas.com/"><img src="https://avatars1.githubusercontent.com/u/505619?v=4" width="100px;" alt="Dominykas Blyžė"/><br /><sub><b>Dominykas Blyžė</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=dominykas" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=dominykas" title="Tests">⚠️</a></td> | ||
</tr> | ||
</table> | ||
@@ -225,0 +230,0 @@ |
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
1622556
14685
281