1export const waitFor = (callback, { interval = 50, timeout = 1000 } = {}) =>
2 act(
3 () =>
4 new Promise((resolve, reject) => {
5 const startTime = Date.now()
6
7 const nextInterval = () => {
8 setTimeout(() => {
9 try {
10 callback()
11 resolve()
12 } catch (err) {
13 if (Date.now() - startTime > timeout) {
14 reject(new Error('Timed out.'))
15 } else {
16 nextInterval()
17 }
18 }
19 }, interval)
20 }
21
22 nextInterval()
23 }),
24 )