Skip to content

Commit a20aa57

Browse files
committed
fix wait-for
1 parent 4abf85f commit a20aa57

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/wait-for.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
// an environment that's faked the timers out.
1010
checkContainerType,
1111
} from './dtlHelpers'
12+
import act, {asyncAct} from './act-compat'
1213

1314
// Not supported for external libraries. Only supported internally in @testing-library/dom
1415
function runWithExpensiveErrorDiagnosticsDisabled(callback) {
@@ -77,7 +78,9 @@ function waitFor(
7778
// third party code that's setting up recursive timers so rapidly that
7879
// the user's timer's don't get a chance to resolve. So we'll advance
7980
// by an interval instead. (We have a test for this case).
80-
jest.advanceTimersByTime(interval)
81+
act(() => {
82+
jest.advanceTimersByTime(interval)
83+
})
8184

8285
// It's really important that checkCallback is run *before* we flush
8386
// in-flight promises. To be honest, I'm not sure why, and I can't quite
@@ -90,9 +93,11 @@ function waitFor(
9093
// of parallelization so we're fine.
9194
// https://stackoverflow.com/a/59243586/971592
9295
// eslint-disable-next-line no-await-in-loop
93-
await new Promise(r => {
94-
setTimeout(r, 0)
95-
jest.advanceTimersByTime(0)
96+
await asyncAct(async () => {
97+
await new Promise(r => {
98+
setTimeout(r, 0)
99+
jest.advanceTimersByTime(0)
100+
})
96101
})
97102
}
98103
} else {

0 commit comments

Comments
 (0)