Socket
Socket
Sign inDemoInstall

@testing-library/react

Package Overview
Dependencies
Maintainers
10
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testing-library/react - npm Package Compare versions

Comparing version 8.0.5 to 8.0.6

163

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

@@ -17,33 +17,5 @@ 'use strict';

var reactAct;
var actSupported = false;
var asyncActSupported = false;
var reactAct = require('react-dom/test-utils').act;
try {
reactAct = require('react-dom/test-utils').act;
actSupported = reactAct !== undefined;
var originalError = console.error;
var errorCalled = false;
console.error = function () {
errorCalled = true;
};
console.error.calls = [];
/* istanbul ignore next */
reactAct(function () {
return {
then: function then() {}
};
}).then(function () {});
/* istanbul ignore next */
if (!errorCalled) {
asyncActSupported = true;
}
console.error = originalError;
} catch (error) {} // ignore, this is to support old versions of react
// act is supported react-dom@16.8.0
var actSupported = reactAct !== undefined; // act is supported react-dom@16.8.0
// so for versions that don't have act from test utils

@@ -53,3 +25,2 @@ // we do this little polyfill. No warnings, but it's

function actPolyfill(cb) {

@@ -61,46 +32,104 @@ ReactDOM.unstable_batchedUpdates(cb);

var act = reactAct || actPolyfill;
var youHaveBeenWarned = false; // this will not avoid warnings that react-dom 16.8.0 logs for triggering
// state updates asynchronously, but at least we can tell people they need
// to upgrade to avoid the warnings.
var youHaveBeenWarned = false;
var isAsyncActSupported = null;
function asyncActPolyfill() {
return _asyncActPolyfill.apply(this, arguments);
} // istanbul ignore next
function asyncAct(cb) {
if (actSupported === true) {
if (isAsyncActSupported === null) {
return new Promise(function (resolve, reject) {
// patch console.error here
var originalConsoleError = console.error;
console.error = function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
function _asyncActPolyfill() {
_asyncActPolyfill = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee(cb) {
return _regeneratorRuntime.wrap(function (_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
// istanbul-ignore-next
if (!youHaveBeenWarned && actSupported && reactDomSixteenPointNineIsReleased) {
// if act is supported and async act isn't and they're trying to use async
// act, then they need to upgrade from 16.8 to 16.9.
// This is a seemless upgrade, so we'll add a warning
console.error("It looks like you're using a version of react-dom that supports the \"act\" function, but not an awaitable version of \"act\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.");
youHaveBeenWarned = true;
}
/* if console.error fired *with that specific message* */
if (args[0].indexOf('Warning: Do not await the result of calling ReactTestUtils.act') === 0) {
// v16.8.6
isAsyncActSupported = false;
} else if (!(args[0].indexOf('Warning: The callback passed to ReactTestUtils.act(...) function must not return anything') === 0)) {
originalConsoleError.call(console, args);
}
};
_context.next = 3;
return cb();
var cbReturn, result;
case 3:
// make all effects resolve after
act(function () {});
try {
result = reactAct(function () {
cbReturn = cb();
return cbReturn;
});
} catch (err) {
console.error = originalConsoleError;
reject(err);
return;
}
case 4:
case "end":
return _context.stop();
result.then(function () {
console.error = originalConsoleError; // if it got here, it means async act is supported
isAsyncActSupported = true;
resolve();
}, function (err) {
console.error = originalConsoleError;
isAsyncActSupported = true;
reject(err);
}); // 16.8.6's act().then() doesn't call a resolve handler, so we need to manually flush here, sigh
if (isAsyncActSupported === false) {
console.error = originalConsoleError;
/* istanbul-ignore-next */
if (!youHaveBeenWarned && reactDomSixteenPointNineIsReleased) {
// if act is supported and async act isn't and they're trying to use async
// act, then they need to upgrade from 16.8 to 16.9.
// This is a seemless upgrade, so we'll add a warning
console.error("It looks like you're using a version of react-dom that supports the \"act\" function, but not an awaitable version of \"act\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.");
youHaveBeenWarned = true;
}
cbReturn.then(function () {
// a faux-version.
// todo - copy https://github.com/facebook/react/blob/master/packages/shared/enqueueTask.js
Promise.resolve().then(function () {
// use sync act to flush effects
act(function () {});
resolve();
});
}, reject);
}
}
}, _callee);
}));
return _asyncActPolyfill.apply(this, arguments);
});
} else if (isAsyncActSupported === false) {
// use the polyfill directly
var _result;
act(function () {
_result = cb();
});
return _result.then(function () {
return Promise.resolve().then(function () {
// use sync act to flush effects
act(function () {});
});
});
} // all good! regular act
return act(cb);
} // use the polyfill
var result;
act(function () {
result = cb();
});
return result.then(function () {
return Promise.resolve().then(function () {
// use sync act to flush effects
act(function () {});
});
});
}
var asyncAct = asyncActSupported ? reactAct : asyncActPolyfill;
/* eslint no-console:0 */

@@ -107,0 +136,0 @@

@@ -12,33 +12,5 @@ import _extends from '@babel/runtime/helpers/esm/extends';

var reactAct;
var actSupported = false;
var asyncActSupported = false;
var reactAct = require('react-dom/test-utils').act;
try {
reactAct = require('react-dom/test-utils').act;
actSupported = reactAct !== undefined;
var originalError = console.error;
var errorCalled = false;
console.error = function () {
errorCalled = true;
};
console.error.calls = [];
/* istanbul ignore next */
reactAct(function () {
return {
then: function then() {}
};
}).then(function () {});
/* istanbul ignore next */
if (!errorCalled) {
asyncActSupported = true;
}
console.error = originalError;
} catch (error) {} // ignore, this is to support old versions of react
// act is supported react-dom@16.8.0
var actSupported = reactAct !== undefined; // act is supported react-dom@16.8.0
// so for versions that don't have act from test utils

@@ -48,3 +20,2 @@ // we do this little polyfill. No warnings, but it's

function actPolyfill(cb) {

@@ -56,46 +27,104 @@ ReactDOM.unstable_batchedUpdates(cb);

var act = reactAct || actPolyfill;
var youHaveBeenWarned = false; // this will not avoid warnings that react-dom 16.8.0 logs for triggering
// state updates asynchronously, but at least we can tell people they need
// to upgrade to avoid the warnings.
var youHaveBeenWarned = false;
var isAsyncActSupported = null;
function asyncActPolyfill() {
return _asyncActPolyfill.apply(this, arguments);
} // istanbul ignore next
function asyncAct(cb) {
if (actSupported === true) {
if (isAsyncActSupported === null) {
return new Promise(function (resolve, reject) {
// patch console.error here
var originalConsoleError = console.error;
console.error = function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
function _asyncActPolyfill() {
_asyncActPolyfill = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee(cb) {
return _regeneratorRuntime.wrap(function (_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
// istanbul-ignore-next
if (!youHaveBeenWarned && actSupported && reactDomSixteenPointNineIsReleased) {
// if act is supported and async act isn't and they're trying to use async
// act, then they need to upgrade from 16.8 to 16.9.
// This is a seemless upgrade, so we'll add a warning
console.error("It looks like you're using a version of react-dom that supports the \"act\" function, but not an awaitable version of \"act\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.");
youHaveBeenWarned = true;
}
/* if console.error fired *with that specific message* */
if (args[0].indexOf('Warning: Do not await the result of calling ReactTestUtils.act') === 0) {
// v16.8.6
isAsyncActSupported = false;
} else if (!(args[0].indexOf('Warning: The callback passed to ReactTestUtils.act(...) function must not return anything') === 0)) {
originalConsoleError.call(console, args);
}
};
_context.next = 3;
return cb();
var cbReturn, result;
case 3:
// make all effects resolve after
act(function () {});
try {
result = reactAct(function () {
cbReturn = cb();
return cbReturn;
});
} catch (err) {
console.error = originalConsoleError;
reject(err);
return;
}
case 4:
case "end":
return _context.stop();
result.then(function () {
console.error = originalConsoleError; // if it got here, it means async act is supported
isAsyncActSupported = true;
resolve();
}, function (err) {
console.error = originalConsoleError;
isAsyncActSupported = true;
reject(err);
}); // 16.8.6's act().then() doesn't call a resolve handler, so we need to manually flush here, sigh
if (isAsyncActSupported === false) {
console.error = originalConsoleError;
/* istanbul-ignore-next */
if (!youHaveBeenWarned && reactDomSixteenPointNineIsReleased) {
// if act is supported and async act isn't and they're trying to use async
// act, then they need to upgrade from 16.8 to 16.9.
// This is a seemless upgrade, so we'll add a warning
console.error("It looks like you're using a version of react-dom that supports the \"act\" function, but not an awaitable version of \"act\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.");
youHaveBeenWarned = true;
}
cbReturn.then(function () {
// a faux-version.
// todo - copy https://github.com/facebook/react/blob/master/packages/shared/enqueueTask.js
Promise.resolve().then(function () {
// use sync act to flush effects
act(function () {});
resolve();
});
}, reject);
}
}
}, _callee);
}));
return _asyncActPolyfill.apply(this, arguments);
});
} else if (isAsyncActSupported === false) {
// use the polyfill directly
var _result;
act(function () {
_result = cb();
});
return _result.then(function () {
return Promise.resolve().then(function () {
// use sync act to flush effects
act(function () {});
});
});
} // all good! regular act
return act(cb);
} // use the polyfill
var result;
act(function () {
result = cb();
});
return result.then(function () {
return Promise.resolve().then(function () {
// use sync act to flush effects
act(function () {});
});
});
}
var asyncAct = asyncActSupported ? reactAct : asyncActPolyfill;
/* eslint no-console:0 */

@@ -102,0 +131,0 @@

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

});
exports.asyncAct = exports.default = void 0;
exports.asyncAct = asyncAct;
exports.default = void 0;

@@ -17,31 +18,5 @@ var _react = _interopRequireDefault(require("react"));

let reactAct;
let actSupported = false;
let asyncActSupported = false;
const reactAct = require('react-dom/test-utils').act;
try {
reactAct = require('react-dom/test-utils').act;
actSupported = reactAct !== undefined;
const originalError = console.error;
let errorCalled = false;
console.error = () => {
errorCalled = true;
};
console.error.calls = [];
/* istanbul ignore next */
reactAct(() => ({
then: () => {}
})).then(() => {});
/* istanbul ignore next */
if (!errorCalled) {
asyncActSupported = true;
}
console.error = originalError;
} catch (error) {} // ignore, this is to support old versions of react
// act is supported react-dom@16.8.0
const actSupported = reactAct !== undefined; // act is supported react-dom@16.8.0
// so for versions that don't have act from test utils

@@ -51,3 +26,2 @@ // we do this little polyfill. No warnings, but it's

function actPolyfill(cb) {

@@ -60,24 +34,100 @@ _reactDom.default.unstable_batchedUpdates(cb);

const act = reactAct || actPolyfill;
let youHaveBeenWarned = false; // this will not avoid warnings that react-dom 16.8.0 logs for triggering
// state updates asynchronously, but at least we can tell people they need
// to upgrade to avoid the warnings.
let youHaveBeenWarned = false;
let isAsyncActSupported = null;
async function asyncActPolyfill(cb) {
// istanbul-ignore-next
if (!youHaveBeenWarned && actSupported && _reactDom2.reactDomSixteenPointNineIsReleased) {
// if act is supported and async act isn't and they're trying to use async
// act, then they need to upgrade from 16.8 to 16.9.
// This is a seemless upgrade, so we'll add a warning
console.error(`It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.`);
youHaveBeenWarned = true;
}
function asyncAct(cb) {
if (actSupported === true) {
if (isAsyncActSupported === null) {
return new Promise((resolve, reject) => {
// patch console.error here
const originalConsoleError = console.error;
await cb(); // make all effects resolve after
console.error = function (...args) {
/* if console.error fired *with that specific message* */
if (args[0].indexOf('Warning: Do not await the result of calling ReactTestUtils.act') === 0) {
// v16.8.6
isAsyncActSupported = false;
} else if (!(args[0].indexOf('Warning: The callback passed to ReactTestUtils.act(...) function must not return anything') === 0)) {
originalConsoleError.call(console, args);
}
};
act(() => {});
} // istanbul ignore next
let cbReturn, result;
try {
result = reactAct(() => {
cbReturn = cb();
return cbReturn;
});
} catch (err) {
console.error = originalConsoleError;
reject(err);
return;
}
const asyncAct = asyncActSupported ? reactAct : asyncActPolyfill;
exports.asyncAct = asyncAct;
result.then(() => {
console.error = originalConsoleError; // if it got here, it means async act is supported
isAsyncActSupported = true;
resolve();
}, err => {
console.error = originalConsoleError;
isAsyncActSupported = true;
reject(err);
}); // 16.8.6's act().then() doesn't call a resolve handler, so we need to manually flush here, sigh
if (isAsyncActSupported === false) {
console.error = originalConsoleError;
/* istanbul-ignore-next */
if (!youHaveBeenWarned && _reactDom2.reactDomSixteenPointNineIsReleased) {
// if act is supported and async act isn't and they're trying to use async
// act, then they need to upgrade from 16.8 to 16.9.
// This is a seemless upgrade, so we'll add a warning
console.error(`It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.`);
youHaveBeenWarned = true;
}
cbReturn.then(() => {
// a faux-version.
// todo - copy https://github.com/facebook/react/blob/master/packages/shared/enqueueTask.js
Promise.resolve().then(() => {
// use sync act to flush effects
act(() => {});
resolve();
});
}, reject);
}
});
} else if (isAsyncActSupported === false) {
// use the polyfill directly
let result;
act(() => {
result = cb();
});
return result.then(() => {
return Promise.resolve().then(() => {
// use sync act to flush effects
act(() => {});
});
});
} // all good! regular act
return act(cb);
} // use the polyfill
let result;
act(() => {
result = cb();
});
return result.then(() => {
return Promise.resolve().then(() => {
// use sync act to flush effects
act(() => {});
});
});
}
var _default = act;

@@ -84,0 +134,0 @@ /* eslint no-console:0 */

{
"name": "@testing-library/react",
"version": "8.0.5",
"version": "8.0.6",
"description": "Simple and complete React DOM testing utilities that encourage good testing practices.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -32,3 +32,3 @@ <div align="center">

[![All Contributors](https://img.shields.io/badge/all_contributors-81-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-84-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]

@@ -255,3 +255,3 @@ [![Join the community on Spectrum][spectrum-badge]][spectrum]

fireEvent.change(getByLabelText(/username/i), {target: {value: 'chuck'}})
fireEvent.change(getBylabelText(/password/i), {target: {value: 'norris'}})
fireEvent.change(getByLabelText(/password/i), {target: {value: 'norris'}})

@@ -268,3 +268,3 @@ fireEvent.click(getByText(/submit/i))

expect(alert).toHaveTextContent(/congrats/i)
expect(window.localStorage.getItem('token')).toEqual(fakeUserReponse.token)
expect(window.localStorage.getItem('token')).toEqual(fakeUserResponse.token)
})

@@ -465,2 +465,5 @@ ```

<td align="center"><a href="https://twitter.com/minh_ngvyen"><img src="https://avatars3.githubusercontent.com/u/2852660?v=4" width="100px;" alt="Minh Nguyen"/><br /><sub><b>Minh Nguyen</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=NMinhNguyen" title="Code">💻</a></td>
<td align="center"><a href="http://iababy46.blogspot.tw/"><img src="https://avatars0.githubusercontent.com/u/11155585?v=4" width="100px;" alt="LiaoJimmy"/><br /><sub><b>LiaoJimmy</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=LiaoJimmy" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/threepointone"><img src="https://avatars2.githubusercontent.com/u/18808?v=4" width="100px;" alt="Sunil Pai"/><br /><sub><b>Sunil Pai</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=threepointone" title="Code">💻</a> <a href="https://github.com/testing-library/react-testing-library/commits?author=threepointone" title="Tests">⚠️</a></td>
<td align="center"><a href="http://twitter.com/dan_abramov"><img src="https://avatars0.githubusercontent.com/u/810438?v=4" width="100px;" alt="Dan Abramov"/><br /><sub><b>Dan Abramov</b></sub></a><br /><a href="#review-gaearon" title="Reviewed Pull Requests">👀</a></td>
</tr>

@@ -467,0 +470,0 @@ </table>

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc