jest-react
Advanced tools
@@ -11,145 +11,104 @@ /** | ||
'use strict'; | ||
if (process.env.NODE_ENV !== "production") { | ||
(function() { | ||
'use strict'; | ||
var assign = Object.assign; | ||
// ATTENTION | ||
// When adding new symbols to this file, | ||
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols' | ||
// The Symbol used to tag the ReactElement-like types. | ||
var REACT_ELEMENT_TYPE = Symbol.for('react.element'); | ||
var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment'); | ||
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare | ||
function isArray(a) { | ||
return isArrayImpl(a); | ||
} | ||
function captureAssertion(fn) { | ||
// Trick to use a Jest matcher inside another Jest matcher. `fn` contains an | ||
// assertion; if it throws, we capture the error and return it, so the stack | ||
// trace presented to the user points to the original assertion in the | ||
// test file. | ||
try { | ||
fn(); | ||
} catch (error) { | ||
return { | ||
pass: false, | ||
message: function () { | ||
return error.message; | ||
} | ||
}; | ||
} | ||
return { | ||
pass: true | ||
}; | ||
} | ||
function assertYieldsWereCleared(root) { | ||
var Scheduler = root._Scheduler; | ||
var actualYields = Scheduler.unstable_clearLog(); | ||
if (actualYields.length !== 0) { | ||
var error = Error('Log of yielded values is not empty. ' + 'Call expect(ReactTestRenderer).unstable_toHaveYielded(...) first.'); | ||
Error.captureStackTrace(error, assertYieldsWereCleared); | ||
throw error; | ||
} | ||
} | ||
function unstable_toMatchRenderedOutput(root, expectedJSX) { | ||
assertYieldsWereCleared(root); | ||
var actualJSON = root.toJSON(); | ||
var actualJSX; | ||
if (actualJSON === null || typeof actualJSON === 'string') { | ||
actualJSX = actualJSON; | ||
} else if (isArray(actualJSON)) { | ||
if (actualJSON.length === 0) { | ||
actualJSX = null; | ||
} else if (actualJSON.length === 1) { | ||
actualJSX = jsonChildToJSXChild(actualJSON[0]); | ||
} else { | ||
var actualJSXChildren = jsonChildrenToJSXChildren(actualJSON); | ||
if (actualJSXChildren === null || typeof actualJSXChildren === 'string') { | ||
actualJSX = actualJSXChildren; | ||
} else { | ||
actualJSX = { | ||
$$typeof: REACT_ELEMENT_TYPE, | ||
type: REACT_FRAGMENT_TYPE, | ||
key: null, | ||
ref: null, | ||
props: { | ||
children: actualJSXChildren | ||
}, | ||
_owner: null, | ||
_store: {} | ||
"use strict"; | ||
"production" !== process.env.NODE_ENV && | ||
(function () { | ||
function captureAssertion(fn) { | ||
try { | ||
fn(); | ||
} catch (error) { | ||
return { | ||
pass: !1, | ||
message: function () { | ||
return error.message; | ||
} | ||
}; | ||
} | ||
return { pass: !0 }; | ||
} | ||
} else { | ||
actualJSX = jsonChildToJSXChild(actualJSON); | ||
} | ||
return captureAssertion(function () { | ||
expect(actualJSX).toEqual(expectedJSX); | ||
}); | ||
} | ||
function jsonChildToJSXChild(jsonChild) { | ||
if (jsonChild === null || typeof jsonChild === 'string') { | ||
return jsonChild; | ||
} else { | ||
var jsxChildren = jsonChildrenToJSXChildren(jsonChild.children); | ||
return { | ||
$$typeof: REACT_ELEMENT_TYPE, | ||
type: jsonChild.type, | ||
key: null, | ||
ref: null, | ||
props: jsxChildren === null ? jsonChild.props : assign({}, jsonChild.props, { | ||
children: jsxChildren | ||
}), | ||
_owner: null, | ||
_store: {} | ||
}; | ||
} | ||
} | ||
function jsonChildrenToJSXChildren(jsonChildren) { | ||
if (jsonChildren !== null) { | ||
if (jsonChildren.length === 1) { | ||
return jsonChildToJSXChild(jsonChildren[0]); | ||
} else if (jsonChildren.length > 1) { | ||
var jsxChildren = []; | ||
var allJSXChildrenAreStrings = true; | ||
var jsxChildrenString = ''; | ||
for (var i = 0; i < jsonChildren.length; i++) { | ||
var jsxChild = jsonChildToJSXChild(jsonChildren[i]); | ||
jsxChildren.push(jsxChild); | ||
if (allJSXChildrenAreStrings) { | ||
if (typeof jsxChild === 'string') { | ||
jsxChildrenString += jsxChild; | ||
} else if (jsxChild !== null) { | ||
allJSXChildrenAreStrings = false; | ||
function assertYieldsWereCleared(root) { | ||
if (0 !== root._Scheduler.unstable_clearLog().length) | ||
throw ( | ||
((root = Error( | ||
"Log of yielded values is not empty. Call expect(ReactTestRenderer).unstable_toHaveYielded(...) first." | ||
)), | ||
Error.captureStackTrace(root, assertYieldsWereCleared), | ||
root) | ||
); | ||
assertConsoleLogsCleared(); | ||
} | ||
function createJSXElementForTestComparison(type, props) { | ||
type = { | ||
$$typeof: REACT_ELEMENT_TYPE, | ||
type: type, | ||
key: null, | ||
props: props, | ||
_owner: null, | ||
_store: {} | ||
}; | ||
Object.defineProperty(type, "ref", { enumerable: !1, value: null }); | ||
return type; | ||
} | ||
function jsonChildToJSXChild(jsonChild) { | ||
if (null === jsonChild || "string" === typeof jsonChild) return jsonChild; | ||
var jsxChildren = jsonChildrenToJSXChildren(jsonChild.children); | ||
return createJSXElementForTestComparison( | ||
jsonChild.type, | ||
null === jsxChildren | ||
? jsonChild.props | ||
: assign({}, jsonChild.props, { children: jsxChildren }) | ||
); | ||
} | ||
function jsonChildrenToJSXChildren(jsonChildren) { | ||
if (null !== jsonChildren) { | ||
if (1 === jsonChildren.length) | ||
return jsonChildToJSXChild(jsonChildren[0]); | ||
if (1 < jsonChildren.length) { | ||
for ( | ||
var jsxChildren = [], | ||
allJSXChildrenAreStrings = !0, | ||
jsxChildrenString = "", | ||
i = 0; | ||
i < jsonChildren.length; | ||
i++ | ||
) { | ||
var jsxChild = jsonChildToJSXChild(jsonChildren[i]); | ||
jsxChildren.push(jsxChild); | ||
allJSXChildrenAreStrings && | ||
("string" === typeof jsxChild | ||
? (jsxChildrenString += jsxChild) | ||
: null !== jsxChild && (allJSXChildrenAreStrings = !1)); | ||
} | ||
return allJSXChildrenAreStrings ? jsxChildrenString : jsxChildren; | ||
} | ||
} | ||
return allJSXChildrenAreStrings ? jsxChildrenString : jsxChildren; | ||
return null; | ||
} | ||
} | ||
return null; | ||
} | ||
exports.unstable_toMatchRenderedOutput = unstable_toMatchRenderedOutput; | ||
var assign = Object.assign, | ||
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), | ||
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), | ||
isArrayImpl = Array.isArray, | ||
assertConsoleLogsCleared = | ||
require("internal-test-utils/consoleMock").assertConsoleLogsCleared; | ||
exports.unstable_toMatchRenderedOutput = function (root, expectedJSX) { | ||
assertYieldsWereCleared(root); | ||
root = root.toJSON(); | ||
if (null === root || "string" === typeof root) var actualJSX = root; | ||
else | ||
isArrayImpl(root) | ||
? 0 === root.length | ||
? (actualJSX = null) | ||
: 1 === root.length | ||
? (actualJSX = jsonChildToJSXChild(root[0])) | ||
: ((root = jsonChildrenToJSXChildren(root)), | ||
(actualJSX = | ||
null === root || "string" === typeof root | ||
? root | ||
: createJSXElementForTestComparison(REACT_FRAGMENT_TYPE, { | ||
children: root | ||
}))) | ||
: (actualJSX = jsonChildToJSXChild(root)); | ||
return captureAssertion(function () { | ||
expect(actualJSX).toEqual(expectedJSX); | ||
}); | ||
}; | ||
})(); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/jest-react.production.min.js'); | ||
module.exports = require('./cjs/jest-react.production.js'); | ||
} else { | ||
module.exports = require('./cjs/jest-react.development.js'); | ||
} |
{ | ||
"name": "jest-react", | ||
"version": "0.0.0-experimental-db69f95e4-20231002", | ||
"version": "0.0.0-experimental-db7dfe05-20250319", | ||
"description": "Jest matchers and utilities for testing React components.", | ||
@@ -20,7 +20,7 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://reactjs.org/", | ||
"homepage": "https://react.dev/", | ||
"peerDependencies": { | ||
"jest": "^23.0.1 || ^24.0.0 || ^25.1.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0", | ||
"react": "0.0.0-experimental-db69f95e4-20231002", | ||
"react-test-renderer": "0.0.0-experimental-db69f95e4-20231002" | ||
"react": "0.0.0-experimental-db7dfe05-20250319", | ||
"react-test-renderer": "0.0.0-experimental-db7dfe05-20250319" | ||
}, | ||
@@ -27,0 +27,0 @@ "files": [ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9209
19.13%223
44.81%2
100%1
Infinity%