@testing-library/react
Advanced tools
Comparing version 13.4.0 to 13.5.0-alpha.1
@@ -37,3 +37,2 @@ 'use strict'; | ||
const domAct = testUtils__namespace.act; | ||
function getGlobalThis() { | ||
@@ -45,4 +44,2 @@ /* istanbul ignore else */ | ||
/* istanbul ignore next */ | ||
if (typeof self !== 'undefined') { | ||
@@ -52,4 +49,2 @@ return self; | ||
/* istanbul ignore next */ | ||
if (typeof window !== 'undefined') { | ||
@@ -59,4 +54,2 @@ return window; | ||
/* istanbul ignore next */ | ||
if (typeof global !== 'undefined') { | ||
@@ -66,15 +59,10 @@ return global; | ||
/* istanbul ignore next */ | ||
throw new Error('unable to locate global object'); | ||
} | ||
function setIsReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
@@ -84,3 +72,2 @@ return callback => { | ||
setIsReactActEnvironment(true); | ||
try { | ||
@@ -91,10 +78,7 @@ // The return value of `act` is always a thenable. | ||
const result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
@@ -125,14 +109,13 @@ const thenable = actResult; | ||
} | ||
const act = withGlobalActEnvironment(domAct); | ||
const act = withGlobalActEnvironment(domAct); | ||
/* eslint no-console:0 */ | ||
// react-testing-library's version of fireEvent will call | ||
// dom-testing-library's version of fireEvent. The reason | ||
// we make this distinction however is because we have | ||
// a few extra events that work a bit differently | ||
const fireEvent = function () { | ||
return dom.fireEvent(...arguments); | ||
}; | ||
Object.keys(dom.fireEvent).forEach(key => { | ||
@@ -142,9 +125,9 @@ fireEvent[key] = function () { | ||
}; | ||
}); // React event system tracks native mouseOver/mouseOut events for | ||
}); | ||
// React event system tracks native mouseOver/mouseOut events for | ||
// running onMouseEnter/onMouseLeave handlers | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31 | ||
const mouseEnter = fireEvent.mouseEnter; | ||
const mouseLeave = fireEvent.mouseLeave; | ||
fireEvent.mouseEnter = function () { | ||
@@ -154,3 +137,2 @@ mouseEnter(...arguments); | ||
}; | ||
fireEvent.mouseLeave = function () { | ||
@@ -160,6 +142,4 @@ mouseLeave(...arguments); | ||
}; | ||
const pointerEnter = fireEvent.pointerEnter; | ||
const pointerLeave = fireEvent.pointerLeave; | ||
fireEvent.pointerEnter = function () { | ||
@@ -169,3 +149,2 @@ pointerEnter(...arguments); | ||
}; | ||
fireEvent.pointerLeave = function () { | ||
@@ -175,9 +154,9 @@ pointerLeave(...arguments); | ||
}; | ||
const select = fireEvent.select; | ||
fireEvent.select = (node, init) => { | ||
select(node, init); // React tracks this event only on focused inputs | ||
select(node, init); | ||
// React tracks this event only on focused inputs | ||
node.focus(); | ||
node.focus(); // React creates this event when one of the following native events happens | ||
// React creates this event when one of the following native events happens | ||
// - contextMenu | ||
@@ -190,12 +169,10 @@ // - mouseUp | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224 | ||
fireEvent.keyUp(node, init); | ||
}; | ||
fireEvent.keyUp(node, init); | ||
}; // React event system tracks native focusout/focusin events for | ||
// React event system tracks native focusout/focusin events for | ||
// running blur/focus handlers | ||
// @link https://github.com/facebook/react/pull/19186 | ||
const blur = fireEvent.blur; | ||
const focus = fireEvent.focus; | ||
fireEvent.blur = function () { | ||
@@ -205,3 +182,2 @@ fireEvent.focusOut(...arguments); | ||
}; | ||
fireEvent.focus = function () { | ||
@@ -222,3 +198,2 @@ fireEvent.focusIn(...arguments); | ||
setIsReactActEnvironment(false); | ||
try { | ||
@@ -237,9 +212,9 @@ return await cb(); | ||
} | ||
}); // Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
}); | ||
// Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case) | ||
/** | ||
* @type {Set<import('react-dom').Container>} | ||
*/ | ||
const mountedContainers = new Set(); | ||
@@ -249,5 +224,3 @@ /** | ||
*/ | ||
const mountedRootEntries = []; | ||
function createConcurrentRoot(container, _ref) { | ||
@@ -260,3 +233,2 @@ let { | ||
let root; | ||
if (hydrate) { | ||
@@ -269,3 +241,2 @@ act(() => { | ||
} | ||
return { | ||
@@ -276,4 +247,4 @@ hydrate() { | ||
throw new Error('Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.'); | ||
} // Nothing to do since hydration happens when creating the root object. | ||
} | ||
// Nothing to do since hydration happens when creating the root object. | ||
}, | ||
@@ -284,10 +255,7 @@ | ||
}, | ||
unmount() { | ||
root.unmount(); | ||
} | ||
}; | ||
} | ||
function createLegacyRoot(container) { | ||
@@ -298,14 +266,10 @@ return { | ||
}, | ||
render(element) { | ||
ReactDOM__default["default"].render(element, container); | ||
}, | ||
unmount() { | ||
ReactDOM__default["default"].unmountComponentAtNode(container); | ||
} | ||
}; | ||
} | ||
function renderRoot(ui, _ref2) { | ||
@@ -320,5 +284,3 @@ let { | ||
} = _ref2; | ||
const wrapUiIfNeeded = innerElement => WrapperComponent ? /*#__PURE__*/React__namespace.createElement(WrapperComponent, null, innerElement) : innerElement; | ||
act(() => { | ||
@@ -338,5 +300,6 @@ if (hydrate) { | ||
} | ||
return Array.isArray(el) ? // eslint-disable-next-line no-console | ||
el.forEach(e => console.log(dom.prettyDOM(e, maxLength, options))) : // eslint-disable-next-line no-console, | ||
return Array.isArray(el) ? | ||
// eslint-disable-next-line no-console | ||
el.forEach(e => console.log(dom.prettyDOM(e, maxLength, options))) : | ||
// eslint-disable-next-line no-console, | ||
console.log(dom.prettyDOM(el, maxLength, options)); | ||
@@ -354,5 +317,7 @@ }, | ||
root | ||
}); // Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
}); | ||
// Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
// folks can use all the same utilities we return in the first place that are bound to the container | ||
}, | ||
asFragment: () => { | ||
@@ -371,3 +336,2 @@ /* istanbul ignore else (old jsdom limitation) */ | ||
} | ||
function render(ui, _temp) { | ||
@@ -382,3 +346,2 @@ let { | ||
} = _temp === void 0 ? {} : _temp; | ||
if (!baseElement) { | ||
@@ -389,9 +352,7 @@ // default to document.body instead of documentElement to avoid output of potentially-large | ||
} | ||
if (!container) { | ||
container = baseElement.appendChild(document.createElement('div')); | ||
} | ||
let root; // eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
let root; | ||
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
if (!mountedContainers.has(container)) { | ||
@@ -407,6 +368,6 @@ const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot; | ||
root | ||
}); // we'll add it to the mounted containers regardless of whether it's actually | ||
}); | ||
// we'll add it to the mounted containers regardless of whether it's actually | ||
// added to document.body so the cleanup method works regardless of whether | ||
// they're passing us a custom container or not. | ||
mountedContainers.add(container); | ||
@@ -417,3 +378,2 @@ } else { | ||
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries` | ||
/* istanbul ignore else */ | ||
@@ -425,3 +385,2 @@ if (rootEntry.container === container) { | ||
} | ||
return renderRoot(ui, { | ||
@@ -436,3 +395,2 @@ container, | ||
} | ||
function cleanup() { | ||
@@ -447,3 +405,2 @@ mountedRootEntries.forEach(_ref3 => { | ||
}); | ||
if (container.parentNode === document.body) { | ||
@@ -456,3 +413,2 @@ document.body.removeChild(container); | ||
} | ||
function renderHook(renderCallback, options) { | ||
@@ -462,3 +418,2 @@ if (options === void 0) { | ||
} | ||
const { | ||
@@ -469,3 +424,2 @@ initialProps, | ||
const result = /*#__PURE__*/React__namespace.createRef(); | ||
function TestComponent(_ref4) { | ||
@@ -481,3 +435,2 @@ let { | ||
} | ||
const { | ||
@@ -489,3 +442,2 @@ rerender: baseRerender, | ||
}), renderOptions); | ||
function rerender(rerenderCallbackProps) { | ||
@@ -496,3 +448,2 @@ return baseRerender( /*#__PURE__*/React__namespace.createElement(TestComponent, { | ||
} | ||
return { | ||
@@ -503,6 +454,7 @@ result, | ||
}; | ||
} // just re-export everything from dom-testing-library | ||
} | ||
/* eslint func-name-matching:0 */ | ||
var _process$env; | ||
// if we're running in a test runner that supports afterEach | ||
// or teardown then we'll automatically run cleanup afterEach test | ||
@@ -512,6 +464,4 @@ // this ensures that tests run in isolation from each other | ||
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'. | ||
if (typeof process === 'undefined' || !((_process$env = process.env) != null && _process$env.RTL_SKIP_AUTO_CLEANUP)) { | ||
if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { | ||
// ignore teardown() in code coverage because Jest does not support it | ||
/* istanbul ignore else */ | ||
@@ -529,7 +479,6 @@ if (typeof afterEach === 'function') { | ||
}); | ||
} // No test setup with other test runners available | ||
} | ||
// No test setup with other test runners available | ||
/* istanbul ignore else */ | ||
if (typeof beforeAll === 'function' && typeof afterAll === 'function') { | ||
@@ -536,0 +485,0 @@ // This matches the behavior of React < 18. |
@@ -9,3 +9,2 @@ import * as testUtils from 'react-dom/test-utils'; | ||
const domAct = testUtils.act; | ||
function getGlobalThis() { | ||
@@ -17,4 +16,2 @@ /* istanbul ignore else */ | ||
/* istanbul ignore next */ | ||
if (typeof self !== 'undefined') { | ||
@@ -24,4 +21,2 @@ return self; | ||
/* istanbul ignore next */ | ||
if (typeof window !== 'undefined') { | ||
@@ -31,4 +26,2 @@ return window; | ||
/* istanbul ignore next */ | ||
if (typeof global !== 'undefined') { | ||
@@ -38,15 +31,10 @@ return global; | ||
/* istanbul ignore next */ | ||
throw new Error('unable to locate global object'); | ||
} | ||
function setIsReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
@@ -56,3 +44,2 @@ return callback => { | ||
setIsReactActEnvironment(true); | ||
try { | ||
@@ -63,10 +50,7 @@ // The return value of `act` is always a thenable. | ||
const result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
@@ -97,14 +81,13 @@ const thenable = actResult; | ||
} | ||
const act = withGlobalActEnvironment(domAct); | ||
const act = withGlobalActEnvironment(domAct); | ||
/* eslint no-console:0 */ | ||
// react-testing-library's version of fireEvent will call | ||
// dom-testing-library's version of fireEvent. The reason | ||
// we make this distinction however is because we have | ||
// a few extra events that work a bit differently | ||
const fireEvent = function () { | ||
return fireEvent$1(...arguments); | ||
}; | ||
Object.keys(fireEvent$1).forEach(key => { | ||
@@ -114,9 +97,9 @@ fireEvent[key] = function () { | ||
}; | ||
}); // React event system tracks native mouseOver/mouseOut events for | ||
}); | ||
// React event system tracks native mouseOver/mouseOut events for | ||
// running onMouseEnter/onMouseLeave handlers | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31 | ||
const mouseEnter = fireEvent.mouseEnter; | ||
const mouseLeave = fireEvent.mouseLeave; | ||
fireEvent.mouseEnter = function () { | ||
@@ -126,3 +109,2 @@ mouseEnter(...arguments); | ||
}; | ||
fireEvent.mouseLeave = function () { | ||
@@ -132,6 +114,4 @@ mouseLeave(...arguments); | ||
}; | ||
const pointerEnter = fireEvent.pointerEnter; | ||
const pointerLeave = fireEvent.pointerLeave; | ||
fireEvent.pointerEnter = function () { | ||
@@ -141,3 +121,2 @@ pointerEnter(...arguments); | ||
}; | ||
fireEvent.pointerLeave = function () { | ||
@@ -147,9 +126,9 @@ pointerLeave(...arguments); | ||
}; | ||
const select = fireEvent.select; | ||
fireEvent.select = (node, init) => { | ||
select(node, init); // React tracks this event only on focused inputs | ||
select(node, init); | ||
// React tracks this event only on focused inputs | ||
node.focus(); | ||
node.focus(); // React creates this event when one of the following native events happens | ||
// React creates this event when one of the following native events happens | ||
// - contextMenu | ||
@@ -162,12 +141,10 @@ // - mouseUp | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224 | ||
fireEvent.keyUp(node, init); | ||
}; | ||
fireEvent.keyUp(node, init); | ||
}; // React event system tracks native focusout/focusin events for | ||
// React event system tracks native focusout/focusin events for | ||
// running blur/focus handlers | ||
// @link https://github.com/facebook/react/pull/19186 | ||
const blur = fireEvent.blur; | ||
const focus = fireEvent.focus; | ||
fireEvent.blur = function () { | ||
@@ -177,3 +154,2 @@ fireEvent.focusOut(...arguments); | ||
}; | ||
fireEvent.focus = function () { | ||
@@ -194,3 +170,2 @@ fireEvent.focusIn(...arguments); | ||
setIsReactActEnvironment(false); | ||
try { | ||
@@ -209,9 +184,9 @@ return await cb(); | ||
} | ||
}); // Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
}); | ||
// Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case) | ||
/** | ||
* @type {Set<import('react-dom').Container>} | ||
*/ | ||
const mountedContainers = new Set(); | ||
@@ -221,5 +196,3 @@ /** | ||
*/ | ||
const mountedRootEntries = []; | ||
function createConcurrentRoot(container, _ref) { | ||
@@ -232,3 +205,2 @@ let { | ||
let root; | ||
if (hydrate) { | ||
@@ -241,3 +213,2 @@ act(() => { | ||
} | ||
return { | ||
@@ -248,4 +219,4 @@ hydrate() { | ||
throw new Error('Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.'); | ||
} // Nothing to do since hydration happens when creating the root object. | ||
} | ||
// Nothing to do since hydration happens when creating the root object. | ||
}, | ||
@@ -256,10 +227,7 @@ | ||
}, | ||
unmount() { | ||
root.unmount(); | ||
} | ||
}; | ||
} | ||
function createLegacyRoot(container) { | ||
@@ -270,14 +238,10 @@ return { | ||
}, | ||
render(element) { | ||
ReactDOM.render(element, container); | ||
}, | ||
unmount() { | ||
ReactDOM.unmountComponentAtNode(container); | ||
} | ||
}; | ||
} | ||
function renderRoot(ui, _ref2) { | ||
@@ -292,5 +256,3 @@ let { | ||
} = _ref2; | ||
const wrapUiIfNeeded = innerElement => WrapperComponent ? /*#__PURE__*/React.createElement(WrapperComponent, null, innerElement) : innerElement; | ||
act(() => { | ||
@@ -310,5 +272,6 @@ if (hydrate) { | ||
} | ||
return Array.isArray(el) ? // eslint-disable-next-line no-console | ||
el.forEach(e => console.log(prettyDOM(e, maxLength, options))) : // eslint-disable-next-line no-console, | ||
return Array.isArray(el) ? | ||
// eslint-disable-next-line no-console | ||
el.forEach(e => console.log(prettyDOM(e, maxLength, options))) : | ||
// eslint-disable-next-line no-console, | ||
console.log(prettyDOM(el, maxLength, options)); | ||
@@ -326,5 +289,7 @@ }, | ||
root | ||
}); // Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
}); | ||
// Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
// folks can use all the same utilities we return in the first place that are bound to the container | ||
}, | ||
asFragment: () => { | ||
@@ -343,3 +308,2 @@ /* istanbul ignore else (old jsdom limitation) */ | ||
} | ||
function render(ui, _temp) { | ||
@@ -354,3 +318,2 @@ let { | ||
} = _temp === void 0 ? {} : _temp; | ||
if (!baseElement) { | ||
@@ -361,9 +324,7 @@ // default to document.body instead of documentElement to avoid output of potentially-large | ||
} | ||
if (!container) { | ||
container = baseElement.appendChild(document.createElement('div')); | ||
} | ||
let root; // eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
let root; | ||
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
if (!mountedContainers.has(container)) { | ||
@@ -379,6 +340,6 @@ const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot; | ||
root | ||
}); // we'll add it to the mounted containers regardless of whether it's actually | ||
}); | ||
// we'll add it to the mounted containers regardless of whether it's actually | ||
// added to document.body so the cleanup method works regardless of whether | ||
// they're passing us a custom container or not. | ||
mountedContainers.add(container); | ||
@@ -389,3 +350,2 @@ } else { | ||
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries` | ||
/* istanbul ignore else */ | ||
@@ -397,3 +357,2 @@ if (rootEntry.container === container) { | ||
} | ||
return renderRoot(ui, { | ||
@@ -408,3 +367,2 @@ container, | ||
} | ||
function cleanup() { | ||
@@ -419,3 +377,2 @@ mountedRootEntries.forEach(_ref3 => { | ||
}); | ||
if (container.parentNode === document.body) { | ||
@@ -428,3 +385,2 @@ document.body.removeChild(container); | ||
} | ||
function renderHook(renderCallback, options) { | ||
@@ -434,3 +390,2 @@ if (options === void 0) { | ||
} | ||
const { | ||
@@ -441,3 +396,2 @@ initialProps, | ||
const result = /*#__PURE__*/React.createRef(); | ||
function TestComponent(_ref4) { | ||
@@ -453,3 +407,2 @@ let { | ||
} | ||
const { | ||
@@ -461,3 +414,2 @@ rerender: baseRerender, | ||
}), renderOptions); | ||
function rerender(rerenderCallbackProps) { | ||
@@ -468,3 +420,2 @@ return baseRerender( /*#__PURE__*/React.createElement(TestComponent, { | ||
} | ||
return { | ||
@@ -475,6 +426,7 @@ result, | ||
}; | ||
} // just re-export everything from dom-testing-library | ||
} | ||
/* eslint func-name-matching:0 */ | ||
var _process$env; | ||
// if we're running in a test runner that supports afterEach | ||
// or teardown then we'll automatically run cleanup afterEach test | ||
@@ -484,6 +436,4 @@ // this ensures that tests run in isolation from each other | ||
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'. | ||
if (typeof process === 'undefined' || !((_process$env = process.env) != null && _process$env.RTL_SKIP_AUTO_CLEANUP)) { | ||
if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) { | ||
// ignore teardown() in code coverage because Jest does not support it | ||
/* istanbul ignore else */ | ||
@@ -501,7 +451,6 @@ if (typeof afterEach === 'function') { | ||
}); | ||
} // No test setup with other test runners available | ||
} | ||
// No test setup with other test runners available | ||
/* istanbul ignore else */ | ||
if (typeof beforeAll === 'function' && typeof afterAll === 'function') { | ||
@@ -508,0 +457,0 @@ // This matches the behavior of React < 18. |
@@ -37,3 +37,2 @@ 'use strict'; | ||
const domAct = testUtils__namespace.act; | ||
function getGlobalThis() { | ||
@@ -45,4 +44,2 @@ /* istanbul ignore else */ | ||
/* istanbul ignore next */ | ||
if (typeof self !== 'undefined') { | ||
@@ -52,4 +49,2 @@ return self; | ||
/* istanbul ignore next */ | ||
if (typeof window !== 'undefined') { | ||
@@ -59,4 +54,2 @@ return window; | ||
/* istanbul ignore next */ | ||
if (typeof global !== 'undefined') { | ||
@@ -66,15 +59,10 @@ return global; | ||
/* istanbul ignore next */ | ||
throw new Error('unable to locate global object'); | ||
} | ||
function setIsReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
@@ -84,3 +72,2 @@ return callback => { | ||
setIsReactActEnvironment(true); | ||
try { | ||
@@ -91,10 +78,7 @@ // The return value of `act` is always a thenable. | ||
const result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
@@ -125,14 +109,13 @@ const thenable = actResult; | ||
} | ||
const act = withGlobalActEnvironment(domAct); | ||
const act = withGlobalActEnvironment(domAct); | ||
/* eslint no-console:0 */ | ||
// react-testing-library's version of fireEvent will call | ||
// dom-testing-library's version of fireEvent. The reason | ||
// we make this distinction however is because we have | ||
// a few extra events that work a bit differently | ||
const fireEvent = function () { | ||
return dom.fireEvent(...arguments); | ||
}; | ||
Object.keys(dom.fireEvent).forEach(key => { | ||
@@ -142,9 +125,9 @@ fireEvent[key] = function () { | ||
}; | ||
}); // React event system tracks native mouseOver/mouseOut events for | ||
}); | ||
// React event system tracks native mouseOver/mouseOut events for | ||
// running onMouseEnter/onMouseLeave handlers | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31 | ||
const mouseEnter = fireEvent.mouseEnter; | ||
const mouseLeave = fireEvent.mouseLeave; | ||
fireEvent.mouseEnter = function () { | ||
@@ -154,3 +137,2 @@ mouseEnter(...arguments); | ||
}; | ||
fireEvent.mouseLeave = function () { | ||
@@ -160,6 +142,4 @@ mouseLeave(...arguments); | ||
}; | ||
const pointerEnter = fireEvent.pointerEnter; | ||
const pointerLeave = fireEvent.pointerLeave; | ||
fireEvent.pointerEnter = function () { | ||
@@ -169,3 +149,2 @@ pointerEnter(...arguments); | ||
}; | ||
fireEvent.pointerLeave = function () { | ||
@@ -175,9 +154,9 @@ pointerLeave(...arguments); | ||
}; | ||
const select = fireEvent.select; | ||
fireEvent.select = (node, init) => { | ||
select(node, init); // React tracks this event only on focused inputs | ||
select(node, init); | ||
// React tracks this event only on focused inputs | ||
node.focus(); | ||
node.focus(); // React creates this event when one of the following native events happens | ||
// React creates this event when one of the following native events happens | ||
// - contextMenu | ||
@@ -190,12 +169,10 @@ // - mouseUp | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224 | ||
fireEvent.keyUp(node, init); | ||
}; | ||
fireEvent.keyUp(node, init); | ||
}; // React event system tracks native focusout/focusin events for | ||
// React event system tracks native focusout/focusin events for | ||
// running blur/focus handlers | ||
// @link https://github.com/facebook/react/pull/19186 | ||
const blur = fireEvent.blur; | ||
const focus = fireEvent.focus; | ||
fireEvent.blur = function () { | ||
@@ -205,3 +182,2 @@ fireEvent.focusOut(...arguments); | ||
}; | ||
fireEvent.focus = function () { | ||
@@ -222,3 +198,2 @@ fireEvent.focusIn(...arguments); | ||
setIsReactActEnvironment(false); | ||
try { | ||
@@ -237,9 +212,9 @@ return await cb(); | ||
} | ||
}); // Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
}); | ||
// Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case) | ||
/** | ||
* @type {Set<import('react-dom').Container>} | ||
*/ | ||
const mountedContainers = new Set(); | ||
@@ -249,5 +224,3 @@ /** | ||
*/ | ||
const mountedRootEntries = []; | ||
function createConcurrentRoot(container, _ref) { | ||
@@ -260,3 +233,2 @@ let { | ||
let root; | ||
if (hydrate) { | ||
@@ -269,3 +241,2 @@ act(() => { | ||
} | ||
return { | ||
@@ -276,4 +247,4 @@ hydrate() { | ||
throw new Error('Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.'); | ||
} // Nothing to do since hydration happens when creating the root object. | ||
} | ||
// Nothing to do since hydration happens when creating the root object. | ||
}, | ||
@@ -284,10 +255,7 @@ | ||
}, | ||
unmount() { | ||
root.unmount(); | ||
} | ||
}; | ||
} | ||
function createLegacyRoot(container) { | ||
@@ -298,14 +266,10 @@ return { | ||
}, | ||
render(element) { | ||
ReactDOM__default["default"].render(element, container); | ||
}, | ||
unmount() { | ||
ReactDOM__default["default"].unmountComponentAtNode(container); | ||
} | ||
}; | ||
} | ||
function renderRoot(ui, _ref2) { | ||
@@ -320,5 +284,3 @@ let { | ||
} = _ref2; | ||
const wrapUiIfNeeded = innerElement => WrapperComponent ? /*#__PURE__*/React__namespace.createElement(WrapperComponent, null, innerElement) : innerElement; | ||
act(() => { | ||
@@ -338,5 +300,6 @@ if (hydrate) { | ||
} | ||
return Array.isArray(el) ? // eslint-disable-next-line no-console | ||
el.forEach(e => console.log(dom.prettyDOM(e, maxLength, options))) : // eslint-disable-next-line no-console, | ||
return Array.isArray(el) ? | ||
// eslint-disable-next-line no-console | ||
el.forEach(e => console.log(dom.prettyDOM(e, maxLength, options))) : | ||
// eslint-disable-next-line no-console, | ||
console.log(dom.prettyDOM(el, maxLength, options)); | ||
@@ -354,5 +317,7 @@ }, | ||
root | ||
}); // Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
}); | ||
// Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
// folks can use all the same utilities we return in the first place that are bound to the container | ||
}, | ||
asFragment: () => { | ||
@@ -371,3 +336,2 @@ /* istanbul ignore else (old jsdom limitation) */ | ||
} | ||
function render(ui, _temp) { | ||
@@ -382,3 +346,2 @@ let { | ||
} = _temp === void 0 ? {} : _temp; | ||
if (!baseElement) { | ||
@@ -389,9 +352,7 @@ // default to document.body instead of documentElement to avoid output of potentially-large | ||
} | ||
if (!container) { | ||
container = baseElement.appendChild(document.createElement('div')); | ||
} | ||
let root; // eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
let root; | ||
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
if (!mountedContainers.has(container)) { | ||
@@ -407,6 +368,6 @@ const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot; | ||
root | ||
}); // we'll add it to the mounted containers regardless of whether it's actually | ||
}); | ||
// we'll add it to the mounted containers regardless of whether it's actually | ||
// added to document.body so the cleanup method works regardless of whether | ||
// they're passing us a custom container or not. | ||
mountedContainers.add(container); | ||
@@ -417,3 +378,2 @@ } else { | ||
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries` | ||
/* istanbul ignore else */ | ||
@@ -425,3 +385,2 @@ if (rootEntry.container === container) { | ||
} | ||
return renderRoot(ui, { | ||
@@ -436,3 +395,2 @@ container, | ||
} | ||
function cleanup() { | ||
@@ -447,3 +405,2 @@ mountedRootEntries.forEach(_ref3 => { | ||
}); | ||
if (container.parentNode === document.body) { | ||
@@ -456,3 +413,2 @@ document.body.removeChild(container); | ||
} | ||
function renderHook(renderCallback, options) { | ||
@@ -462,3 +418,2 @@ if (options === void 0) { | ||
} | ||
const { | ||
@@ -469,3 +424,2 @@ initialProps, | ||
const result = /*#__PURE__*/React__namespace.createRef(); | ||
function TestComponent(_ref4) { | ||
@@ -481,3 +435,2 @@ let { | ||
} | ||
const { | ||
@@ -489,3 +442,2 @@ rerender: baseRerender, | ||
}), renderOptions); | ||
function rerender(rerenderCallbackProps) { | ||
@@ -496,3 +448,2 @@ return baseRerender( /*#__PURE__*/React__namespace.createElement(TestComponent, { | ||
} | ||
return { | ||
@@ -503,3 +454,4 @@ result, | ||
}; | ||
} // just re-export everything from dom-testing-library | ||
} | ||
/* eslint func-name-matching:0 */ | ||
@@ -506,0 +458,0 @@ |
@@ -9,3 +9,2 @@ import * as React from 'react'; | ||
const domAct = testUtils.act; | ||
function getGlobalThis() { | ||
@@ -17,4 +16,2 @@ /* istanbul ignore else */ | ||
/* istanbul ignore next */ | ||
if (typeof self !== 'undefined') { | ||
@@ -24,4 +21,2 @@ return self; | ||
/* istanbul ignore next */ | ||
if (typeof window !== 'undefined') { | ||
@@ -31,4 +26,2 @@ return window; | ||
/* istanbul ignore next */ | ||
if (typeof global !== 'undefined') { | ||
@@ -38,15 +31,10 @@ return global; | ||
/* istanbul ignore next */ | ||
throw new Error('unable to locate global object'); | ||
} | ||
function setIsReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
@@ -56,3 +44,2 @@ return callback => { | ||
setIsReactActEnvironment(true); | ||
try { | ||
@@ -63,10 +50,7 @@ // The return value of `act` is always a thenable. | ||
const result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
@@ -97,14 +81,13 @@ const thenable = actResult; | ||
} | ||
const act = withGlobalActEnvironment(domAct); | ||
const act = withGlobalActEnvironment(domAct); | ||
/* eslint no-console:0 */ | ||
// react-testing-library's version of fireEvent will call | ||
// dom-testing-library's version of fireEvent. The reason | ||
// we make this distinction however is because we have | ||
// a few extra events that work a bit differently | ||
const fireEvent = function () { | ||
return fireEvent$1(...arguments); | ||
}; | ||
Object.keys(fireEvent$1).forEach(key => { | ||
@@ -114,9 +97,9 @@ fireEvent[key] = function () { | ||
}; | ||
}); // React event system tracks native mouseOver/mouseOut events for | ||
}); | ||
// React event system tracks native mouseOver/mouseOut events for | ||
// running onMouseEnter/onMouseLeave handlers | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31 | ||
const mouseEnter = fireEvent.mouseEnter; | ||
const mouseLeave = fireEvent.mouseLeave; | ||
fireEvent.mouseEnter = function () { | ||
@@ -126,3 +109,2 @@ mouseEnter(...arguments); | ||
}; | ||
fireEvent.mouseLeave = function () { | ||
@@ -132,6 +114,4 @@ mouseLeave(...arguments); | ||
}; | ||
const pointerEnter = fireEvent.pointerEnter; | ||
const pointerLeave = fireEvent.pointerLeave; | ||
fireEvent.pointerEnter = function () { | ||
@@ -141,3 +121,2 @@ pointerEnter(...arguments); | ||
}; | ||
fireEvent.pointerLeave = function () { | ||
@@ -147,9 +126,9 @@ pointerLeave(...arguments); | ||
}; | ||
const select = fireEvent.select; | ||
fireEvent.select = (node, init) => { | ||
select(node, init); // React tracks this event only on focused inputs | ||
select(node, init); | ||
// React tracks this event only on focused inputs | ||
node.focus(); | ||
node.focus(); // React creates this event when one of the following native events happens | ||
// React creates this event when one of the following native events happens | ||
// - contextMenu | ||
@@ -162,12 +141,10 @@ // - mouseUp | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224 | ||
fireEvent.keyUp(node, init); | ||
}; | ||
fireEvent.keyUp(node, init); | ||
}; // React event system tracks native focusout/focusin events for | ||
// React event system tracks native focusout/focusin events for | ||
// running blur/focus handlers | ||
// @link https://github.com/facebook/react/pull/19186 | ||
const blur = fireEvent.blur; | ||
const focus = fireEvent.focus; | ||
fireEvent.blur = function () { | ||
@@ -177,3 +154,2 @@ fireEvent.focusOut(...arguments); | ||
}; | ||
fireEvent.focus = function () { | ||
@@ -194,3 +170,2 @@ fireEvent.focusIn(...arguments); | ||
setIsReactActEnvironment(false); | ||
try { | ||
@@ -209,9 +184,9 @@ return await cb(); | ||
} | ||
}); // Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
}); | ||
// Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case) | ||
/** | ||
* @type {Set<import('react-dom').Container>} | ||
*/ | ||
const mountedContainers = new Set(); | ||
@@ -221,5 +196,3 @@ /** | ||
*/ | ||
const mountedRootEntries = []; | ||
function createConcurrentRoot(container, _ref) { | ||
@@ -232,3 +205,2 @@ let { | ||
let root; | ||
if (hydrate) { | ||
@@ -241,3 +213,2 @@ act(() => { | ||
} | ||
return { | ||
@@ -248,4 +219,4 @@ hydrate() { | ||
throw new Error('Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.'); | ||
} // Nothing to do since hydration happens when creating the root object. | ||
} | ||
// Nothing to do since hydration happens when creating the root object. | ||
}, | ||
@@ -256,10 +227,7 @@ | ||
}, | ||
unmount() { | ||
root.unmount(); | ||
} | ||
}; | ||
} | ||
function createLegacyRoot(container) { | ||
@@ -270,14 +238,10 @@ return { | ||
}, | ||
render(element) { | ||
ReactDOM.render(element, container); | ||
}, | ||
unmount() { | ||
ReactDOM.unmountComponentAtNode(container); | ||
} | ||
}; | ||
} | ||
function renderRoot(ui, _ref2) { | ||
@@ -292,5 +256,3 @@ let { | ||
} = _ref2; | ||
const wrapUiIfNeeded = innerElement => WrapperComponent ? /*#__PURE__*/React.createElement(WrapperComponent, null, innerElement) : innerElement; | ||
act(() => { | ||
@@ -310,5 +272,6 @@ if (hydrate) { | ||
} | ||
return Array.isArray(el) ? // eslint-disable-next-line no-console | ||
el.forEach(e => console.log(prettyDOM(e, maxLength, options))) : // eslint-disable-next-line no-console, | ||
return Array.isArray(el) ? | ||
// eslint-disable-next-line no-console | ||
el.forEach(e => console.log(prettyDOM(e, maxLength, options))) : | ||
// eslint-disable-next-line no-console, | ||
console.log(prettyDOM(el, maxLength, options)); | ||
@@ -326,5 +289,7 @@ }, | ||
root | ||
}); // Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
}); | ||
// Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
// folks can use all the same utilities we return in the first place that are bound to the container | ||
}, | ||
asFragment: () => { | ||
@@ -343,3 +308,2 @@ /* istanbul ignore else (old jsdom limitation) */ | ||
} | ||
function render(ui, _temp) { | ||
@@ -354,3 +318,2 @@ let { | ||
} = _temp === void 0 ? {} : _temp; | ||
if (!baseElement) { | ||
@@ -361,9 +324,7 @@ // default to document.body instead of documentElement to avoid output of potentially-large | ||
} | ||
if (!container) { | ||
container = baseElement.appendChild(document.createElement('div')); | ||
} | ||
let root; // eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
let root; | ||
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
if (!mountedContainers.has(container)) { | ||
@@ -379,6 +340,6 @@ const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot; | ||
root | ||
}); // we'll add it to the mounted containers regardless of whether it's actually | ||
}); | ||
// we'll add it to the mounted containers regardless of whether it's actually | ||
// added to document.body so the cleanup method works regardless of whether | ||
// they're passing us a custom container or not. | ||
mountedContainers.add(container); | ||
@@ -389,3 +350,2 @@ } else { | ||
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries` | ||
/* istanbul ignore else */ | ||
@@ -397,3 +357,2 @@ if (rootEntry.container === container) { | ||
} | ||
return renderRoot(ui, { | ||
@@ -408,3 +367,2 @@ container, | ||
} | ||
function cleanup() { | ||
@@ -419,3 +377,2 @@ mountedRootEntries.forEach(_ref3 => { | ||
}); | ||
if (container.parentNode === document.body) { | ||
@@ -428,3 +385,2 @@ document.body.removeChild(container); | ||
} | ||
function renderHook(renderCallback, options) { | ||
@@ -434,3 +390,2 @@ if (options === void 0) { | ||
} | ||
const { | ||
@@ -441,3 +396,2 @@ initialProps, | ||
const result = /*#__PURE__*/React.createRef(); | ||
function TestComponent(_ref4) { | ||
@@ -453,3 +407,2 @@ let { | ||
} | ||
const { | ||
@@ -461,3 +414,2 @@ rerender: baseRerender, | ||
}), renderOptions); | ||
function rerender(rerenderCallbackProps) { | ||
@@ -468,3 +420,2 @@ return baseRerender( /*#__PURE__*/React.createElement(TestComponent, { | ||
} | ||
return { | ||
@@ -475,5 +426,6 @@ result, | ||
}; | ||
} // just re-export everything from dom-testing-library | ||
} | ||
/* eslint func-name-matching:0 */ | ||
export { act, cleanup, fireEvent, render, renderHook }; |
@@ -9,11 +9,6 @@ "use strict"; | ||
exports.setReactActEnvironment = setIsReactActEnvironment; | ||
var testUtils = _interopRequireWildcard(require("react-dom/test-utils")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const domAct = testUtils.act; | ||
function getGlobalThis() { | ||
@@ -25,4 +20,2 @@ /* istanbul ignore else */ | ||
/* istanbul ignore next */ | ||
if (typeof self !== 'undefined') { | ||
@@ -32,4 +25,2 @@ return self; | ||
/* istanbul ignore next */ | ||
if (typeof window !== 'undefined') { | ||
@@ -39,4 +30,2 @@ return window; | ||
/* istanbul ignore next */ | ||
if (typeof global !== 'undefined') { | ||
@@ -46,15 +35,10 @@ return global; | ||
/* istanbul ignore next */ | ||
throw new Error('unable to locate global object'); | ||
} | ||
function setIsReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
@@ -64,3 +48,2 @@ return callback => { | ||
setIsReactActEnvironment(true); | ||
try { | ||
@@ -71,10 +54,7 @@ // The return value of `act` is always a thenable. | ||
const result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
@@ -105,7 +85,5 @@ const thenable = actResult; | ||
} | ||
const act = withGlobalActEnvironment(domAct); | ||
var _default = act; | ||
/* eslint no-console:0 */ | ||
exports.default = _default; |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.fireEvent = void 0; | ||
var _dom = require("@testing-library/dom"); | ||
// react-testing-library's version of fireEvent will call | ||
@@ -16,13 +14,12 @@ // dom-testing-library's version of fireEvent. The reason | ||
const fireEvent = (...args) => (0, _dom.fireEvent)(...args); | ||
exports.fireEvent = fireEvent; | ||
Object.keys(_dom.fireEvent).forEach(key => { | ||
fireEvent[key] = (...args) => _dom.fireEvent[key](...args); | ||
}); // React event system tracks native mouseOver/mouseOut events for | ||
}); | ||
// React event system tracks native mouseOver/mouseOut events for | ||
// running onMouseEnter/onMouseLeave handlers | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31 | ||
const mouseEnter = fireEvent.mouseEnter; | ||
const mouseLeave = fireEvent.mouseLeave; | ||
fireEvent.mouseEnter = (...args) => { | ||
@@ -32,3 +29,2 @@ mouseEnter(...args); | ||
}; | ||
fireEvent.mouseLeave = (...args) => { | ||
@@ -38,6 +34,4 @@ mouseLeave(...args); | ||
}; | ||
const pointerEnter = fireEvent.pointerEnter; | ||
const pointerLeave = fireEvent.pointerLeave; | ||
fireEvent.pointerEnter = (...args) => { | ||
@@ -47,3 +41,2 @@ pointerEnter(...args); | ||
}; | ||
fireEvent.pointerLeave = (...args) => { | ||
@@ -53,9 +46,9 @@ pointerLeave(...args); | ||
}; | ||
const select = fireEvent.select; | ||
fireEvent.select = (node, init) => { | ||
select(node, init); // React tracks this event only on focused inputs | ||
select(node, init); | ||
// React tracks this event only on focused inputs | ||
node.focus(); | ||
node.focus(); // React creates this event when one of the following native events happens | ||
// React creates this event when one of the following native events happens | ||
// - contextMenu | ||
@@ -68,12 +61,10 @@ // - mouseUp | ||
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224 | ||
fireEvent.keyUp(node, init); | ||
}; | ||
fireEvent.keyUp(node, init); | ||
}; // React event system tracks native focusout/focusin events for | ||
// React event system tracks native focusout/focusin events for | ||
// running blur/focus handlers | ||
// @link https://github.com/facebook/react/pull/19186 | ||
const blur = fireEvent.blur; | ||
const focus = fireEvent.focus; | ||
fireEvent.blur = (...args) => { | ||
@@ -83,3 +74,2 @@ fireEvent.focusOut(...args); | ||
}; | ||
fireEvent.focus = (...args) => { | ||
@@ -86,0 +76,0 @@ fireEvent.focusIn(...args); |
@@ -6,7 +6,4 @@ "use strict"; | ||
}); | ||
var _actCompat = require("./act-compat"); | ||
var _pure = require("./pure"); | ||
Object.keys(_pure).forEach(function (key) { | ||
@@ -22,5 +19,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _process$env; | ||
// if we're running in a test runner that supports afterEach | ||
@@ -33,3 +28,2 @@ // or teardown then we'll automatically run cleanup afterEach test | ||
// ignore teardown() in code coverage because Jest does not support it | ||
/* istanbul ignore else */ | ||
@@ -47,7 +41,6 @@ if (typeof afterEach === 'function') { | ||
}); | ||
} // No test setup with other test runners available | ||
} | ||
// No test setup with other test runners available | ||
/* istanbul ignore else */ | ||
if (typeof beforeAll === 'function' && typeof afterAll === 'function') { | ||
@@ -54,0 +47,0 @@ // This matches the behavior of React < 18. |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -30,11 +29,6 @@ value: true | ||
exports.renderHook = renderHook; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _reactDom = _interopRequireDefault(require("react-dom")); | ||
var ReactDOMClient = _interopRequireWildcard(require("react-dom/client")); | ||
var _dom = require("@testing-library/dom"); | ||
Object.keys(_dom).forEach(function (key) { | ||
@@ -51,11 +45,6 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _actCompat = _interopRequireWildcard(require("./act-compat")); | ||
var _fireEvent = require("./fire-event"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
(0, _dom.configure)({ | ||
@@ -71,3 +60,2 @@ unstable_advanceTimersWrapper: cb => { | ||
(0, _actCompat.setReactActEnvironment)(false); | ||
try { | ||
@@ -86,9 +74,9 @@ return await cb(); | ||
} | ||
}); // Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
}); | ||
// Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case) | ||
/** | ||
* @type {Set<import('react-dom').Container>} | ||
*/ | ||
const mountedContainers = new Set(); | ||
@@ -98,5 +86,3 @@ /** | ||
*/ | ||
const mountedRootEntries = []; | ||
function createConcurrentRoot(container, { | ||
@@ -108,3 +94,2 @@ hydrate, | ||
let root; | ||
if (hydrate) { | ||
@@ -117,3 +102,2 @@ (0, _actCompat.default)(() => { | ||
} | ||
return { | ||
@@ -124,4 +108,4 @@ hydrate() { | ||
throw new Error('Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.'); | ||
} // Nothing to do since hydration happens when creating the root object. | ||
} | ||
// Nothing to do since hydration happens when creating the root object. | ||
}, | ||
@@ -132,10 +116,7 @@ | ||
}, | ||
unmount() { | ||
root.unmount(); | ||
} | ||
}; | ||
} | ||
function createLegacyRoot(container) { | ||
@@ -146,14 +127,10 @@ return { | ||
}, | ||
render(element) { | ||
_reactDom.default.render(element, container); | ||
}, | ||
unmount() { | ||
_reactDom.default.unmountComponentAtNode(container); | ||
} | ||
}; | ||
} | ||
function renderRoot(ui, { | ||
@@ -168,3 +145,2 @@ baseElement, | ||
const wrapUiIfNeeded = innerElement => WrapperComponent ? /*#__PURE__*/React.createElement(WrapperComponent, null, innerElement) : innerElement; | ||
(0, _actCompat.default)(() => { | ||
@@ -180,4 +156,6 @@ if (hydrate) { | ||
baseElement, | ||
debug: (el = baseElement, maxLength, options) => Array.isArray(el) ? // eslint-disable-next-line no-console | ||
el.forEach(e => console.log((0, _dom.prettyDOM)(e, maxLength, options))) : // eslint-disable-next-line no-console, | ||
debug: (el = baseElement, maxLength, options) => Array.isArray(el) ? | ||
// eslint-disable-next-line no-console | ||
el.forEach(e => console.log((0, _dom.prettyDOM)(e, maxLength, options))) : | ||
// eslint-disable-next-line no-console, | ||
console.log((0, _dom.prettyDOM)(el, maxLength, options)), | ||
@@ -194,5 +172,7 @@ unmount: () => { | ||
root | ||
}); // Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
}); | ||
// Intentionally do not return anything to avoid unnecessarily complicating the API. | ||
// folks can use all the same utilities we return in the first place that are bound to the container | ||
}, | ||
asFragment: () => { | ||
@@ -211,3 +191,2 @@ /* istanbul ignore else (old jsdom limitation) */ | ||
} | ||
function render(ui, { | ||
@@ -226,9 +205,7 @@ container, | ||
} | ||
if (!container) { | ||
container = baseElement.appendChild(document.createElement('div')); | ||
} | ||
let root; // eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
let root; | ||
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first. | ||
if (!mountedContainers.has(container)) { | ||
@@ -244,6 +221,6 @@ const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot; | ||
root | ||
}); // we'll add it to the mounted containers regardless of whether it's actually | ||
}); | ||
// we'll add it to the mounted containers regardless of whether it's actually | ||
// added to document.body so the cleanup method works regardless of whether | ||
// they're passing us a custom container or not. | ||
mountedContainers.add(container); | ||
@@ -254,3 +231,2 @@ } else { | ||
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries` | ||
/* istanbul ignore else */ | ||
@@ -262,3 +238,2 @@ if (rootEntry.container === container) { | ||
} | ||
return renderRoot(ui, { | ||
@@ -273,3 +248,2 @@ container, | ||
} | ||
function cleanup() { | ||
@@ -283,3 +257,2 @@ mountedRootEntries.forEach(({ | ||
}); | ||
if (container.parentNode === document.body) { | ||
@@ -292,3 +265,2 @@ document.body.removeChild(container); | ||
} | ||
function renderHook(renderCallback, options = {}) { | ||
@@ -300,3 +272,2 @@ const { | ||
const result = /*#__PURE__*/React.createRef(); | ||
function TestComponent({ | ||
@@ -311,3 +282,2 @@ renderCallbackProps | ||
} | ||
const { | ||
@@ -319,3 +289,2 @@ rerender: baseRerender, | ||
}), renderOptions); | ||
function rerender(rerenderCallbackProps) { | ||
@@ -326,3 +295,2 @@ return baseRerender( /*#__PURE__*/React.createElement(TestComponent, { | ||
} | ||
return { | ||
@@ -333,4 +301,6 @@ result, | ||
}; | ||
} // just re-export everything from dom-testing-library | ||
} | ||
// just re-export everything from dom-testing-library | ||
/* eslint func-name-matching:0 */ |
{ | ||
"name": "@testing-library/react", | ||
"version": "13.4.0", | ||
"version": "13.5.0-alpha.1", | ||
"description": "Simple and complete React DOM testing utilities that encourage good testing practices.", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14" | ||
}, | ||
@@ -55,3 +55,5 @@ "scripts": { | ||
"@testing-library/jest-dom": "^5.11.6", | ||
"chalk": "^4.1.2", | ||
"dotenv-cli": "^4.0.0", | ||
"jest-diff": "^27.5.1", | ||
"kcd-scripts": "^11.1.0", | ||
@@ -58,0 +60,0 @@ "npm-run-all": "^4.1.5", |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
5283661
34563
690
5
10
3
16