MCPcopy
hub / github.com/testing-library/react-hooks-testing-library / wait

Function wait

src/core/asyncUtils.ts:17–43  ·  view source on GitHub ↗
(callback: () => boolean | void, { interval, timeout }: WaitOptions)

Source from the content-addressed store, hash-verified

15
16function asyncUtils(act: Act, addResolver: (callback: () => void) => void): AsyncUtils {
17 const wait = async (callback: () => boolean | void, { interval, timeout }: WaitOptions) => {
18 const checkResult = () => {
19 const callbackResult = callback()
20 return callbackResult ?? callbackResult === undefined
21 }
22
23 const timeoutSignal = createTimeoutController(timeout)
24
25 const waitForResult = async () => {
26 while (true) {
27 const intervalSignal = createTimeoutController(interval)
28 timeoutSignal.onTimeout(() => intervalSignal.cancel())
29
30 await intervalSignal.wrap(new Promise<void>(addResolver))
31
32 if (checkResult() || timeoutSignal.timedOut) {
33 return
34 }
35 }
36 }
37
38 if (!checkResult()) {
39 await act(() => timeoutSignal.wrap(waitForResult()))
40 }
41
42 return !timeoutSignal.timedOut
43 }
44
45 const waitFor = async (
46 callback: () => boolean | void,

Callers 3

waitForFunction · 0.85
waitForValueToChangeFunction · 0.85
waitForNextUpdateFunction · 0.85

Calls 3

createTimeoutControllerFunction · 0.90
checkResultFunction · 0.85
waitForResultFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…