Socket
Socket
Sign inDemoInstall

@testing-library/dom

Package Overview
Dependencies
Maintainers
10
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testing-library/dom - npm Package Compare versions

Comparing version 5.5.2 to 5.5.3

dist/__tests__/fake-timers.js

26

dist/__tests__/wait-for-dom-change.js

@@ -53,27 +53,1 @@ import {waitForDomChange} from '../wait-for-dom-change'

})
test('can time out', async () => {
jest.useFakeTimers()
const promise = waitForDomChange()
jest.advanceTimersByTime(4600)
await expect(promise).rejects.toThrow(/timed out/i)
jest.useRealTimers()
})
test('can specify our own timeout time', async () => {
jest.useFakeTimers()
const promise = waitForDomChange({timeout: 4700})
const handler = jest.fn()
promise.then(handler, handler)
// advance beyond the default
jest.advanceTimersByTime(4600)
// promise was neither rejected nor resolved
expect(handler).toHaveBeenCalledTimes(0)
// advance beyond our specified timeout
jest.advanceTimersByTime(150)
// timed out
await expect(promise).rejects.toThrow(/timed out/i)
jest.useRealTimers()
})

@@ -36,1 +36,25 @@ import {waitForElementToBeRemoved} from '../'

})
test('requires a function as the first parameter', () => {
return expect(
waitForElementToBeRemoved(),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"waitForElementToBeRemoved requires a function as the first parameter"`,
)
})
test('requires an element to exist first', () => {
return expect(
waitForElementToBeRemoved(() => null),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal."`,
)
})
test('requires an unempty array of elements to exist first', () => {
return expect(
waitForElementToBeRemoved(() => []),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal."`,
)
})

@@ -22,28 +22,2 @@ import {waitForElement} from '../wait-for-element'

test('can time out', async () => {
jest.useFakeTimers()
const promise = waitForElement(() => {})
jest.advanceTimersByTime(4600)
await expect(promise).rejects.toThrow(/timed out/i)
jest.useRealTimers()
})
test('can specify our own timeout time', async () => {
jest.useFakeTimers()
const promise = waitForElement(() => {}, {timeout: 4700})
const handler = jest.fn()
promise.then(handler, handler)
// advance beyond the default
jest.advanceTimersByTime(4600)
// promise was neither rejected nor resolved
expect(handler).toHaveBeenCalledTimes(0)
// advance beyond our specified timeout
jest.advanceTimersByTime(150)
// timed out
await expect(promise).rejects.toThrow(/timed out/i)
jest.useRealTimers()
})
test('throws last thrown error', async () => {

@@ -50,0 +24,0 @@ const {rerender, container} = render('<div />')

33

dist/@testing-library/dom.cjs.js

@@ -126,2 +126,15 @@ 'use strict';

var globalObj = typeof window === 'undefined' ? global : window; // we only run our tests in node, and setImmediate is supported in node.
// istanbul ignore next
function setImmediatePolyfill(fn) {
return globalObj.setTimeout(fn, 0);
} // istanbul ignore next
var setTimeout = globalObj.setTimeout,
clearTimeout = globalObj.clearTimeout,
_globalObj$setImmedia = globalObj.setImmediate,
setImmediate = _globalObj$setImmedia === void 0 ? setImmediatePolyfill : _globalObj$setImmedia;
function newMutationObserver(onMutation) {

@@ -140,20 +153,3 @@ var MutationObserverConstructor = typeof window !== 'undefined' && typeof window.MutationObserver !== 'undefined' ? window.MutationObserver : MutationObserver;

}
/*
* There are browsers for which `setImmediate` is not available. This
* serves as a polyfill of sorts, adopting `setTimeout` as the closest
* equivalent
*/
function getSetImmediate() {
/* istanbul ignore else */
if (typeof setImmediate === 'function') {
return setImmediate;
} else {
return function (fn) {
return setTimeout(fn, 0);
};
}
}
// It would be cleaner for this to live inside './queries', but

@@ -215,3 +211,2 @@ // other parts of the code assume that all exports from

function onDone(error, result) {
var setImmediate = getSetImmediate();
clearTimeout(timer);

@@ -1015,3 +1010,2 @@ setImmediate(function () {

function onDone(error, result) {
var setImmediate = getSetImmediate();
clearTimeout(timer);

@@ -1056,3 +1050,2 @@ setImmediate(function () {

return new Promise(function (resolve, reject) {
var setImmediate = getSetImmediate();
var timer = setTimeout(function () {

@@ -1059,0 +1052,0 @@ onDone(new Error('Timed out in waitForDomChange.'), null);

@@ -120,2 +120,15 @@ 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.
// istanbul ignore next
function setImmediatePolyfill(fn) {
return globalObj.setTimeout(fn, 0);
} // istanbul ignore next
var setTimeout = globalObj.setTimeout,
clearTimeout = globalObj.clearTimeout,
_globalObj$setImmedia = globalObj.setImmediate,
setImmediate = _globalObj$setImmedia === void 0 ? setImmediatePolyfill : _globalObj$setImmedia;
function newMutationObserver(onMutation) {

@@ -134,20 +147,3 @@ var MutationObserverConstructor = typeof window !== 'undefined' && typeof window.MutationObserver !== 'undefined' ? window.MutationObserver : MutationObserver;

}
/*
* There are browsers for which `setImmediate` is not available. This
* serves as a polyfill of sorts, adopting `setTimeout` as the closest
* equivalent
*/
function getSetImmediate() {
/* istanbul ignore else */
if (typeof setImmediate === 'function') {
return setImmediate;
} else {
return function (fn) {
return setTimeout(fn, 0);
};
}
}
// It would be cleaner for this to live inside './queries', but

@@ -209,3 +205,2 @@ // other parts of the code assume that all exports from

function onDone(error, result) {
var setImmediate = getSetImmediate();
clearTimeout(timer);

@@ -1009,3 +1004,2 @@ setImmediate(function () {

function onDone(error, result) {
var setImmediate = getSetImmediate();
clearTimeout(timer);

@@ -1050,3 +1044,2 @@ setImmediate(function () {

return new Promise(function (resolve, reject) {
var setImmediate = getSetImmediate();
var timer = setTimeout(function () {

@@ -1053,0 +1046,0 @@ onDone(new Error('Timed out in waitForDomChange.'), null);

@@ -10,6 +10,23 @@ "use strict";

exports.newMutationObserver = newMutationObserver;
exports.getSetImmediate = getSetImmediate;
exports.clearTimeout = exports.setTimeout = exports.setImmediate = void 0;
var _mutationobserverShim = _interopRequireDefault(require("@sheerun/mutationobserver-shim"));
const globalObj = typeof window === 'undefined' ? global : window; // we only run our tests in node, and setImmediate is supported in node.
// istanbul ignore next
function setImmediatePolyfill(fn) {
return globalObj.setTimeout(fn, 0);
} // istanbul ignore next
const {
setTimeout,
clearTimeout,
setImmediate = setImmediatePolyfill
} = globalObj;
exports.setImmediate = setImmediate;
exports.clearTimeout = clearTimeout;
exports.setTimeout = setTimeout;
function newMutationObserver(onMutation) {

@@ -27,19 +44,2 @@ const MutationObserverConstructor = typeof window !== 'undefined' && typeof window.MutationObserver !== 'undefined' ? window.MutationObserver : _mutationobserverShim.default;

return window.document;
}
/*
* There are browsers for which `setImmediate` is not available. This
* serves as a polyfill of sorts, adopting `setTimeout` as the closest
* equivalent
*/
function getSetImmediate() {
/* istanbul ignore else */
if (typeof setImmediate === 'function') {
return setImmediate;
} else {
return function (fn) {
return setTimeout(fn, 0);
};
}
}

@@ -23,4 +23,3 @@ "use strict";

return new Promise((resolve, reject) => {
const setImmediate = (0, _helpers.getSetImmediate)();
const timer = setTimeout(function () {
const timer = (0, _helpers.setTimeout)(function () {
onDone(new Error('Timed out in waitForDomChange.'), null);

@@ -34,4 +33,4 @@ }, timeout);

function onDone(error, result) {
clearTimeout(timer);
setImmediate(() => observer.disconnect());
(0, _helpers.clearTimeout)(timer);
(0, _helpers.setImmediate)(() => observer.disconnect());

@@ -38,0 +37,0 @@ if (error) {

@@ -27,3 +27,3 @@ "use strict";

const timer = setTimeout(function () {
const timer = (0, _helpers.setTimeout)(function () {
onDone(new Error('Timed out in waitForElementToBeRemoved.'), null);

@@ -59,5 +59,4 @@ }, timeout);

function onDone(error, result) {
const setImmediate = (0, _helpers.getSetImmediate)();
clearTimeout(timer);
setImmediate(() => observer.disconnect());
(0, _helpers.clearTimeout)(timer);
(0, _helpers.setImmediate)(() => observer.disconnect());

@@ -64,0 +63,0 @@ if (error) {

@@ -29,3 +29,3 @@ "use strict";

let lastError;
const timer = setTimeout(onTimeout, timeout);
const timer = (0, _helpers.setTimeout)(onTimeout, timeout);
const observer = (0, _helpers.newMutationObserver)(onMutation);

@@ -35,5 +35,4 @@ observer.observe(container, mutationObserverOptions);

function onDone(error, result) {
const setImmediate = (0, _helpers.getSetImmediate)();
clearTimeout(timer);
setImmediate(() => observer.disconnect());
(0, _helpers.clearTimeout)(timer);
(0, _helpers.setImmediate)(() => observer.disconnect());

@@ -40,0 +39,0 @@ if (error) {

{
"name": "@testing-library/dom",
"version": "5.5.2",
"version": "5.5.3",
"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 not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc