@testing-library/react
Advanced tools
Comparing version 13.0.0-alpha.1 to 13.0.0-alpha.3
@@ -24,5 +24,3 @@ 'use strict'; | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
get: function () { return e[k]; } | ||
}); | ||
@@ -32,3 +30,3 @@ } | ||
} | ||
n['default'] = e; | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
@@ -52,7 +50,82 @@ } | ||
function actPolyfill(cb) { | ||
ReactDOM__default['default'].unstable_batchedUpdates(cb); | ||
ReactDOM__default['default'].render( /*#__PURE__*/React__namespace.createElement("div", null), document.createElement('div')); | ||
ReactDOM__default["default"].unstable_batchedUpdates(cb); | ||
ReactDOM__default["default"].render( /*#__PURE__*/React__namespace.createElement("div", null), document.createElement('div')); | ||
} | ||
var act = isomorphicAct || domAct || actPolyfill; | ||
function getGlobalThis() { | ||
/* istanbul ignore else */ | ||
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 setReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
return function (callback) { | ||
var previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(true); | ||
try { | ||
// The return value of `act` is always a thenable. | ||
var callbackNeedsToBeAwaited = false; | ||
var actResult = actImplementation(function () { | ||
var result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
var thenable = actResult; | ||
return { | ||
then: function then(resolve, reject) { | ||
thenable.then(function (returnValue) { | ||
setReactActEnvironment(previousActEnvironment); | ||
resolve(returnValue); | ||
}, function (error) { | ||
setReactActEnvironment(previousActEnvironment); | ||
reject(error); | ||
}); | ||
} | ||
}; | ||
} else { | ||
setReactActEnvironment(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. | ||
setReactActEnvironment(previousActEnvironment); | ||
throw error; | ||
} | ||
}; | ||
} | ||
var act = withGlobalActEnvironment(isomorphicAct || domAct || actPolyfill); | ||
var youHaveBeenWarned = false; | ||
@@ -243,5 +316,5 @@ var isAsyncActSupported = null; | ||
asyncWrapper: function () { | ||
var _asyncWrapper = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(cb) { | ||
var _asyncWrapper = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(cb) { | ||
var result; | ||
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) { | ||
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
@@ -251,4 +324,4 @@ switch (_context2.prev = _context2.next) { | ||
_context2.next = 2; | ||
return asyncAct( /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() { | ||
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) { | ||
return asyncAct( /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() { | ||
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
@@ -302,5 +375,40 @@ switch (_context.prev = _context.next) { | ||
}, | ||
asyncWrapper: function asyncWrapper(cb) { | ||
return 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: function () { | ||
var _asyncWrapper2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(cb) { | ||
var previousActEnvironment; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(false); | ||
_context3.prev = 2; | ||
_context3.next = 5; | ||
return cb(); | ||
case 5: | ||
return _context3.abrupt("return", _context3.sent); | ||
case 6: | ||
_context3.prev = 6; | ||
setReactActEnvironment(previousActEnvironment); | ||
return _context3.finish(6); | ||
case 9: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, null, [[2,, 6, 9]]); | ||
})); | ||
function asyncWrapper(_x2) { | ||
return _asyncWrapper2.apply(this, arguments); | ||
} | ||
return asyncWrapper; | ||
}() | ||
}); | ||
@@ -323,7 +431,7 @@ } // Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
function createConcurrentRoot(container, options) { | ||
if (typeof ReactDOM__default['default'].createRoot !== 'function') { | ||
throw new TypeError("Attempted to use concurrent React with `react-dom@" + ReactDOM__default['default'].version + "`. Be sure to use the `next` or `experimental` release channel (https://reactjs.org/docs/release-channels.html).'"); | ||
if (typeof ReactDOM__default["default"].createRoot !== 'function') { | ||
throw new TypeError("Attempted to use concurrent React with `react-dom@" + ReactDOM__default["default"].version + "`. Be sure to use the `next` or `experimental` release channel (https://reactjs.org/docs/release-channels.html).'"); | ||
} | ||
var root = options.hydrate ? ReactDOM__default['default'].hydrateRoot(container) : ReactDOM__default['default'].createRoot(container); | ||
var root = options.hydrate ? ReactDOM__default["default"].hydrateRoot(container) : ReactDOM__default["default"].createRoot(container); | ||
return { | ||
@@ -350,9 +458,9 @@ hydrate: function hydrate(element) { | ||
hydrate: function hydrate(element) { | ||
ReactDOM__default['default'].hydrate(element, container); | ||
ReactDOM__default["default"].hydrate(element, container); | ||
}, | ||
render: function render(element) { | ||
ReactDOM__default['default'].render(element, container); | ||
ReactDOM__default["default"].render(element, container); | ||
}, | ||
unmount: function unmount() { | ||
ReactDOM__default['default'].unmountComponentAtNode(container); | ||
ReactDOM__default["default"].unmountComponentAtNode(container); | ||
} | ||
@@ -381,3 +489,3 @@ }; | ||
}); | ||
return _extends__default['default']({ | ||
return _extends__default["default"]({ | ||
container: container, | ||
@@ -428,3 +536,3 @@ baseElement: baseElement, | ||
_ref3$legacyRoot = _ref3.legacyRoot, | ||
legacyRoot = _ref3$legacyRoot === void 0 ? typeof ReactDOM__default['default'].createRoot !== 'function' : _ref3$legacyRoot, | ||
legacyRoot = _ref3$legacyRoot === void 0 ? typeof ReactDOM__default["default"].createRoot !== 'function' : _ref3$legacyRoot, | ||
queries = _ref3.queries, | ||
@@ -529,6 +637,4 @@ _ref3$hydrate = _ref3.hydrate, | ||
enumerable: true, | ||
get: function () { | ||
return dom[k]; | ||
} | ||
get: function () { return dom[k]; } | ||
}); | ||
}); |
@@ -22,3 +22,78 @@ import _extends from '@babel/runtime/helpers/esm/extends'; | ||
var act = isomorphicAct || domAct || actPolyfill; | ||
function getGlobalThis() { | ||
/* istanbul ignore else */ | ||
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 setReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
return function (callback) { | ||
var previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(true); | ||
try { | ||
// The return value of `act` is always a thenable. | ||
var callbackNeedsToBeAwaited = false; | ||
var actResult = actImplementation(function () { | ||
var result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
var thenable = actResult; | ||
return { | ||
then: function then(resolve, reject) { | ||
thenable.then(function (returnValue) { | ||
setReactActEnvironment(previousActEnvironment); | ||
resolve(returnValue); | ||
}, function (error) { | ||
setReactActEnvironment(previousActEnvironment); | ||
reject(error); | ||
}); | ||
} | ||
}; | ||
} else { | ||
setReactActEnvironment(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. | ||
setReactActEnvironment(previousActEnvironment); | ||
throw error; | ||
} | ||
}; | ||
} | ||
var act = withGlobalActEnvironment(isomorphicAct || domAct || actPolyfill); | ||
var youHaveBeenWarned = false; | ||
@@ -266,5 +341,40 @@ var isAsyncActSupported = null; | ||
}, | ||
asyncWrapper: function asyncWrapper(cb) { | ||
return 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: function () { | ||
var _asyncWrapper2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(cb) { | ||
var previousActEnvironment; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(false); | ||
_context3.prev = 2; | ||
_context3.next = 5; | ||
return cb(); | ||
case 5: | ||
return _context3.abrupt("return", _context3.sent); | ||
case 6: | ||
_context3.prev = 6; | ||
setReactActEnvironment(previousActEnvironment); | ||
return _context3.finish(6); | ||
case 9: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, null, [[2,, 6, 9]]); | ||
})); | ||
function asyncWrapper(_x2) { | ||
return _asyncWrapper2.apply(this, arguments); | ||
} | ||
return asyncWrapper; | ||
}() | ||
}); | ||
@@ -271,0 +381,0 @@ } // Ideally we'd just use a WeakMap where containers are keys and roots are values. |
@@ -24,5 +24,3 @@ 'use strict'; | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
get: function () { return e[k]; } | ||
}); | ||
@@ -32,3 +30,3 @@ } | ||
} | ||
n['default'] = e; | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
@@ -52,7 +50,82 @@ } | ||
function actPolyfill(cb) { | ||
ReactDOM__default['default'].unstable_batchedUpdates(cb); | ||
ReactDOM__default['default'].render( /*#__PURE__*/React__namespace.createElement("div", null), document.createElement('div')); | ||
ReactDOM__default["default"].unstable_batchedUpdates(cb); | ||
ReactDOM__default["default"].render( /*#__PURE__*/React__namespace.createElement("div", null), document.createElement('div')); | ||
} | ||
var act = isomorphicAct || domAct || actPolyfill; | ||
function getGlobalThis() { | ||
/* istanbul ignore else */ | ||
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 setReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
return function (callback) { | ||
var previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(true); | ||
try { | ||
// The return value of `act` is always a thenable. | ||
var callbackNeedsToBeAwaited = false; | ||
var actResult = actImplementation(function () { | ||
var result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
var thenable = actResult; | ||
return { | ||
then: function then(resolve, reject) { | ||
thenable.then(function (returnValue) { | ||
setReactActEnvironment(previousActEnvironment); | ||
resolve(returnValue); | ||
}, function (error) { | ||
setReactActEnvironment(previousActEnvironment); | ||
reject(error); | ||
}); | ||
} | ||
}; | ||
} else { | ||
setReactActEnvironment(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. | ||
setReactActEnvironment(previousActEnvironment); | ||
throw error; | ||
} | ||
}; | ||
} | ||
var act = withGlobalActEnvironment(isomorphicAct || domAct || actPolyfill); | ||
var youHaveBeenWarned = false; | ||
@@ -243,5 +316,5 @@ var isAsyncActSupported = null; | ||
asyncWrapper: function () { | ||
var _asyncWrapper = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(cb) { | ||
var _asyncWrapper = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(cb) { | ||
var result; | ||
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) { | ||
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
@@ -251,4 +324,4 @@ switch (_context2.prev = _context2.next) { | ||
_context2.next = 2; | ||
return asyncAct( /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() { | ||
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) { | ||
return asyncAct( /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() { | ||
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
@@ -302,5 +375,40 @@ switch (_context.prev = _context.next) { | ||
}, | ||
asyncWrapper: function asyncWrapper(cb) { | ||
return 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: function () { | ||
var _asyncWrapper2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(cb) { | ||
var previousActEnvironment; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(false); | ||
_context3.prev = 2; | ||
_context3.next = 5; | ||
return cb(); | ||
case 5: | ||
return _context3.abrupt("return", _context3.sent); | ||
case 6: | ||
_context3.prev = 6; | ||
setReactActEnvironment(previousActEnvironment); | ||
return _context3.finish(6); | ||
case 9: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, null, [[2,, 6, 9]]); | ||
})); | ||
function asyncWrapper(_x2) { | ||
return _asyncWrapper2.apply(this, arguments); | ||
} | ||
return asyncWrapper; | ||
}() | ||
}); | ||
@@ -323,7 +431,7 @@ } // Ideally we'd just use a WeakMap where containers are keys and roots are values. | ||
function createConcurrentRoot(container, options) { | ||
if (typeof ReactDOM__default['default'].createRoot !== 'function') { | ||
throw new TypeError("Attempted to use concurrent React with `react-dom@" + ReactDOM__default['default'].version + "`. Be sure to use the `next` or `experimental` release channel (https://reactjs.org/docs/release-channels.html).'"); | ||
if (typeof ReactDOM__default["default"].createRoot !== 'function') { | ||
throw new TypeError("Attempted to use concurrent React with `react-dom@" + ReactDOM__default["default"].version + "`. Be sure to use the `next` or `experimental` release channel (https://reactjs.org/docs/release-channels.html).'"); | ||
} | ||
var root = options.hydrate ? ReactDOM__default['default'].hydrateRoot(container) : ReactDOM__default['default'].createRoot(container); | ||
var root = options.hydrate ? ReactDOM__default["default"].hydrateRoot(container) : ReactDOM__default["default"].createRoot(container); | ||
return { | ||
@@ -350,9 +458,9 @@ hydrate: function hydrate(element) { | ||
hydrate: function hydrate(element) { | ||
ReactDOM__default['default'].hydrate(element, container); | ||
ReactDOM__default["default"].hydrate(element, container); | ||
}, | ||
render: function render(element) { | ||
ReactDOM__default['default'].render(element, container); | ||
ReactDOM__default["default"].render(element, container); | ||
}, | ||
unmount: function unmount() { | ||
ReactDOM__default['default'].unmountComponentAtNode(container); | ||
ReactDOM__default["default"].unmountComponentAtNode(container); | ||
} | ||
@@ -381,3 +489,3 @@ }; | ||
}); | ||
return _extends__default['default']({ | ||
return _extends__default["default"]({ | ||
container: container, | ||
@@ -428,3 +536,3 @@ baseElement: baseElement, | ||
_ref3$legacyRoot = _ref3.legacyRoot, | ||
legacyRoot = _ref3$legacyRoot === void 0 ? typeof ReactDOM__default['default'].createRoot !== 'function' : _ref3$legacyRoot, | ||
legacyRoot = _ref3$legacyRoot === void 0 ? typeof ReactDOM__default["default"].createRoot !== 'function' : _ref3$legacyRoot, | ||
queries = _ref3.queries, | ||
@@ -505,6 +613,4 @@ _ref3$hydrate = _ref3.hydrate, | ||
enumerable: true, | ||
get: function () { | ||
return dom[k]; | ||
} | ||
get: function () { return dom[k]; } | ||
}); | ||
}); |
@@ -22,3 +22,78 @@ import _extends from '@babel/runtime/helpers/esm/extends'; | ||
var act = isomorphicAct || domAct || actPolyfill; | ||
function getGlobalThis() { | ||
/* istanbul ignore else */ | ||
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 setReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
return function (callback) { | ||
var previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(true); | ||
try { | ||
// The return value of `act` is always a thenable. | ||
var callbackNeedsToBeAwaited = false; | ||
var actResult = actImplementation(function () { | ||
var result = callback(); | ||
if (result !== null && typeof result === 'object' && typeof result.then === 'function') { | ||
callbackNeedsToBeAwaited = true; | ||
} | ||
return result; | ||
}); | ||
if (callbackNeedsToBeAwaited) { | ||
var thenable = actResult; | ||
return { | ||
then: function then(resolve, reject) { | ||
thenable.then(function (returnValue) { | ||
setReactActEnvironment(previousActEnvironment); | ||
resolve(returnValue); | ||
}, function (error) { | ||
setReactActEnvironment(previousActEnvironment); | ||
reject(error); | ||
}); | ||
} | ||
}; | ||
} else { | ||
setReactActEnvironment(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. | ||
setReactActEnvironment(previousActEnvironment); | ||
throw error; | ||
} | ||
}; | ||
} | ||
var act = withGlobalActEnvironment(isomorphicAct || domAct || actPolyfill); | ||
var youHaveBeenWarned = false; | ||
@@ -266,5 +341,40 @@ var isAsyncActSupported = null; | ||
}, | ||
asyncWrapper: function asyncWrapper(cb) { | ||
return 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: function () { | ||
var _asyncWrapper2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(cb) { | ||
var previousActEnvironment; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(false); | ||
_context3.prev = 2; | ||
_context3.next = 5; | ||
return cb(); | ||
case 5: | ||
return _context3.abrupt("return", _context3.sent); | ||
case 6: | ||
_context3.prev = 6; | ||
setReactActEnvironment(previousActEnvironment); | ||
return _context3.finish(6); | ||
case 9: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, null, [[2,, 6, 9]]); | ||
})); | ||
function asyncWrapper(_x2) { | ||
return _asyncWrapper2.apply(this, arguments); | ||
} | ||
return asyncWrapper; | ||
}() | ||
}); | ||
@@ -271,0 +381,0 @@ } // Ideally we'd just use a WeakMap where containers are keys and roots are values. |
@@ -10,2 +10,4 @@ "use strict"; | ||
exports.default = void 0; | ||
exports.getIsReactActEnvironment = getIsReactActEnvironment; | ||
exports.setReactActEnvironment = setReactActEnvironment; | ||
@@ -35,3 +37,78 @@ var React = _interopRequireWildcard(require("react")); | ||
const act = isomorphicAct || domAct || actPolyfill; | ||
function getGlobalThis() { | ||
/* istanbul ignore else */ | ||
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 setReactActEnvironment(isReactActEnvironment) { | ||
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment; | ||
} | ||
function getIsReactActEnvironment() { | ||
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
function withGlobalActEnvironment(actImplementation) { | ||
return callback => { | ||
const previousActEnvironment = getIsReactActEnvironment(); | ||
setReactActEnvironment(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 => { | ||
setReactActEnvironment(previousActEnvironment); | ||
resolve(returnValue); | ||
}, error => { | ||
setReactActEnvironment(previousActEnvironment); | ||
reject(error); | ||
}); | ||
} | ||
}; | ||
} else { | ||
setReactActEnvironment(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. | ||
setReactActEnvironment(previousActEnvironment); | ||
throw error; | ||
} | ||
}; | ||
} | ||
const act = withGlobalActEnvironment(isomorphicAct || domAct || actPolyfill); | ||
let youHaveBeenWarned = false; | ||
@@ -38,0 +115,0 @@ let isAsyncActSupported = null; |
@@ -14,4 +14,2 @@ "use strict"; | ||
}; | ||
exports.render = render; | ||
exports.cleanup = cleanup; | ||
Object.defineProperty(exports, "act", { | ||
@@ -23,2 +21,3 @@ enumerable: true, | ||
}); | ||
exports.cleanup = cleanup; | ||
Object.defineProperty(exports, "fireEvent", { | ||
@@ -30,2 +29,3 @@ enumerable: true, | ||
}); | ||
exports.render = render; | ||
@@ -80,3 +80,15 @@ var React = _interopRequireWildcard(require("react")); | ||
}, | ||
asyncWrapper: cb => 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 { | ||
return await cb(); | ||
} finally { | ||
(0, _actCompat.setReactActEnvironment)(previousActEnvironment); | ||
} | ||
} | ||
}); | ||
@@ -83,0 +95,0 @@ } // Ideally we'd just use a WeakMap where containers are keys and roots are values. |
{ | ||
"name": "@testing-library/react", | ||
"version": "13.0.0-alpha.1", | ||
"version": "13.0.0-alpha.3", | ||
"description": "Simple and complete React DOM testing utilities that encourage good testing practices.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
4353231
29081