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

Function waitForPaint

packages/internal-test-utils/ReactInternalTestUtils.js:259–287  ·  view source on GitHub ↗
(expectedLog)

Source from the content-addressed store, hash-verified

257// now because that's how untable_flushUntilNextPaint already worked, but maybe
258// we should split these use cases into separate APIs.
259export async function waitForPaint(expectedLog) {
260 assertYieldsWereCleared(waitForPaint);
261
262 // Create the error object before doing any async work, to get a better
263 // stack trace.
264 const error = new Error();
265 Error.captureStackTrace(error, waitForPaint);
266
267 // Wait until end of current task/microtask.
268 await waitForMicrotasks();
269 if (SchedulerMock.unstable_hasPendingWork()) {
270 // Flush until React yields.
271 SchedulerMock.unstable_flushUntilNextPaint();
272 // Wait one more microtask to flush any remaining synchronous work.
273 await waitForMicrotasks();
274 }
275
276 const actualLog = SchedulerMock.unstable_clearLog();
277 if (equals(actualLog, expectedLog)) {
278 return;
279 }
280
281 error.message = `
282Expected sequence of events did not occur.
283
284${diff(expectedLog, actualLog)}
285`;
286 throw error;
287}
288
289export async function waitForDiscrete(expectedLog) {
290 assertYieldsWereCleared(waitForDiscrete);

Calls 3

assertYieldsWereClearedFunction · 0.70
waitForMicrotasksFunction · 0.70
diffFunction · 0.50

Tested by 2

ChildFunction · 0.68
ChildFunction · 0.68