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

Function act

packages/react-dom/src/__tests__/ReactDOMFizzStatic-test.js:65–97  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

63 });
64
65 async function act(callback) {
66 await callback();
67 // Await one turn around the event loop.
68 // This assumes that we'll flush everything we have so far.
69 await new Promise(resolve => {
70 setImmediate(resolve);
71 });
72 if (hasErrored) {
73 throw fatalError;
74 }
75 // JSDOM doesn't support stream HTML parser so we need to give it a proper fragment.
76 // We also want to execute any scripts that are embedded.
77 // We assume that we have now received a proper fragment of HTML.
78 const bufferedContent = buffer;
79 buffer = '';
80 const fakeBody = document.createElement('body');
81 fakeBody.innerHTML = bufferedContent;
82 while (fakeBody.firstChild) {
83 const node = fakeBody.firstChild;
84 if (node.nodeName === 'SCRIPT') {
85 const script = document.createElement('script');
86 script.textContent = node.textContent;
87 for (let i = 0; i < node.attributes.length; i++) {
88 const attribute = node.attributes[i];
89 script.setAttribute(attribute.name, attribute.value);
90 }
91 fakeBody.removeChild(node);
92 container.appendChild(script);
93 } else {
94 container.appendChild(node);
95 }
96 }
97 }
98
99 function getVisibleChildren(element) {
100 const children = [];

Callers 1

Calls 1

callbackFunction · 0.50

Tested by

no test coverage detected