Skip to content

Commit c699137

Browse files
committed
feat(waitFor): Support async unstable_advanceTimersWrapper
1 parent 39a64d4 commit c699137

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/wait-for.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ function waitFor(
6767
reject(error)
6868
return
6969
}
70-
// we *could* (maybe should?) use `advanceTimersToNextTimer` but it's
71-
// possible that could make this loop go on forever if someone is using
72-
// third party code that's setting up recursive timers so rapidly that
73-
// the user's timer's don't get a chance to resolve. So we'll advance
74-
// by an interval instead. (We have a test for this case).
75-
advanceTimersWrapper(() => {
70+
71+
// In this rare case, we *need* to wait for in-flight promises
72+
// to resolve before continuing. We don't need to take advantage
73+
// of parallelization so we're fine.
74+
// https://stackoverflow.com/a/59243586/971592
75+
// eslint-disable-next-line no-await-in-loop
76+
await advanceTimersWrapper(async () => {
77+
// we *could* (maybe should?) use `advanceTimersToNextTimer` but it's
78+
// possible that could make this loop go on forever if someone is using
79+
// third party code that's setting up recursive timers so rapidly that
80+
// the user's timer's don't get a chance to resolve. So we'll advance
81+
// by an interval instead. (We have a test for this case).
7682
jest.advanceTimersByTime(interval)
7783
})
7884

@@ -85,18 +91,6 @@ function waitFor(
8591
if (finished) {
8692
break
8793
}
88-
89-
// In this rare case, we *need* to wait for in-flight promises
90-
// to resolve before continuing. We don't need to take advantage
91-
// of parallelization so we're fine.
92-
// https://stackoverflow.com/a/59243586/971592
93-
// eslint-disable-next-line no-await-in-loop
94-
await advanceTimersWrapper(async () => {
95-
await new Promise(r => {
96-
setTimeout(r, 0)
97-
jest.advanceTimersByTime(0)
98-
})
99-
})
10094
}
10195
} else {
10296
try {

0 commit comments

Comments
 (0)