Skip to content

Commit 1ddafa2

Browse files
committed
Disable interval checking by default
1 parent 42cba7e commit 1ddafa2

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

docs/api-reference.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ in the callback to perform assertion or to test values.
181181
#### `interval`
182182

183183
The amount of time in milliseconds (ms) to wait between checks of the callback if no renders occur.
184-
By default, an interval of 50ms is used.
184+
Interval checking is disabled if `interval` is not provided in the options or provided as a `falsy`
185+
value. By default, it is disabled.
185186

186187
#### `timeout`
187188

@@ -210,7 +211,8 @@ comparison.
210211
#### `interval`
211212

212213
The amount of time in milliseconds (ms) to wait between checks of the callback if no renders occur.
213-
By default, an interval of 50ms is used.
214+
Interval checking is disabled if `interval` is not provided in the options or provided as a `falsy`
215+
value. By default, it is disabled.
214216

215217
#### `timeout`
216218

src/asyncUtils.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function asyncUtils(addResolver) {
3838
await nextUpdatePromise
3939
}
4040

41-
const waitFor = async (callback, { interval = 50, timeout, suppressErrors = true } = {}) => {
41+
const waitFor = async (callback, { interval, timeout, suppressErrors = true } = {}) => {
4242
const checkResult = () => {
4343
try {
4444
const callbackResult = callback()
@@ -55,7 +55,12 @@ function asyncUtils(addResolver) {
5555
while (true) {
5656
const startTime = Date.now()
5757
try {
58-
await Promise.race([waitForNextUpdate({ timeout }), resolveAfter(interval)])
58+
const nextCheck = interval
59+
? Promise.race([waitForNextUpdate({ timeout }), resolveAfter(interval)])
60+
: waitForNextUpdate({ timeout })
61+
62+
await nextCheck
63+
5964
if (checkResult()) {
6065
return
6166
}

test/asyncHook.test.js

-22
Original file line numberDiff line numberDiff line change
@@ -280,28 +280,6 @@ describe('async hook tests', () => {
280280
expect(complete).toBe(true)
281281
})
282282

283-
test('should wait for arbitrary expectation to pass (deprecated)', async () => {
284-
const { wait } = renderHook(() => null)
285-
286-
let actual = 0
287-
let expected = 1
288-
289-
setTimeout(() => {
290-
actual = expected
291-
}, 200)
292-
293-
let complete = false
294-
await wait(
295-
() => {
296-
expect(actual).toBe(expected)
297-
complete = true
298-
},
299-
{ interval: 100 }
300-
)
301-
302-
expect(complete).toBe(true)
303-
})
304-
305283
test('should not hang if expectation is already passing (deprecated)', async () => {
306284
const { result, wait } = renderHook(() => useSequence('first', 'second'))
307285

0 commit comments

Comments
 (0)