MCPcopy
hub / github.com/facebook/react / unstable_toMatchRenderedOutput

Function unstable_toMatchRenderedOutput

packages/jest-react/src/JestReact.js:69–98  ·  view source on GitHub ↗
(root, expectedJSX)

Source from the content-addressed store, hash-verified

67}
68
69export function unstable_toMatchRenderedOutput(root, expectedJSX) {
70 assertYieldsWereCleared(root);
71 const actualJSON = root.toJSON();
72
73 let actualJSX;
74 if (actualJSON === null || typeof actualJSON === 'string') {
75 actualJSX = actualJSON;
76 } else if (isArray(actualJSON)) {
77 if (actualJSON.length === 0) {
78 actualJSX = null;
79 } else if (actualJSON.length === 1) {
80 actualJSX = jsonChildToJSXChild(actualJSON[0]);
81 } else {
82 const actualJSXChildren = jsonChildrenToJSXChildren(actualJSON);
83 if (actualJSXChildren === null || typeof actualJSXChildren === 'string') {
84 actualJSX = actualJSXChildren;
85 } else {
86 actualJSX = createJSXElementForTestComparison(REACT_FRAGMENT_TYPE, {
87 children: actualJSXChildren,
88 });
89 }
90 }
91 } else {
92 actualJSX = jsonChildToJSXChild(actualJSON);
93 }
94
95 return captureAssertion(() => {
96 expect(actualJSX).toEqual(expectedJSX);
97 });
98}
99
100function jsonChildToJSXChild(jsonChild) {
101 if (jsonChild === null || typeof jsonChild === 'string') {

Callers

nothing calls this directly

Calls 8

isArrayFunction · 0.85
jsonChildToJSXChildFunction · 0.85
toJSONMethod · 0.80
assertYieldsWereClearedFunction · 0.70
captureAssertionFunction · 0.70
toEqualMethod · 0.65

Tested by

no test coverage detected