node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

@@ -0,0 +1,532 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
var DeprecatedReactTestUtils = require('react-dom/test-utils');
var ReactDOM = require('react-dom');
var ReactDOMClient = require('react-dom/client');
var dom = require('@testing-library/dom');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var DeprecatedReactTestUtils__namespace = /*#__PURE__*/_interopNamespace(DeprecatedReactTestUtils);
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
var ReactDOMClient__namespace = /*#__PURE__*/_interopNamespace(ReactDOMClient);
const reactAct = typeof React__namespace.act === 'function' ? React__namespace.act : DeprecatedReactTestUtils__namespace.act;
function getGlobalThis() {
/* istanbul ignore else */
if (typeof globalThis !== 'undefined') {
return globalThis;
}
/* istanbul ignore next */
if (typeof self !== 'undefined') {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined') {
return window;
}
/* istanbul ignore next */
if (typeof global !== 'undefined') {
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) {
return callback => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(true);
try {
// The return value of `act` is always a thenable.
let callbackNeedsToBeAwaited = false;
const actResult = actImplementation(() => {
const result = callback();
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
callbackNeedsToBeAwaited = true;
}
return result;
});
if (callbackNeedsToBeAwaited) {
const thenable = actResult;
return {
then: (resolve, reject) => {
thenable.then(returnValue => {
setIsReactActEnvironment(previousActEnvironment);
resolve(returnValue);
}, error => {
setIsReactActEnvironment(previousActEnvironment);
reject(error);
});
}
};
} else {
setIsReactActEnvironment(previousActEnvironment);
return actResult;
}
} catch (error) {
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
// or if we have to await the callback first.
setIsReactActEnvironment(previousActEnvironment);
throw error;
}
};
}
const act = withGlobalActEnvironment(reactAct);
/* 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 => {
fireEvent[key] = function () {
return dom.fireEvent[key](...arguments);
};
});
// 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 () {
mouseEnter(...arguments);
return fireEvent.mouseOver(...arguments);
};
fireEvent.mouseLeave = function () {
mouseLeave(...arguments);
return fireEvent.mouseOut(...arguments);
};
const pointerEnter = fireEvent.pointerEnter;
const pointerLeave = fireEvent.pointerLeave;
fireEvent.pointerEnter = function () {
pointerEnter(...arguments);
return fireEvent.pointerOver(...arguments);
};
fireEvent.pointerLeave = function () {
pointerLeave(...arguments);
return fireEvent.pointerOut(...arguments);
};
const select = fireEvent.select;
fireEvent.select = (node, init) => {
select(node, init);
// React tracks this event only on focused inputs
node.focus();
// React creates this event when one of the following native events happens
// - contextMenu
// - mouseUp
// - dragEnd
// - keyUp
// - keyDown
// so we can use any here
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
fireEvent.keyUp(node, init);
};
// 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 () {
fireEvent.focusOut(...arguments);
return blur(...arguments);
};
fireEvent.focus = function () {
fireEvent.focusIn(...arguments);
return focus(...arguments);
};
let configForRTL = {
reactStrictMode: false
};
function getConfig() {
return {
...dom.getConfig(),
...configForRTL
};
}
function configure(newConfig) {
if (typeof newConfig === 'function') {
// Pass the existing config out to the provided function
// and accept a delta in return
newConfig = newConfig(getConfig());
}
const {
reactStrictMode,
...configForDTL
} = newConfig;
dom.configure(configForDTL);
configForRTL = {
...configForRTL,
reactStrictMode
};
}
function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true ||
// modern timers
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
);
} // istanbul ignore next
return false;
}
dom.configure({
unstable_advanceTimersWrapper: cb => {
return act(cb);
},
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
// But that's not necessarily how `asyncWrapper` is used since it's a public method.
// Let's just hope nobody else is using it.
asyncWrapper: async cb => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(false);
try {
const result = await cb();
// Drain microtask queue.
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
// The caller would have no chance to wrap the in-flight Promises in `act()`
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, 0);
if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(0);
}
});
return result;
} finally {
setIsReactActEnvironment(previousActEnvironment);
}
},
eventWrapper: cb => {
let result;
act(() => {
result = cb();
});
return result;
}
});
// 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();
/**
* @type Array<{container: import('react-dom').Container, root: ReturnType<typeof createConcurrentRoot>}>
*/
const mountedRootEntries = [];
function strictModeIfNeeded(innerElement) {
return getConfig().reactStrictMode ? /*#__PURE__*/React__namespace.createElement(React__namespace.StrictMode, null, innerElement) : innerElement;
}
function wrapUiIfNeeded(innerElement, wrapperComponent) {
return wrapperComponent ? /*#__PURE__*/React__namespace.createElement(wrapperComponent, null, innerElement) : innerElement;
}
function createConcurrentRoot(container, _ref) {
let {
hydrate,
ui,
wrapper: WrapperComponent
} = _ref;
let root;
if (hydrate) {
act(() => {
root = ReactDOMClient__namespace.hydrateRoot(container, strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)));
});
} else {
root = ReactDOMClient__namespace.createRoot(container);
}
return {
hydrate() {
/* istanbul ignore if */
if (!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.
},
render(element) {
root.render(element);
},
unmount() {
root.unmount();
}
};
}
function createLegacyRoot(container) {
return {
hydrate(element) {
ReactDOM__default["default"].hydrate(element, container);
},
render(element) {
ReactDOM__default["default"].render(element, container);
},
unmount() {
ReactDOM__default["default"].unmountComponentAtNode(container);
}
};
}
function renderRoot(ui, _ref2) {
let {
baseElement,
container,
hydrate,
queries,
root,
wrapper: WrapperComponent
} = _ref2;
act(() => {
if (hydrate) {
root.hydrate(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
} else {
root.render(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
}
});
return {
container,
baseElement,
debug: function (el, maxLength, options) {
if (el === void 0) {
el = baseElement;
}
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));
},
unmount: () => {
act(() => {
root.unmount();
});
},
rerender: rerenderUi => {
renderRoot(rerenderUi, {
container,
baseElement,
root,
wrapper: WrapperComponent
});
// 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: () => {
/* istanbul ignore else (old jsdom limitation) */
if (typeof document.createRange === 'function') {
return document.createRange().createContextualFragment(container.innerHTML);
} else {
const template = document.createElement('template');
template.innerHTML = container.innerHTML;
return template.content;
}
},
...dom.getQueriesForElement(baseElement, queries)
};
}
function render(ui, _temp) {
let {
container,
baseElement = container,
legacyRoot = false,
queries,
hydrate = false,
wrapper
} = _temp === void 0 ? {} : _temp;
if (legacyRoot && typeof ReactDOM__default["default"].render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, render);
throw error;
}
if (!baseElement) {
// default to document.body instead of documentElement to avoid output of potentially-large
// head elements (such as JSS style blocks) in debug output
baseElement = document.body;
}
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.
if (!mountedContainers.has(container)) {
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
root = createRootImpl(container, {
hydrate,
ui,
wrapper
});
mountedRootEntries.push({
container,
root
});
// 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);
} else {
mountedRootEntries.forEach(rootEntry => {
// Else is unreachable since `mountedContainers` has the `container`.
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries`
/* istanbul ignore else */
if (rootEntry.container === container) {
root = rootEntry.root;
}
});
}
return renderRoot(ui, {
container,
baseElement,
queries,
hydrate,
wrapper,
root
});
}
function cleanup() {
mountedRootEntries.forEach(_ref3 => {
let {
root,
container
} = _ref3;
act(() => {
root.unmount();
});
if (container.parentNode === document.body) {
document.body.removeChild(container);
}
});
mountedRootEntries.length = 0;
mountedContainers.clear();
}
function renderHook(renderCallback, options) {
if (options === void 0) {
options = {};
}
const {
initialProps,
...renderOptions
} = options;
if (renderOptions.legacyRoot && typeof ReactDOM__default["default"].render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, renderHook);
throw error;
}
const result = /*#__PURE__*/React__namespace.createRef();
function TestComponent(_ref4) {
let {
renderCallbackProps
} = _ref4;
const pendingResult = renderCallback(renderCallbackProps);
React__namespace.useEffect(() => {
result.current = pendingResult;
});
return null;
}
const {
rerender: baseRerender,
unmount
} = render( /*#__PURE__*/React__namespace.createElement(TestComponent, {
renderCallbackProps: initialProps
}), renderOptions);
function rerender(rerenderCallbackProps) {
return baseRerender( /*#__PURE__*/React__namespace.createElement(TestComponent, {
renderCallbackProps: rerenderCallbackProps
}));
}
return {
result,
rerender,
unmount
};
}
/* eslint func-name-matching:0 */
// if we're running in a test runner that supports afterEach
// or teardown then we'll automatically run cleanup afterEach test
// this ensures that tests run in isolation from each other
// if you don't like this then either import the `pure` module
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'.
if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) {
// ignore teardown() in code coverage because Jest does not support it
/* istanbul ignore else */
if (typeof afterEach === 'function') {
afterEach(() => {
cleanup();
});
} else if (typeof teardown === 'function') {
// Block is guarded by `typeof` check.
// eslint does not support `typeof` guards.
// eslint-disable-next-line no-undef
teardown(() => {
cleanup();
});
}
// No test setup with other test runners available
/* istanbul ignore else */
if (typeof beforeAll === 'function' && typeof afterAll === 'function') {
// This matches the behavior of React < 18.
let previousIsReactActEnvironment = getIsReactActEnvironment();
beforeAll(() => {
previousIsReactActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(true);
});
afterAll(() => {
setIsReactActEnvironment(previousIsReactActEnvironment);
});
}
}
exports.act = act;
exports.cleanup = cleanup;
exports.configure = configure;
exports.fireEvent = fireEvent;
exports.getConfig = getConfig;
exports.render = render;
exports.renderHook = renderHook;
Object.keys(dom).forEach(function (k) {
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return dom[k]; }
});
});
@@ -0,0 +1,492 @@
import * as React from 'react';
import * as DeprecatedReactTestUtils from 'react-dom/test-utils';
import ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import { fireEvent as fireEvent$1, getConfig as getConfig$1, configure as configure$1, prettyDOM, getQueriesForElement } from '@testing-library/dom';
export * from '@testing-library/dom';
const reactAct = typeof React.act === 'function' ? React.act : DeprecatedReactTestUtils.act;
function getGlobalThis() {
/* istanbul ignore else */
if (typeof globalThis !== 'undefined') {
return globalThis;
}
/* istanbul ignore next */
if (typeof self !== 'undefined') {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined') {
return window;
}
/* istanbul ignore next */
if (typeof global !== 'undefined') {
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) {
return callback => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(true);
try {
// The return value of `act` is always a thenable.
let callbackNeedsToBeAwaited = false;
const actResult = actImplementation(() => {
const result = callback();
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
callbackNeedsToBeAwaited = true;
}
return result;
});
if (callbackNeedsToBeAwaited) {
const thenable = actResult;
return {
then: (resolve, reject) => {
thenable.then(returnValue => {
setIsReactActEnvironment(previousActEnvironment);
resolve(returnValue);
}, error => {
setIsReactActEnvironment(previousActEnvironment);
reject(error);
});
}
};
} else {
setIsReactActEnvironment(previousActEnvironment);
return actResult;
}
} catch (error) {
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
// or if we have to await the callback first.
setIsReactActEnvironment(previousActEnvironment);
throw error;
}
};
}
const act = withGlobalActEnvironment(reactAct);
/* 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 => {
fireEvent[key] = function () {
return fireEvent$1[key](...arguments);
};
});
// 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 () {
mouseEnter(...arguments);
return fireEvent.mouseOver(...arguments);
};
fireEvent.mouseLeave = function () {
mouseLeave(...arguments);
return fireEvent.mouseOut(...arguments);
};
const pointerEnter = fireEvent.pointerEnter;
const pointerLeave = fireEvent.pointerLeave;
fireEvent.pointerEnter = function () {
pointerEnter(...arguments);
return fireEvent.pointerOver(...arguments);
};
fireEvent.pointerLeave = function () {
pointerLeave(...arguments);
return fireEvent.pointerOut(...arguments);
};
const select = fireEvent.select;
fireEvent.select = (node, init) => {
select(node, init);
// React tracks this event only on focused inputs
node.focus();
// React creates this event when one of the following native events happens
// - contextMenu
// - mouseUp
// - dragEnd
// - keyUp
// - keyDown
// so we can use any here
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
fireEvent.keyUp(node, init);
};
// 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 () {
fireEvent.focusOut(...arguments);
return blur(...arguments);
};
fireEvent.focus = function () {
fireEvent.focusIn(...arguments);
return focus(...arguments);
};
let configForRTL = {
reactStrictMode: false
};
function getConfig() {
return {
...getConfig$1(),
...configForRTL
};
}
function configure(newConfig) {
if (typeof newConfig === 'function') {
// Pass the existing config out to the provided function
// and accept a delta in return
newConfig = newConfig(getConfig());
}
const {
reactStrictMode,
...configForDTL
} = newConfig;
configure$1(configForDTL);
configForRTL = {
...configForRTL,
reactStrictMode
};
}
function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true ||
// modern timers
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
);
} // istanbul ignore next
return false;
}
configure$1({
unstable_advanceTimersWrapper: cb => {
return act(cb);
},
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
// But that's not necessarily how `asyncWrapper` is used since it's a public method.
// Let's just hope nobody else is using it.
asyncWrapper: async cb => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(false);
try {
const result = await cb();
// Drain microtask queue.
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
// The caller would have no chance to wrap the in-flight Promises in `act()`
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, 0);
if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(0);
}
});
return result;
} finally {
setIsReactActEnvironment(previousActEnvironment);
}
},
eventWrapper: cb => {
let result;
act(() => {
result = cb();
});
return result;
}
});
// 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();
/**
* @type Array<{container: import('react-dom').Container, root: ReturnType<typeof createConcurrentRoot>}>
*/
const mountedRootEntries = [];
function strictModeIfNeeded(innerElement) {
return getConfig().reactStrictMode ? /*#__PURE__*/React.createElement(React.StrictMode, null, innerElement) : innerElement;
}
function wrapUiIfNeeded(innerElement, wrapperComponent) {
return wrapperComponent ? /*#__PURE__*/React.createElement(wrapperComponent, null, innerElement) : innerElement;
}
function createConcurrentRoot(container, _ref) {
let {
hydrate,
ui,
wrapper: WrapperComponent
} = _ref;
let root;
if (hydrate) {
act(() => {
root = ReactDOMClient.hydrateRoot(container, strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)));
});
} else {
root = ReactDOMClient.createRoot(container);
}
return {
hydrate() {
/* istanbul ignore if */
if (!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.
},
render(element) {
root.render(element);
},
unmount() {
root.unmount();
}
};
}
function createLegacyRoot(container) {
return {
hydrate(element) {
ReactDOM.hydrate(element, container);
},
render(element) {
ReactDOM.render(element, container);
},
unmount() {
ReactDOM.unmountComponentAtNode(container);
}
};
}
function renderRoot(ui, _ref2) {
let {
baseElement,
container,
hydrate,
queries,
root,
wrapper: WrapperComponent
} = _ref2;
act(() => {
if (hydrate) {
root.hydrate(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
} else {
root.render(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
}
});
return {
container,
baseElement,
debug: function (el, maxLength, options) {
if (el === void 0) {
el = baseElement;
}
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));
},
unmount: () => {
act(() => {
root.unmount();
});
},
rerender: rerenderUi => {
renderRoot(rerenderUi, {
container,
baseElement,
root,
wrapper: WrapperComponent
});
// 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: () => {
/* istanbul ignore else (old jsdom limitation) */
if (typeof document.createRange === 'function') {
return document.createRange().createContextualFragment(container.innerHTML);
} else {
const template = document.createElement('template');
template.innerHTML = container.innerHTML;
return template.content;
}
},
...getQueriesForElement(baseElement, queries)
};
}
function render(ui, _temp) {
let {
container,
baseElement = container,
legacyRoot = false,
queries,
hydrate = false,
wrapper
} = _temp === void 0 ? {} : _temp;
if (legacyRoot && typeof ReactDOM.render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, render);
throw error;
}
if (!baseElement) {
// default to document.body instead of documentElement to avoid output of potentially-large
// head elements (such as JSS style blocks) in debug output
baseElement = document.body;
}
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.
if (!mountedContainers.has(container)) {
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
root = createRootImpl(container, {
hydrate,
ui,
wrapper
});
mountedRootEntries.push({
container,
root
});
// 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);
} else {
mountedRootEntries.forEach(rootEntry => {
// Else is unreachable since `mountedContainers` has the `container`.
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries`
/* istanbul ignore else */
if (rootEntry.container === container) {
root = rootEntry.root;
}
});
}
return renderRoot(ui, {
container,
baseElement,
queries,
hydrate,
wrapper,
root
});
}
function cleanup() {
mountedRootEntries.forEach(_ref3 => {
let {
root,
container
} = _ref3;
act(() => {
root.unmount();
});
if (container.parentNode === document.body) {
document.body.removeChild(container);
}
});
mountedRootEntries.length = 0;
mountedContainers.clear();
}
function renderHook(renderCallback, options) {
if (options === void 0) {
options = {};
}
const {
initialProps,
...renderOptions
} = options;
if (renderOptions.legacyRoot && typeof ReactDOM.render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, renderHook);
throw error;
}
const result = /*#__PURE__*/React.createRef();
function TestComponent(_ref4) {
let {
renderCallbackProps
} = _ref4;
const pendingResult = renderCallback(renderCallbackProps);
React.useEffect(() => {
result.current = pendingResult;
});
return null;
}
const {
rerender: baseRerender,
unmount
} = render( /*#__PURE__*/React.createElement(TestComponent, {
renderCallbackProps: initialProps
}), renderOptions);
function rerender(rerenderCallbackProps) {
return baseRerender( /*#__PURE__*/React.createElement(TestComponent, {
renderCallbackProps: rerenderCallbackProps
}));
}
return {
result,
rerender,
unmount
};
}
/* eslint func-name-matching:0 */
// if we're running in a test runner that supports afterEach
// or teardown then we'll automatically run cleanup afterEach test
// this ensures that tests run in isolation from each other
// if you don't like this then either import the `pure` module
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'.
if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) {
// ignore teardown() in code coverage because Jest does not support it
/* istanbul ignore else */
if (typeof afterEach === 'function') {
afterEach(() => {
cleanup();
});
} else if (typeof teardown === 'function') {
// Block is guarded by `typeof` check.
// eslint does not support `typeof` guards.
// eslint-disable-next-line no-undef
teardown(() => {
cleanup();
});
}
// No test setup with other test runners available
/* istanbul ignore else */
if (typeof beforeAll === 'function' && typeof afterAll === 'function') {
// This matches the behavior of React < 18.
let previousIsReactActEnvironment = getIsReactActEnvironment();
beforeAll(() => {
previousIsReactActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(true);
});
afterAll(() => {
setIsReactActEnvironment(previousIsReactActEnvironment);
});
}
}
export { act, cleanup, configure, fireEvent, getConfig, render, renderHook };
@@ -0,0 +1,496 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
var ReactDOM = require('react-dom');
var ReactDOMClient = require('react-dom/client');
var dom = require('@testing-library/dom');
var DeprecatedReactTestUtils = require('react-dom/test-utils');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
var ReactDOMClient__namespace = /*#__PURE__*/_interopNamespace(ReactDOMClient);
var DeprecatedReactTestUtils__namespace = /*#__PURE__*/_interopNamespace(DeprecatedReactTestUtils);
const reactAct = typeof React__namespace.act === 'function' ? React__namespace.act : DeprecatedReactTestUtils__namespace.act;
function getGlobalThis() {
/* istanbul ignore else */
if (typeof globalThis !== 'undefined') {
return globalThis;
}
/* istanbul ignore next */
if (typeof self !== 'undefined') {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined') {
return window;
}
/* istanbul ignore next */
if (typeof global !== 'undefined') {
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) {
return callback => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(true);
try {
// The return value of `act` is always a thenable.
let callbackNeedsToBeAwaited = false;
const actResult = actImplementation(() => {
const result = callback();
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
callbackNeedsToBeAwaited = true;
}
return result;
});
if (callbackNeedsToBeAwaited) {
const thenable = actResult;
return {
then: (resolve, reject) => {
thenable.then(returnValue => {
setIsReactActEnvironment(previousActEnvironment);
resolve(returnValue);
}, error => {
setIsReactActEnvironment(previousActEnvironment);
reject(error);
});
}
};
} else {
setIsReactActEnvironment(previousActEnvironment);
return actResult;
}
} catch (error) {
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
// or if we have to await the callback first.
setIsReactActEnvironment(previousActEnvironment);
throw error;
}
};
}
const act = withGlobalActEnvironment(reactAct);
/* 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 => {
fireEvent[key] = function () {
return dom.fireEvent[key](...arguments);
};
});
// 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 () {
mouseEnter(...arguments);
return fireEvent.mouseOver(...arguments);
};
fireEvent.mouseLeave = function () {
mouseLeave(...arguments);
return fireEvent.mouseOut(...arguments);
};
const pointerEnter = fireEvent.pointerEnter;
const pointerLeave = fireEvent.pointerLeave;
fireEvent.pointerEnter = function () {
pointerEnter(...arguments);
return fireEvent.pointerOver(...arguments);
};
fireEvent.pointerLeave = function () {
pointerLeave(...arguments);
return fireEvent.pointerOut(...arguments);
};
const select = fireEvent.select;
fireEvent.select = (node, init) => {
select(node, init);
// React tracks this event only on focused inputs
node.focus();
// React creates this event when one of the following native events happens
// - contextMenu
// - mouseUp
// - dragEnd
// - keyUp
// - keyDown
// so we can use any here
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
fireEvent.keyUp(node, init);
};
// 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 () {
fireEvent.focusOut(...arguments);
return blur(...arguments);
};
fireEvent.focus = function () {
fireEvent.focusIn(...arguments);
return focus(...arguments);
};
let configForRTL = {
reactStrictMode: false
};
function getConfig() {
return {
...dom.getConfig(),
...configForRTL
};
}
function configure(newConfig) {
if (typeof newConfig === 'function') {
// Pass the existing config out to the provided function
// and accept a delta in return
newConfig = newConfig(getConfig());
}
const {
reactStrictMode,
...configForDTL
} = newConfig;
dom.configure(configForDTL);
configForRTL = {
...configForRTL,
reactStrictMode
};
}
function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true ||
// modern timers
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
);
} // istanbul ignore next
return false;
}
dom.configure({
unstable_advanceTimersWrapper: cb => {
return act(cb);
},
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
// But that's not necessarily how `asyncWrapper` is used since it's a public method.
// Let's just hope nobody else is using it.
asyncWrapper: async cb => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(false);
try {
const result = await cb();
// Drain microtask queue.
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
// The caller would have no chance to wrap the in-flight Promises in `act()`
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, 0);
if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(0);
}
});
return result;
} finally {
setIsReactActEnvironment(previousActEnvironment);
}
},
eventWrapper: cb => {
let result;
act(() => {
result = cb();
});
return result;
}
});
// 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();
/**
* @type Array<{container: import('react-dom').Container, root: ReturnType<typeof createConcurrentRoot>}>
*/
const mountedRootEntries = [];
function strictModeIfNeeded(innerElement) {
return getConfig().reactStrictMode ? /*#__PURE__*/React__namespace.createElement(React__namespace.StrictMode, null, innerElement) : innerElement;
}
function wrapUiIfNeeded(innerElement, wrapperComponent) {
return wrapperComponent ? /*#__PURE__*/React__namespace.createElement(wrapperComponent, null, innerElement) : innerElement;
}
function createConcurrentRoot(container, _ref) {
let {
hydrate,
ui,
wrapper: WrapperComponent
} = _ref;
let root;
if (hydrate) {
act(() => {
root = ReactDOMClient__namespace.hydrateRoot(container, strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)));
});
} else {
root = ReactDOMClient__namespace.createRoot(container);
}
return {
hydrate() {
/* istanbul ignore if */
if (!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.
},
render(element) {
root.render(element);
},
unmount() {
root.unmount();
}
};
}
function createLegacyRoot(container) {
return {
hydrate(element) {
ReactDOM__default["default"].hydrate(element, container);
},
render(element) {
ReactDOM__default["default"].render(element, container);
},
unmount() {
ReactDOM__default["default"].unmountComponentAtNode(container);
}
};
}
function renderRoot(ui, _ref2) {
let {
baseElement,
container,
hydrate,
queries,
root,
wrapper: WrapperComponent
} = _ref2;
act(() => {
if (hydrate) {
root.hydrate(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
} else {
root.render(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
}
});
return {
container,
baseElement,
debug: function (el, maxLength, options) {
if (el === void 0) {
el = baseElement;
}
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));
},
unmount: () => {
act(() => {
root.unmount();
});
},
rerender: rerenderUi => {
renderRoot(rerenderUi, {
container,
baseElement,
root,
wrapper: WrapperComponent
});
// 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: () => {
/* istanbul ignore else (old jsdom limitation) */
if (typeof document.createRange === 'function') {
return document.createRange().createContextualFragment(container.innerHTML);
} else {
const template = document.createElement('template');
template.innerHTML = container.innerHTML;
return template.content;
}
},
...dom.getQueriesForElement(baseElement, queries)
};
}
function render(ui, _temp) {
let {
container,
baseElement = container,
legacyRoot = false,
queries,
hydrate = false,
wrapper
} = _temp === void 0 ? {} : _temp;
if (legacyRoot && typeof ReactDOM__default["default"].render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, render);
throw error;
}
if (!baseElement) {
// default to document.body instead of documentElement to avoid output of potentially-large
// head elements (such as JSS style blocks) in debug output
baseElement = document.body;
}
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.
if (!mountedContainers.has(container)) {
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
root = createRootImpl(container, {
hydrate,
ui,
wrapper
});
mountedRootEntries.push({
container,
root
});
// 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);
} else {
mountedRootEntries.forEach(rootEntry => {
// Else is unreachable since `mountedContainers` has the `container`.
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries`
/* istanbul ignore else */
if (rootEntry.container === container) {
root = rootEntry.root;
}
});
}
return renderRoot(ui, {
container,
baseElement,
queries,
hydrate,
wrapper,
root
});
}
function cleanup() {
mountedRootEntries.forEach(_ref3 => {
let {
root,
container
} = _ref3;
act(() => {
root.unmount();
});
if (container.parentNode === document.body) {
document.body.removeChild(container);
}
});
mountedRootEntries.length = 0;
mountedContainers.clear();
}
function renderHook(renderCallback, options) {
if (options === void 0) {
options = {};
}
const {
initialProps,
...renderOptions
} = options;
if (renderOptions.legacyRoot && typeof ReactDOM__default["default"].render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, renderHook);
throw error;
}
const result = /*#__PURE__*/React__namespace.createRef();
function TestComponent(_ref4) {
let {
renderCallbackProps
} = _ref4;
const pendingResult = renderCallback(renderCallbackProps);
React__namespace.useEffect(() => {
result.current = pendingResult;
});
return null;
}
const {
rerender: baseRerender,
unmount
} = render( /*#__PURE__*/React__namespace.createElement(TestComponent, {
renderCallbackProps: initialProps
}), renderOptions);
function rerender(rerenderCallbackProps) {
return baseRerender( /*#__PURE__*/React__namespace.createElement(TestComponent, {
renderCallbackProps: rerenderCallbackProps
}));
}
return {
result,
rerender,
unmount
};
}
/* eslint func-name-matching:0 */
exports.act = act;
exports.cleanup = cleanup;
exports.configure = configure;
exports.fireEvent = fireEvent;
exports.getConfig = getConfig;
exports.render = render;
exports.renderHook = renderHook;
Object.keys(dom).forEach(function (k) {
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return dom[k]; }
});
});
@@ -0,0 +1,456 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import { fireEvent as fireEvent$1, getConfig as getConfig$1, configure as configure$1, prettyDOM, getQueriesForElement } from '@testing-library/dom';
export * from '@testing-library/dom';
import * as DeprecatedReactTestUtils from 'react-dom/test-utils';
const reactAct = typeof React.act === 'function' ? React.act : DeprecatedReactTestUtils.act;
function getGlobalThis() {
/* istanbul ignore else */
if (typeof globalThis !== 'undefined') {
return globalThis;
}
/* istanbul ignore next */
if (typeof self !== 'undefined') {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined') {
return window;
}
/* istanbul ignore next */
if (typeof global !== 'undefined') {
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) {
return callback => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(true);
try {
// The return value of `act` is always a thenable.
let callbackNeedsToBeAwaited = false;
const actResult = actImplementation(() => {
const result = callback();
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
callbackNeedsToBeAwaited = true;
}
return result;
});
if (callbackNeedsToBeAwaited) {
const thenable = actResult;
return {
then: (resolve, reject) => {
thenable.then(returnValue => {
setIsReactActEnvironment(previousActEnvironment);
resolve(returnValue);
}, error => {
setIsReactActEnvironment(previousActEnvironment);
reject(error);
});
}
};
} else {
setIsReactActEnvironment(previousActEnvironment);
return actResult;
}
} catch (error) {
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
// or if we have to await the callback first.
setIsReactActEnvironment(previousActEnvironment);
throw error;
}
};
}
const act = withGlobalActEnvironment(reactAct);
/* 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 => {
fireEvent[key] = function () {
return fireEvent$1[key](...arguments);
};
});
// 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 () {
mouseEnter(...arguments);
return fireEvent.mouseOver(...arguments);
};
fireEvent.mouseLeave = function () {
mouseLeave(...arguments);
return fireEvent.mouseOut(...arguments);
};
const pointerEnter = fireEvent.pointerEnter;
const pointerLeave = fireEvent.pointerLeave;
fireEvent.pointerEnter = function () {
pointerEnter(...arguments);
return fireEvent.pointerOver(...arguments);
};
fireEvent.pointerLeave = function () {
pointerLeave(...arguments);
return fireEvent.pointerOut(...arguments);
};
const select = fireEvent.select;
fireEvent.select = (node, init) => {
select(node, init);
// React tracks this event only on focused inputs
node.focus();
// React creates this event when one of the following native events happens
// - contextMenu
// - mouseUp
// - dragEnd
// - keyUp
// - keyDown
// so we can use any here
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
fireEvent.keyUp(node, init);
};
// 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 () {
fireEvent.focusOut(...arguments);
return blur(...arguments);
};
fireEvent.focus = function () {
fireEvent.focusIn(...arguments);
return focus(...arguments);
};
let configForRTL = {
reactStrictMode: false
};
function getConfig() {
return {
...getConfig$1(),
...configForRTL
};
}
function configure(newConfig) {
if (typeof newConfig === 'function') {
// Pass the existing config out to the provided function
// and accept a delta in return
newConfig = newConfig(getConfig());
}
const {
reactStrictMode,
...configForDTL
} = newConfig;
configure$1(configForDTL);
configForRTL = {
...configForRTL,
reactStrictMode
};
}
function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true ||
// modern timers
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
);
} // istanbul ignore next
return false;
}
configure$1({
unstable_advanceTimersWrapper: cb => {
return act(cb);
},
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
// But that's not necessarily how `asyncWrapper` is used since it's a public method.
// Let's just hope nobody else is using it.
asyncWrapper: async cb => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(false);
try {
const result = await cb();
// Drain microtask queue.
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
// The caller would have no chance to wrap the in-flight Promises in `act()`
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, 0);
if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(0);
}
});
return result;
} finally {
setIsReactActEnvironment(previousActEnvironment);
}
},
eventWrapper: cb => {
let result;
act(() => {
result = cb();
});
return result;
}
});
// 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();
/**
* @type Array<{container: import('react-dom').Container, root: ReturnType<typeof createConcurrentRoot>}>
*/
const mountedRootEntries = [];
function strictModeIfNeeded(innerElement) {
return getConfig().reactStrictMode ? /*#__PURE__*/React.createElement(React.StrictMode, null, innerElement) : innerElement;
}
function wrapUiIfNeeded(innerElement, wrapperComponent) {
return wrapperComponent ? /*#__PURE__*/React.createElement(wrapperComponent, null, innerElement) : innerElement;
}
function createConcurrentRoot(container, _ref) {
let {
hydrate,
ui,
wrapper: WrapperComponent
} = _ref;
let root;
if (hydrate) {
act(() => {
root = ReactDOMClient.hydrateRoot(container, strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)));
});
} else {
root = ReactDOMClient.createRoot(container);
}
return {
hydrate() {
/* istanbul ignore if */
if (!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.
},
render(element) {
root.render(element);
},
unmount() {
root.unmount();
}
};
}
function createLegacyRoot(container) {
return {
hydrate(element) {
ReactDOM.hydrate(element, container);
},
render(element) {
ReactDOM.render(element, container);
},
unmount() {
ReactDOM.unmountComponentAtNode(container);
}
};
}
function renderRoot(ui, _ref2) {
let {
baseElement,
container,
hydrate,
queries,
root,
wrapper: WrapperComponent
} = _ref2;
act(() => {
if (hydrate) {
root.hydrate(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
} else {
root.render(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
}
});
return {
container,
baseElement,
debug: function (el, maxLength, options) {
if (el === void 0) {
el = baseElement;
}
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));
},
unmount: () => {
act(() => {
root.unmount();
});
},
rerender: rerenderUi => {
renderRoot(rerenderUi, {
container,
baseElement,
root,
wrapper: WrapperComponent
});
// 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: () => {
/* istanbul ignore else (old jsdom limitation) */
if (typeof document.createRange === 'function') {
return document.createRange().createContextualFragment(container.innerHTML);
} else {
const template = document.createElement('template');
template.innerHTML = container.innerHTML;
return template.content;
}
},
...getQueriesForElement(baseElement, queries)
};
}
function render(ui, _temp) {
let {
container,
baseElement = container,
legacyRoot = false,
queries,
hydrate = false,
wrapper
} = _temp === void 0 ? {} : _temp;
if (legacyRoot && typeof ReactDOM.render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, render);
throw error;
}
if (!baseElement) {
// default to document.body instead of documentElement to avoid output of potentially-large
// head elements (such as JSS style blocks) in debug output
baseElement = document.body;
}
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.
if (!mountedContainers.has(container)) {
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
root = createRootImpl(container, {
hydrate,
ui,
wrapper
});
mountedRootEntries.push({
container,
root
});
// 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);
} else {
mountedRootEntries.forEach(rootEntry => {
// Else is unreachable since `mountedContainers` has the `container`.
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries`
/* istanbul ignore else */
if (rootEntry.container === container) {
root = rootEntry.root;
}
});
}
return renderRoot(ui, {
container,
baseElement,
queries,
hydrate,
wrapper,
root
});
}
function cleanup() {
mountedRootEntries.forEach(_ref3 => {
let {
root,
container
} = _ref3;
act(() => {
root.unmount();
});
if (container.parentNode === document.body) {
document.body.removeChild(container);
}
});
mountedRootEntries.length = 0;
mountedContainers.clear();
}
function renderHook(renderCallback, options) {
if (options === void 0) {
options = {};
}
const {
initialProps,
...renderOptions
} = options;
if (renderOptions.legacyRoot && typeof ReactDOM.render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, renderHook);
throw error;
}
const result = /*#__PURE__*/React.createRef();
function TestComponent(_ref4) {
let {
renderCallbackProps
} = _ref4;
const pendingResult = renderCallback(renderCallbackProps);
React.useEffect(() => {
result.current = pendingResult;
});
return null;
}
const {
rerender: baseRerender,
unmount
} = render( /*#__PURE__*/React.createElement(TestComponent, {
renderCallbackProps: initialProps
}), renderOptions);
function rerender(rerenderCallbackProps) {
return baseRerender( /*#__PURE__*/React.createElement(TestComponent, {
renderCallbackProps: rerenderCallbackProps
}));
}
return {
result,
rerender,
unmount
};
}
/* eslint func-name-matching:0 */
export { act, cleanup, configure, fireEvent, getConfig, render, renderHook };
File diff suppressed because it is too large. Load diff
@@ -0,0 +1 @@
{"version":3,"file":"react.pure.umd.js","sources":["../../node_modules/pretty-format/node_modules/ansi-styles/index.js","../../node_modules/pretty-format/build/collections.js","../../node_modules/pretty-format/build/plugins/AsymmetricMatcher.js","../../node_modules/ansi-regex/index.js","../../node_modules/pretty-format/build/plugins/ConvertAnsi.js","../../node_modules/pretty-format/build/plugins/DOMCollection.js","../../node_modules/pretty-format/build/plugins/lib/escapeHTML.js","../../node_modules/pretty-format/build/plugins/lib/markup.js","../../node_modules/pretty-format/build/plugins/DOMElement.js","../../node_modules/pretty-format/build/plugins/Immutable.js","../../node_modules/react-is/cjs/react-is.development.js","../../node_modules/react-is/index.js","../../node_modules/pretty-format/build/plugins/ReactElement.js","../../node_modules/pretty-format/build/plugins/ReactTestComponent.js","../../node_modules/pretty-format/build/index.js","../../node_modules/dom-accessibility-api/dist/polyfills/array.from.mjs","../../node_modules/dom-accessibility-api/dist/polyfills/SetLike.mjs","../../node_modules/dom-accessibility-api/dist/getRole.mjs","../../node_modules/dom-accessibility-api/dist/util.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name-and-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name.mjs","../../node_modules/aria-query/lib/util/iteratorProxy.js","../../node_modules/aria-query/lib/util/iterationDecorator.js","../../node_modules/aria-query/lib/ariaPropsMap.js","../../node_modules/aria-query/lib/domMap.js","../../node_modules/aria-query/lib/etc/roles/abstract/commandRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/compositeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/inputRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/landmarkRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/rangeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/roletypeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionheadRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/selectRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/structureRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/widgetRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/windowRole.js","../../node_modules/aria-query/lib/etc/roles/ariaAbstractRoles.js","../../node_modules/aria-query/lib/etc/roles/literal/alertRole.js","../../node_modules/aria-query/lib/etc/roles/literal/alertdialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/applicationRole.js","../../node_modules/aria-query/lib/etc/roles/literal/articleRole.js","../../node_modules/aria-query/lib/etc/roles/literal/bannerRole.js","../../node_modules/aria-query/lib/etc/roles/literal/blockquoteRole.js","../../node_modules/aria-query/lib/etc/roles/literal/buttonRole.js","../../node_modules/aria-query/lib/etc/roles/literal/captionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/cellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/checkboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/codeRole.js","../../node_modules/aria-query/lib/etc/roles/literal/columnheaderRole.js","../../node_modules/aria-query/lib/etc/roles/literal/comboboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/complementaryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/contentinfoRole.js","../../node_modules/aria-query/lib/etc/roles/literal/definitionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/deletionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/dialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/directoryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/documentRole.js","../../node_modules/aria-query/lib/etc/roles/literal/emphasisRole.js","../../node_modules/aria-query/lib/etc/roles/literal/feedRole.js","../../node_modules/aria-query/lib/etc/roles/literal/figureRole.js","../../node_modules/aria-query/lib/etc/roles/literal/formRole.js","../../node_modules/aria-query/lib/etc/roles/literal/genericRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridcellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/groupRole.js","../../node_modules/aria-query/lib/etc/roles/literal/headingRole.js","../../node_modules/aria-query/lib/etc/roles/literal/imgRole.js","../../node_modules/aria-query/lib/etc/roles/literal/insertionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/linkRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listitemRole.js","../..Line truncated
@@ -0,0 +1,2 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom"),require("react-dom/client"),require("react-dom/test-utils")):"function"==typeof define&&define.amd?define(["exports","react","react-dom","react-dom/client","react-dom/test-utils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TestingLibraryReact={},e.React,e.ReactDOM,e.ReactDOMClient,e.ReactTestUtils)}(this,(function(e,t,r,n,a){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}function i(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(r){if("default"!==r&&!(r in e)){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}}))})),Object.freeze(e)}var u=l(t),s=o(r),d=l(n),c=l(a),p={},m={exports:{}};!function(e){const t=function(e){return void 0===e&&(e=0),t=>`[${38+e};5;${t}m`},r=function(e){return void 0===e&&(e=0),(t,r,n)=>`[${38+e};2;${t};${r};${n}m`};Object.defineProperty(e,"exports",{enumerable:!0,get:function(){const e=new Map,n={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};n.color.gray=n.color.blackBright,n.bgColor.bgGray=n.bgColor.bgBlackBright,n.color.grey=n.color.blackBright,n.bgColor.bgGrey=n.bgColor.bgBlackBright;for(const[t,r]of Object.entries(n)){for(const[t,a]of Object.entries(r))n[t]={open:`[${a[0]}m`,close:`[${a[1]}m`},r[t]=n[t],e.set(a[0],a[1]);Object.defineProperty(n,t,{value:r,enumerable:!1})}return Object.defineProperty(n,"codes",{value:e,enumerable:!1}),n.color.close="",n.bgColor.close="",n.color.ansi256=t(),n.color.ansi16m=r(),n.bgColor.ansi256=t(10),n.bgColor.ansi16m=r(10),Object.defineProperties(n,{rgbToAnsi256:{value:(e,t,r)=>e===t&&t===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(r/255*5),enumerable:!1},hexToRgb:{value:e=>{const t=/(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(e.toString(16));if(!t)return[0,0,0];let{colorString:r}=t.groups;3===r.length&&(r=r.split("").map((e=>e+e)).join(""));const n=Number.parseInt(r,16);return[n>>16&255,n>>8&255,255&n]},enumerable:!1},hexToAnsi256:{value:e=>n.rgbToAnsi256(...n.hexToRgb(e)),enumerable:!1}}),n}})}(m);var f={};Object.defineProperty(f,"__esModule",{value:!0}),f.printIteratorEntries=function(e,t,r,n,a,o,l){void 0===l&&(l=": ");let i="",u=e.next();if(!u.done){i+=t.spacingOuter;const s=r+t.indent;for(;!u.done;){i+=s+o(u.value[0],t,s,n,a)+l+o(u.value[1],t,s,n,a),u=e.next(),u.done?t.min||(i+=","):i+=","+t.spacingInner}i+=t.spacingOuter+r}return i},f.printIteratorValues=function(e,t,r,n,a,o){let l="",i=e.next();if(!i.done){l+=t.spacingOuter;const u=r+t.indent;for(;!i.done;)l+=u+o(i.value,t,u,n,a),i=e.next(),i.done?t.min||(l+=","):l+=","+t.spacingInner;l+=t.spacingOuter+r}return l},f.printListItems=function(e,t,r,n,a,o){let l="";if(e.length){l+=t.spacingOuter;const i=r+t.indent;for(let r=0;r<e.length;r++)l+=i,r in e&&(l+=o(e[r],t,i,n,a)),r<e.length-1?l+=","+t.spacingInner:t.min||(l+=",");l+=t.spacingOuter+r}return l},f.printObjectProperties=function(e,t,r,n,a,o){let l="";const i=b(e,t.compareKeys);if(i.length){l+=t.spacingOuter;const u=r+t.indent;for(let r=0;r<i.length;r++){const s=i[r];l+=u+o(s,t,u,n,a)+": "+o(e[s],t,u,n,a),r<i.length-1?l+=","+t.spacingInner:t.min||(l+=",")}l+=t.spacingOuter+r}return l};const b=(e,t)=>{const r=Object.keys(e).sort(t);return Object.getOwnPropertySymbols&&Object.getOwnPropertySymbols(e).forEach((t=>{Object.getOwnPropertyDescriptor(e,t).enumerable&&r.push(t)})),r};var v={};Object.defineProperty(v,"__esModule",{value:!0}),v.test=v.serialize=v.default=void 0;var y=f,h="undefined"!=typeof globalThis?globalThis:void 0!==h?h:"undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")(),g=h["jest-symbol-do-not-touch"]||h.Symbol;const C="function"==typeof g&&g.for?g.for("jest.asymmetricMatcher"):1267621,q=" ",P=(e,t,r,n,a,o)=>{const l=e.toString();return"ArrayContaiLine truncated
//# sourceMappingURL=react.pure.umd.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"react.pure.umd.min.js","sources":["../../node_modules/pretty-format/node_modules/ansi-styles/index.js","../../node_modules/pretty-format/build/collections.js","../../node_modules/pretty-format/build/plugins/AsymmetricMatcher.js","../../node_modules/pretty-format/build/plugins/ConvertAnsi.js","../../node_modules/ansi-regex/index.js","../../node_modules/pretty-format/build/plugins/DOMCollection.js","../../node_modules/pretty-format/build/plugins/lib/escapeHTML.js","../../node_modules/pretty-format/build/plugins/lib/markup.js","../../node_modules/pretty-format/build/plugins/DOMElement.js","../../node_modules/pretty-format/build/plugins/Immutable.js","../../node_modules/react-is/index.js","../../node_modules/react-is/cjs/react-is.production.min.js","../../node_modules/pretty-format/build/plugins/ReactElement.js","../../node_modules/pretty-format/build/plugins/ReactTestComponent.js","../../node_modules/pretty-format/build/index.js","../../node_modules/dom-accessibility-api/dist/polyfills/array.from.mjs","../../node_modules/dom-accessibility-api/dist/polyfills/SetLike.mjs","../../node_modules/dom-accessibility-api/dist/getRole.mjs","../../node_modules/dom-accessibility-api/dist/util.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name-and-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name.mjs","../../node_modules/aria-query/lib/util/iteratorProxy.js","../../node_modules/aria-query/lib/util/iterationDecorator.js","../../node_modules/aria-query/lib/ariaPropsMap.js","../../node_modules/aria-query/lib/domMap.js","../../node_modules/aria-query/lib/etc/roles/abstract/commandRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/compositeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/inputRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/landmarkRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/rangeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/roletypeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionheadRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/selectRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/structureRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/widgetRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/windowRole.js","../../node_modules/aria-query/lib/etc/roles/ariaAbstractRoles.js","../../node_modules/aria-query/lib/etc/roles/literal/alertRole.js","../../node_modules/aria-query/lib/etc/roles/literal/alertdialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/applicationRole.js","../../node_modules/aria-query/lib/etc/roles/literal/articleRole.js","../../node_modules/aria-query/lib/etc/roles/literal/bannerRole.js","../../node_modules/aria-query/lib/etc/roles/literal/blockquoteRole.js","../../node_modules/aria-query/lib/etc/roles/literal/buttonRole.js","../../node_modules/aria-query/lib/etc/roles/literal/captionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/cellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/checkboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/codeRole.js","../../node_modules/aria-query/lib/etc/roles/literal/columnheaderRole.js","../../node_modules/aria-query/lib/etc/roles/literal/comboboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/complementaryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/contentinfoRole.js","../../node_modules/aria-query/lib/etc/roles/literal/definitionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/deletionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/dialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/directoryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/documentRole.js","../../node_modules/aria-query/lib/etc/roles/literal/emphasisRole.js","../../node_modules/aria-query/lib/etc/roles/literal/feedRole.js","../../node_modules/aria-query/lib/etc/roles/literal/figureRole.js","../../node_modules/aria-query/lib/etc/roles/literal/formRole.js","../../node_modules/aria-query/lib/etc/roles/literal/genericRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridcellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/groupRole.js","../../node_modules/aria-query/lib/etc/roles/literal/headingRole.js","../../node_modules/aria-query/lib/etc/roles/literal/imgRole.js","../../node_modules/aria-query/lib/etc/roles/literal/insertionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/linkRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listitemRole.js"Line truncated
File diff suppressed because it is too large. Load diff
@@ -0,0 +1 @@
{"version":3,"file":"react.umd.js","sources":["../../src/act-compat.js","../../node_modules/pretty-format/node_modules/ansi-styles/index.js","../../node_modules/pretty-format/build/collections.js","../../node_modules/pretty-format/build/plugins/AsymmetricMatcher.js","../../node_modules/ansi-regex/index.js","../../node_modules/pretty-format/build/plugins/ConvertAnsi.js","../../node_modules/pretty-format/build/plugins/DOMCollection.js","../../node_modules/pretty-format/build/plugins/lib/escapeHTML.js","../../node_modules/pretty-format/build/plugins/lib/markup.js","../../node_modules/pretty-format/build/plugins/DOMElement.js","../../node_modules/pretty-format/build/plugins/Immutable.js","../../node_modules/react-is/cjs/react-is.development.js","../../node_modules/react-is/index.js","../../node_modules/pretty-format/build/plugins/ReactElement.js","../../node_modules/pretty-format/build/plugins/ReactTestComponent.js","../../node_modules/pretty-format/build/index.js","../../node_modules/dom-accessibility-api/dist/polyfills/array.from.mjs","../../node_modules/dom-accessibility-api/dist/polyfills/SetLike.mjs","../../node_modules/dom-accessibility-api/dist/getRole.mjs","../../node_modules/dom-accessibility-api/dist/util.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name-and-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name.mjs","../../node_modules/aria-query/lib/util/iteratorProxy.js","../../node_modules/aria-query/lib/util/iterationDecorator.js","../../node_modules/aria-query/lib/ariaPropsMap.js","../../node_modules/aria-query/lib/domMap.js","../../node_modules/aria-query/lib/etc/roles/abstract/commandRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/compositeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/inputRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/landmarkRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/rangeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/roletypeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionheadRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/selectRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/structureRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/widgetRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/windowRole.js","../../node_modules/aria-query/lib/etc/roles/ariaAbstractRoles.js","../../node_modules/aria-query/lib/etc/roles/literal/alertRole.js","../../node_modules/aria-query/lib/etc/roles/literal/alertdialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/applicationRole.js","../../node_modules/aria-query/lib/etc/roles/literal/articleRole.js","../../node_modules/aria-query/lib/etc/roles/literal/bannerRole.js","../../node_modules/aria-query/lib/etc/roles/literal/blockquoteRole.js","../../node_modules/aria-query/lib/etc/roles/literal/buttonRole.js","../../node_modules/aria-query/lib/etc/roles/literal/captionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/cellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/checkboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/codeRole.js","../../node_modules/aria-query/lib/etc/roles/literal/columnheaderRole.js","../../node_modules/aria-query/lib/etc/roles/literal/comboboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/complementaryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/contentinfoRole.js","../../node_modules/aria-query/lib/etc/roles/literal/definitionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/deletionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/dialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/directoryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/documentRole.js","../../node_modules/aria-query/lib/etc/roles/literal/emphasisRole.js","../../node_modules/aria-query/lib/etc/roles/literal/feedRole.js","../../node_modules/aria-query/lib/etc/roles/literal/figureRole.js","../../node_modules/aria-query/lib/etc/roles/literal/formRole.js","../../node_modules/aria-query/lib/etc/roles/literal/genericRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridcellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/groupRole.js","../../node_modules/aria-query/lib/etc/roles/literal/headingRole.js","../../node_modules/aria-query/lib/etc/roles/literal/imgRole.js","../../node_modules/aria-query/lib/etc/roles/literal/insertionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/linkRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/liLine truncated
@@ -0,0 +1,2 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom/test-utils"),require("react-dom"),require("react-dom/client")):"function"==typeof define&&define.amd?define(["exports","react","react-dom/test-utils","react-dom","react-dom/client"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TestingLibraryReact={},e.React,e.ReactTestUtils,e.ReactDOM,e.ReactDOMClient)}(this,(function(e,t,r,n,a){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}function i(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(r){if("default"!==r&&!(r in e)){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}}))})),Object.freeze(e)}var u=l(t),s=l(r),d=o(n),c=l(a);const p="function"==typeof u.act?u.act:s.act;function m(){if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}function f(e){m().IS_REACT_ACT_ENVIRONMENT=e}function b(){return m().IS_REACT_ACT_ENVIRONMENT}const v=(y=p,e=>{const t=b();f(!0);try{let r=!1;const n=y((()=>{const t=e();return null!==t&&"object"==typeof t&&"function"==typeof t.then&&(r=!0),t}));return r?{then:(e,r)=>{n.then((r=>{f(t),e(r)}),(e=>{f(t),r(e)}))}}:(f(t),n)}catch(e){throw f(t),e}});var y,h={},g={exports:{}};!function(e){const t=function(e){return void 0===e&&(e=0),t=>`[${38+e};5;${t}m`},r=function(e){return void 0===e&&(e=0),(t,r,n)=>`[${38+e};2;${t};${r};${n}m`};Object.defineProperty(e,"exports",{enumerable:!0,get:function(){const e=new Map,n={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};n.color.gray=n.color.blackBright,n.bgColor.bgGray=n.bgColor.bgBlackBright,n.color.grey=n.color.blackBright,n.bgColor.bgGrey=n.bgColor.bgBlackBright;for(const[t,r]of Object.entries(n)){for(const[t,a]of Object.entries(r))n[t]={open:`[${a[0]}m`,close:`[${a[1]}m`},r[t]=n[t],e.set(a[0],a[1]);Object.defineProperty(n,t,{value:r,enumerable:!1})}return Object.defineProperty(n,"codes",{value:e,enumerable:!1}),n.color.close="",n.bgColor.close="",n.color.ansi256=t(),n.color.ansi16m=r(),n.bgColor.ansi256=t(10),n.bgColor.ansi16m=r(10),Object.defineProperties(n,{rgbToAnsi256:{value:(e,t,r)=>e===t&&t===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(r/255*5),enumerable:!1},hexToRgb:{value:e=>{const t=/(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(e.toString(16));if(!t)return[0,0,0];let{colorString:r}=t.groups;3===r.length&&(r=r.split("").map((e=>e+e)).join(""));const n=Number.parseInt(r,16);return[n>>16&255,n>>8&255,255&n]},enumerable:!1},hexToAnsi256:{value:e=>n.rgbToAnsi256(...n.hexToRgb(e)),enumerable:!1}}),n}})}(g);var C={};Object.defineProperty(C,"__esModule",{value:!0}),C.printIteratorEntries=function(e,t,r,n,a,o,l){void 0===l&&(l=": ");let i="",u=e.next();if(!u.done){i+=t.spacingOuter;const s=r+t.indent;for(;!u.done;){i+=s+o(u.value[0],t,s,n,a)+l+o(u.value[1],t,s,n,a),u=e.next(),u.done?t.min||(i+=","):i+=","+t.spacingInner}i+=t.spacingOuter+r}return i},C.printIteratorValues=function(e,t,r,n,a,o){let l="",i=e.next();if(!i.done){l+=t.spacingOuter;const u=r+t.indent;for(;!i.done;)l+=u+o(i.value,t,u,n,a),i=e.next(),i.done?t.min||(l+=","):l+=","+t.spacingInner;l+=t.spacingOuter+r}return l},C.printListItems=function(e,t,r,n,a,o){let l="";if(e.length){l+=t.spacingOuter;const i=r+t.indent;for(let r=0;r<e.length;r++)l+=i,r in e&&(l+=o(e[r],t,i,n,a)),r<e.length-1?l+=","+t.spacingInner:t.min||(l+=",");l+=t.spacingOuter+r}return l},C.printObjectProperties=function(e,t,r,n,a,o){let l="";const i=P(e,t.compareKeys);if(i.length){l+=t.spacingOuter;const u=r+t.indent;for(let r=0;r<i.length;r++){const s=i[r];l+=u+o(s,t,u,n,a)+": "+o(e[s],t,u,n,a),r<i.length-1?l+=","+t.spacingInner:t.min||(l+=",")}l+=t.spacingOLine truncated
//# sourceMappingURL=react.umd.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"react.umd.min.js","sources":["../../src/act-compat.js","../../node_modules/pretty-format/node_modules/ansi-styles/index.js","../../node_modules/pretty-format/build/collections.js","../../node_modules/pretty-format/build/plugins/AsymmetricMatcher.js","../../node_modules/pretty-format/build/plugins/ConvertAnsi.js","../../node_modules/ansi-regex/index.js","../../node_modules/pretty-format/build/plugins/DOMCollection.js","../../node_modules/pretty-format/build/plugins/lib/escapeHTML.js","../../node_modules/pretty-format/build/plugins/lib/markup.js","../../node_modules/pretty-format/build/plugins/DOMElement.js","../../node_modules/pretty-format/build/plugins/Immutable.js","../../node_modules/react-is/index.js","../../node_modules/react-is/cjs/react-is.production.min.js","../../node_modules/pretty-format/build/plugins/ReactElement.js","../../node_modules/pretty-format/build/plugins/ReactTestComponent.js","../../node_modules/pretty-format/build/index.js","../../node_modules/dom-accessibility-api/dist/polyfills/array.from.mjs","../../node_modules/dom-accessibility-api/dist/polyfills/SetLike.mjs","../../node_modules/dom-accessibility-api/dist/getRole.mjs","../../node_modules/dom-accessibility-api/dist/util.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name-and-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-description.mjs","../../node_modules/dom-accessibility-api/dist/accessible-name.mjs","../../node_modules/aria-query/lib/util/iteratorProxy.js","../../node_modules/aria-query/lib/util/iterationDecorator.js","../../node_modules/aria-query/lib/ariaPropsMap.js","../../node_modules/aria-query/lib/domMap.js","../../node_modules/aria-query/lib/etc/roles/abstract/commandRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/compositeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/inputRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/landmarkRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/rangeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/roletypeRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/sectionheadRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/selectRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/structureRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/widgetRole.js","../../node_modules/aria-query/lib/etc/roles/abstract/windowRole.js","../../node_modules/aria-query/lib/etc/roles/ariaAbstractRoles.js","../../node_modules/aria-query/lib/etc/roles/literal/alertRole.js","../../node_modules/aria-query/lib/etc/roles/literal/alertdialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/applicationRole.js","../../node_modules/aria-query/lib/etc/roles/literal/articleRole.js","../../node_modules/aria-query/lib/etc/roles/literal/bannerRole.js","../../node_modules/aria-query/lib/etc/roles/literal/blockquoteRole.js","../../node_modules/aria-query/lib/etc/roles/literal/buttonRole.js","../../node_modules/aria-query/lib/etc/roles/literal/captionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/cellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/checkboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/codeRole.js","../../node_modules/aria-query/lib/etc/roles/literal/columnheaderRole.js","../../node_modules/aria-query/lib/etc/roles/literal/comboboxRole.js","../../node_modules/aria-query/lib/etc/roles/literal/complementaryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/contentinfoRole.js","../../node_modules/aria-query/lib/etc/roles/literal/definitionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/deletionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/dialogRole.js","../../node_modules/aria-query/lib/etc/roles/literal/directoryRole.js","../../node_modules/aria-query/lib/etc/roles/literal/documentRole.js","../../node_modules/aria-query/lib/etc/roles/literal/emphasisRole.js","../../node_modules/aria-query/lib/etc/roles/literal/feedRole.js","../../node_modules/aria-query/lib/etc/roles/literal/figureRole.js","../../node_modules/aria-query/lib/etc/roles/literal/formRole.js","../../node_modules/aria-query/lib/etc/roles/literal/genericRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridRole.js","../../node_modules/aria-query/lib/etc/roles/literal/gridcellRole.js","../../node_modules/aria-query/lib/etc/roles/literal/groupRole.js","../../node_modules/aria-query/lib/etc/roles/literal/headingRole.js","../../node_modules/aria-query/lib/etc/roles/literal/imgRole.js","../../node_modules/aria-query/lib/etc/roles/literal/insertionRole.js","../../node_modules/aria-query/lib/etc/roles/literal/linkRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listRole.js","../../node_modules/aria-query/lib/etc/roles/literal/listboxRole.js","../../node_modules/aria-query/lib/etc/roles/litLine truncated
+81
View File
@@ -0,0 +1,81 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.getIsReactActEnvironment = getIsReactActEnvironment;
exports.setReactActEnvironment = setIsReactActEnvironment;
var React = _interopRequireWildcard(require("react"));
var DeprecatedReactTestUtils = _interopRequireWildcard(require("react-dom/test-utils"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const reactAct = typeof React.act === 'function' ? React.act : DeprecatedReactTestUtils.act;
function getGlobalThis() {
/* istanbul ignore else */
if (typeof globalThis !== 'undefined') {
return globalThis;
}
/* istanbul ignore next */
if (typeof self !== 'undefined') {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined') {
return window;
}
/* istanbul ignore next */
if (typeof global !== 'undefined') {
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) {
return callback => {
const previousActEnvironment = getIsReactActEnvironment();
setIsReactActEnvironment(true);
try {
// The return value of `act` is always a thenable.
let callbackNeedsToBeAwaited = false;
const actResult = actImplementation(() => {
const result = callback();
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
callbackNeedsToBeAwaited = true;
}
return result;
});
if (callbackNeedsToBeAwaited) {
const thenable = actResult;
return {
then: (resolve, reject) => {
thenable.then(returnValue => {
setIsReactActEnvironment(previousActEnvironment);
resolve(returnValue);
}, error => {
setIsReactActEnvironment(previousActEnvironment);
reject(error);
});
}
};
} else {
setIsReactActEnvironment(previousActEnvironment);
return actResult;
}
} catch (error) {
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
// or if we have to await the callback first.
setIsReactActEnvironment(previousActEnvironment);
throw error;
}
};
}
const act = withGlobalActEnvironment(reactAct);
var _default = exports.default = act;
/* eslint no-console:0 */
+33
View File
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.configure = configure;
exports.getConfig = getConfig;
var _dom = require("@testing-library/dom");
let configForRTL = {
reactStrictMode: false
};
function getConfig() {
return {
...(0, _dom.getConfig)(),
...configForRTL
};
}
function configure(newConfig) {
if (typeof newConfig === 'function') {
// Pass the existing config out to the provided function
// and accept a delta in return
newConfig = newConfig(getConfig());
}
const {
reactStrictMode,
...configForDTL
} = newConfig;
(0, _dom.configure)(configForDTL);
configForRTL = {
...configForRTL,
reactStrictMode
};
}
+70
View File
@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fireEvent = void 0;
var _dom = require("@testing-library/dom");
// 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 = (...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
// 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) => {
mouseEnter(...args);
return fireEvent.mouseOver(...args);
};
fireEvent.mouseLeave = (...args) => {
mouseLeave(...args);
return fireEvent.mouseOut(...args);
};
const pointerEnter = fireEvent.pointerEnter;
const pointerLeave = fireEvent.pointerLeave;
fireEvent.pointerEnter = (...args) => {
pointerEnter(...args);
return fireEvent.pointerOver(...args);
};
fireEvent.pointerLeave = (...args) => {
pointerLeave(...args);
return fireEvent.pointerOut(...args);
};
const select = fireEvent.select;
fireEvent.select = (node, init) => {
select(node, init);
// React tracks this event only on focused inputs
node.focus();
// React creates this event when one of the following native events happens
// - contextMenu
// - mouseUp
// - dragEnd
// - keyUp
// - keyDown
// so we can use any here
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
fireEvent.keyUp(node, init);
};
// 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) => {
fireEvent.focusOut(...args);
return blur(...args);
};
fireEvent.focus = (...args) => {
fireEvent.focusIn(...args);
return focus(...args);
};
+52
View File
@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _actCompat = require("./act-compat");
var _pure = require("./pure");
Object.keys(_pure).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _pure[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _pure[key];
}
});
});
// if we're running in a test runner that supports afterEach
// or teardown then we'll automatically run cleanup afterEach test
// this ensures that tests run in isolation from each other
// if you don't like this then either import the `pure` module
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'.
if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) {
// ignore teardown() in code coverage because Jest does not support it
/* istanbul ignore else */
if (typeof afterEach === 'function') {
afterEach(() => {
(0, _pure.cleanup)();
});
} else if (typeof teardown === 'function') {
// Block is guarded by `typeof` check.
// eslint does not support `typeof` guards.
// eslint-disable-next-line no-undef
teardown(() => {
(0, _pure.cleanup)();
});
}
// No test setup with other test runners available
/* istanbul ignore else */
if (typeof beforeAll === 'function' && typeof afterAll === 'function') {
// This matches the behavior of React < 18.
let previousIsReactActEnvironment = (0, _actCompat.getIsReactActEnvironment)();
beforeAll(() => {
previousIsReactActEnvironment = (0, _actCompat.getIsReactActEnvironment)();
(0, _actCompat.setReactActEnvironment)(true);
});
afterAll(() => {
(0, _actCompat.setReactActEnvironment)(previousIsReactActEnvironment);
});
}
}
+335
View File
@@ -0,0 +1,335 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
render: true,
renderHook: true,
cleanup: true,
act: true,
fireEvent: true,
getConfig: true,
configure: true
};
Object.defineProperty(exports, "act", {
enumerable: true,
get: function () {
return _actCompat.default;
}
});
exports.cleanup = cleanup;
Object.defineProperty(exports, "configure", {
enumerable: true,
get: function () {
return _config.configure;
}
});
Object.defineProperty(exports, "fireEvent", {
enumerable: true,
get: function () {
return _fireEvent.fireEvent;
}
});
Object.defineProperty(exports, "getConfig", {
enumerable: true,
get: function () {
return _config.getConfig;
}
});
exports.render = render;
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) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _dom[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _dom[key];
}
});
});
var _actCompat = _interopRequireWildcard(require("./act-compat"));
var _fireEvent = require("./fire-event");
var _config = require("./config");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true ||
// modern timers
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
);
} // istanbul ignore next
return false;
}
(0, _dom.configure)({
unstable_advanceTimersWrapper: cb => {
return (0, _actCompat.default)(cb);
},
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
// But that's not necessarily how `asyncWrapper` is used since it's a public method.
// Let's just hope nobody else is using it.
asyncWrapper: async cb => {
const previousActEnvironment = (0, _actCompat.getIsReactActEnvironment)();
(0, _actCompat.setReactActEnvironment)(false);
try {
const result = await cb();
// Drain microtask queue.
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
// The caller would have no chance to wrap the in-flight Promises in `act()`
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, 0);
if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(0);
}
});
return result;
} finally {
(0, _actCompat.setReactActEnvironment)(previousActEnvironment);
}
},
eventWrapper: cb => {
let result;
(0, _actCompat.default)(() => {
result = cb();
});
return result;
}
});
// 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();
/**
* @type Array<{container: import('react-dom').Container, root: ReturnType<typeof createConcurrentRoot>}>
*/
const mountedRootEntries = [];
function strictModeIfNeeded(innerElement) {
return (0, _config.getConfig)().reactStrictMode ? /*#__PURE__*/React.createElement(React.StrictMode, null, innerElement) : innerElement;
}
function wrapUiIfNeeded(innerElement, wrapperComponent) {
return wrapperComponent ? /*#__PURE__*/React.createElement(wrapperComponent, null, innerElement) : innerElement;
}
function createConcurrentRoot(container, {
hydrate,
ui,
wrapper: WrapperComponent
}) {
let root;
if (hydrate) {
(0, _actCompat.default)(() => {
root = ReactDOMClient.hydrateRoot(container, strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)));
});
} else {
root = ReactDOMClient.createRoot(container);
}
return {
hydrate() {
/* istanbul ignore if */
if (!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.
},
render(element) {
root.render(element);
},
unmount() {
root.unmount();
}
};
}
function createLegacyRoot(container) {
return {
hydrate(element) {
_reactDom.default.hydrate(element, container);
},
render(element) {
_reactDom.default.render(element, container);
},
unmount() {
_reactDom.default.unmountComponentAtNode(container);
}
};
}
function renderRoot(ui, {
baseElement,
container,
hydrate,
queries,
root,
wrapper: WrapperComponent
}) {
(0, _actCompat.default)(() => {
if (hydrate) {
root.hydrate(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
} else {
root.render(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent)), container);
}
});
return {
container,
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,
console.log((0, _dom.prettyDOM)(el, maxLength, options)),
unmount: () => {
(0, _actCompat.default)(() => {
root.unmount();
});
},
rerender: rerenderUi => {
renderRoot(rerenderUi, {
container,
baseElement,
root,
wrapper: WrapperComponent
});
// 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: () => {
/* istanbul ignore else (old jsdom limitation) */
if (typeof document.createRange === 'function') {
return document.createRange().createContextualFragment(container.innerHTML);
} else {
const template = document.createElement('template');
template.innerHTML = container.innerHTML;
return template.content;
}
},
...(0, _dom.getQueriesForElement)(baseElement, queries)
};
}
function render(ui, {
container,
baseElement = container,
legacyRoot = false,
queries,
hydrate = false,
wrapper
} = {}) {
if (legacyRoot && typeof _reactDom.default.render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, render);
throw error;
}
if (!baseElement) {
// default to document.body instead of documentElement to avoid output of potentially-large
// head elements (such as JSS style blocks) in debug output
baseElement = document.body;
}
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.
if (!mountedContainers.has(container)) {
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
root = createRootImpl(container, {
hydrate,
ui,
wrapper
});
mountedRootEntries.push({
container,
root
});
// 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);
} else {
mountedRootEntries.forEach(rootEntry => {
// Else is unreachable since `mountedContainers` has the `container`.
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries`
/* istanbul ignore else */
if (rootEntry.container === container) {
root = rootEntry.root;
}
});
}
return renderRoot(ui, {
container,
baseElement,
queries,
hydrate,
wrapper,
root
});
}
function cleanup() {
mountedRootEntries.forEach(({
root,
container
}) => {
(0, _actCompat.default)(() => {
root.unmount();
});
if (container.parentNode === document.body) {
document.body.removeChild(container);
}
});
mountedRootEntries.length = 0;
mountedContainers.clear();
}
function renderHook(renderCallback, options = {}) {
const {
initialProps,
...renderOptions
} = options;
if (renderOptions.legacyRoot && typeof _reactDom.default.render !== 'function') {
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
Error.captureStackTrace(error, renderHook);
throw error;
}
const result = /*#__PURE__*/React.createRef();
function TestComponent({
renderCallbackProps
}) {
const pendingResult = renderCallback(renderCallbackProps);
React.useEffect(() => {
result.current = pendingResult;
});
return null;
}
const {
rerender: baseRerender,
unmount
} = render( /*#__PURE__*/React.createElement(TestComponent, {
renderCallbackProps: initialProps
}), renderOptions);
function rerender(rerenderCallbackProps) {
return baseRerender( /*#__PURE__*/React.createElement(TestComponent, {
renderCallbackProps: rerenderCallbackProps
}));
}
return {
result,
rerender,
unmount
};
}
// just re-export everything from dom-testing-library
/* eslint func-name-matching:0 */