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.9 to 9.0.0

dist/pure.js

48

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

@@ -7,3 +7,2 @@ 'use strict';

var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));

@@ -13,4 +12,5 @@ var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));

var ReactDOM = _interopDefault(require('react-dom'));
var testUtils = require('react-dom/test-utils');
var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
var dom = require('@testing-library/dom');
var testUtils = require('react-dom/test-utils');

@@ -327,2 +327,46 @@ var reactAct = testUtils.act;

// 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 afterEach === 'function' && !process.env.RTL_SKIP_AUTO_CLEANUP) {
afterEach(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.wrap(function (_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return asyncAct(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function (_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
}
}, _callee);
})));
case 2:
cleanup();
case 3:
case "end":
return _context2.stop();
}
}
}, _callee2);
})));
}
Object.keys(dom).forEach(function (k) {

@@ -329,0 +373,0 @@ if (k !== 'default') Object.defineProperty(exports, k, {

@@ -1,2 +0,1 @@

import _extends from '@babel/runtime/helpers/esm/extends';
import _regeneratorRuntime from '@babel/runtime/regenerator';

@@ -6,5 +5,6 @@ import _asyncToGenerator from '@babel/runtime/helpers/esm/asyncToGenerator';

import ReactDOM from 'react-dom';
import { act as act$1 } from 'react-dom/test-utils';
import _extends from '@babel/runtime/helpers/esm/extends';
import { configure, prettyDOM, getQueriesForElement, fireEvent as fireEvent$1 } from '@testing-library/dom';
export * from '@testing-library/dom';
import { act as act$1 } from 'react-dom/test-utils';

@@ -321,2 +321,46 @@ var reactAct = act$1;

// 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 afterEach === 'function' && !process.env.RTL_SKIP_AUTO_CLEANUP) {
afterEach(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.wrap(function (_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return asyncAct(
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function (_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
}
}, _callee);
})));
case 2:
cleanup();
case 3:
case "end":
return _context2.stop();
}
}
}, _callee2);
})));
}
export { act, cleanup, fireEvent, render };

173

dist/index.js
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
render: true,
cleanup: true,
fireEvent: true,
act: true
};
exports.render = render;
exports.cleanup = cleanup;
exports.fireEvent = fireEvent;
Object.defineProperty(exports, "act", {
enumerable: true,
get: function () {
return _actCompat.default;
}
});
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _actCompat = require("./act-compat");
var _react = _interopRequireDefault(require("react"));
var _pure = require("./pure");
var _reactDom = _interopRequireDefault(require("react-dom"));
var _dom = require("@testing-library/dom");
Object.keys(_dom).forEach(function (key) {
Object.keys(_pure).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _dom[key];
return _pure[key];
}

@@ -45,133 +21,12 @@ });

var _actCompat = _interopRequireWildcard(require("./act-compat"));
(0, _dom.configure)({
asyncWrapper: async cb => {
let result;
await (0, _actCompat.asyncAct)(async () => {
result = await cb();
});
return result;
}
});
const mountedContainers = new Set();
function render(ui, {
container,
baseElement = container,
queries,
hydrate = false,
wrapper: WrapperComponent
} = {}) {
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'));
} // 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);
const wrapUiIfNeeded = innerElement => WrapperComponent ? _react.default.createElement(WrapperComponent, null, innerElement) : innerElement;
(0, _actCompat.default)(() => {
if (hydrate) {
_reactDom.default.hydrate(wrapUiIfNeeded(ui), container);
} else {
_reactDom.default.render(wrapUiIfNeeded(ui), container);
}
// if we're running in a test runner that supports afterEach
// 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 afterEach === 'function' && !process.env.RTL_SKIP_AUTO_CLEANUP) {
afterEach(async () => {
await (0, _actCompat.asyncAct)(async () => {});
(0, _pure.cleanup)();
});
return (0, _extends2.default)({
container,
baseElement,
// eslint-disable-next-line no-console
debug: (el = baseElement) => console.log((0, _dom.prettyDOM)(el)),
unmount: () => _reactDom.default.unmountComponentAtNode(container),
rerender: rerenderUi => {
render(wrapUiIfNeeded(rerenderUi), {
container,
baseElement
}); // 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 if (jsdom limitation) */
if (typeof document.createRange === 'function') {
return document.createRange().createContextualFragment(container.innerHTML);
}
const template = document.createElement('template');
template.innerHTML = container.innerHTML;
return template.content;
}
}, (0, _dom.getQueriesForElement)(baseElement, queries));
}
function cleanup() {
mountedContainers.forEach(cleanupAtContainer);
} // maybe one day we'll expose this (perhaps even as a utility returned by render).
// but let's wait until someone asks for it.
function cleanupAtContainer(container) {
_reactDom.default.unmountComponentAtNode(container);
if (container.parentNode === document.body) {
document.body.removeChild(container);
}
mountedContainers.delete(container);
} // react-testing-library's version of fireEvent will call
// dom-testing-library's version of fireEvent wrapped inside
// an "act" call so that after all event callbacks have been
// been called, the resulting useEffect callbacks will also
// be called.
function fireEvent(...args) {
let returnValue;
(0, _actCompat.default)(() => {
returnValue = (0, _dom.fireEvent)(...args);
});
return returnValue;
}
Object.keys(_dom.fireEvent).forEach(key => {
fireEvent[key] = (...args) => {
let returnValue;
(0, _actCompat.default)(() => {
returnValue = _dom.fireEvent[key](...args);
});
return returnValue;
};
}); // 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
fireEvent.mouseEnter = fireEvent.mouseOver;
fireEvent.mouseLeave = fireEvent.mouseOut;
fireEvent.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);
}; // just re-export everything from dom-testing-library
// NOTE: we're not going to export asyncAct because that's our own compatibility
// thing for people using react-dom@16.8.0. Anyone else doesn't need it and
// people should just upgrade anyway.
/* eslint func-name-matching:0 */
}
{
"name": "@testing-library/react",
"version": "8.0.9",
"version": "9.0.0",
"description": "Simple and complete React DOM testing utilities that encourage good testing practices.",

@@ -27,3 +27,4 @@ "main": "dist/index.js",

"typings",
"cleanup-after-each.js"
"cleanup-after-each.js",
"pure.js"
],

@@ -46,3 +47,3 @@ "keywords": [

"@babel/runtime": "^7.5.5",
"@testing-library/dom": "^5.6.1"
"@testing-library/dom": "^6.0.0"
},

@@ -52,3 +53,3 @@ "devDependencies": {

"@testing-library/jest-dom": "^4.0.0",
"@types/react": "^16.8.25",
"@types/react": "^16.9.1",
"@types/react-dom": "^16.8.5",

@@ -55,0 +56,0 @@ "kcd-scripts": "^1.5.2",

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