| 90 | } |
| 91 | |
| 92 | export async function waitForAll(expectedLog) { |
| 93 | assertYieldsWereCleared(waitForAll); |
| 94 | |
| 95 | class="cm">// Create the error object before doing any async work, to get a better |
| 96 | class="cm">// stack trace. |
| 97 | const error = new Error(); |
| 98 | Error.captureStackTrace(error, waitForAll); |
| 99 | |
| 100 | do { |
| 101 | class="cm">// Wait until end of current task/microtask. |
| 102 | await waitForMicrotasks(); |
| 103 | if (!SchedulerMock.unstable_hasPendingWork()) { |
| 104 | class="cm">// There's no pending work, even after a microtask. Stop flushing. |
| 105 | break; |
| 106 | } |
| 107 | SchedulerMock.unstable_flushAllWithoutAsserting(); |
| 108 | } while (true); |
| 109 | |
| 110 | const actualLog = SchedulerMock.unstable_clearLog(); |
| 111 | if (equals(actualLog, expectedLog)) { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | error.message = ` |
| 116 | Expected sequence of events did not occur. |
| 117 | |
| 118 | ${diff(expectedLog, actualLog)} |
| 119 | `; |
| 120 | throw error; |
| 121 | } |
| 122 | |
| 123 | function aggregateErrors(errors: Array<mixed>): mixed { |
| 124 | if (errors.length > 1 && typeof AggregateError === class="st">'function') { |