@@ -10,8 +10,13 @@ import {
1010import { resolveAfter , callAfter } from '../helpers/promises'
1111import { TimeoutError } from '../helpers/error'
1212
13- const DEFAULT_INTERVAL = 50
14- const DEFAULT_TIMEOUT = 1000
13+ let defaultInterval : number | false = 50
14+ let defaultTimeout : number | false = 1000
15+
16+ function setDefaultWaitOptions ( { interval, timeout } : WaitOptions ) {
17+ defaultInterval = interval ?? defaultInterval
18+ defaultTimeout = timeout ?? defaultTimeout
19+ }
1520
1621function asyncUtils ( act : Act , addResolver : ( callback : ( ) => void ) => void ) : AsyncUtils {
1722 const wait = async ( callback : ( ) => boolean | void , { interval, timeout } : WaitOptions ) => {
@@ -55,7 +60,7 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn
5560
5661 const waitFor = async (
5762 callback : ( ) => boolean | void ,
58- { interval = DEFAULT_INTERVAL , timeout = DEFAULT_TIMEOUT } : WaitForOptions = { }
63+ { interval = defaultInterval , timeout = defaultTimeout } : WaitForOptions = { }
5964 ) => {
6065 const safeCallback = ( ) => {
6166 try {
@@ -73,7 +78,7 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn
7378
7479 const waitForValueToChange = async (
7580 selector : ( ) => unknown ,
76- { interval = DEFAULT_INTERVAL , timeout = DEFAULT_TIMEOUT } : WaitForValueToChangeOptions = { }
81+ { interval = defaultInterval , timeout = defaultTimeout } : WaitForValueToChangeOptions = { }
7782 ) => {
7883 const initialValue = selector ( )
7984
@@ -83,9 +88,7 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn
8388 }
8489 }
8590
86- const waitForNextUpdate = async ( {
87- timeout = DEFAULT_TIMEOUT
88- } : WaitForNextUpdateOptions = { } ) => {
91+ const waitForNextUpdate = async ( { timeout = defaultTimeout } : WaitForNextUpdateOptions = { } ) => {
8992 let updated = false
9093 addResolver ( ( ) => {
9194 updated = true
@@ -104,4 +107,4 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn
104107 }
105108}
106109
107- export { asyncUtils }
110+ export { asyncUtils , setDefaultWaitOptions }
0 commit comments