| 257 | // now because that's how untable_flushUntilNextPaint already worked, but maybe |
| 258 | // we should split these use cases into separate APIs. |
| 259 | export 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 = ` |
| 282 | Expected sequence of events did not occur. |
| 283 | |
| 284 | ${diff(expectedLog, actualLog)} |
| 285 | `; |
| 286 | throw error; |
| 287 | } |
| 288 | |
| 289 | export async function waitForDiscrete(expectedLog) { |
| 290 | assertYieldsWereCleared(waitForDiscrete); |