@@ -7,8 +7,8 @@ export interface WaitOptions {
7
7
}
8
8
9
9
class TimeoutError extends Error {
10
- constructor ( utilName : string , { timeout } : Pick < WaitOptions , 'timeout' > ) {
11
- super ( `Timed out in ${ utilName } after ${ timeout as number } ms.` )
10
+ constructor ( utilName : string , timeout : number ) {
11
+ super ( `Timed out in ${ utilName } after ${ timeout } ms.` )
12
12
}
13
13
}
14
14
@@ -21,14 +21,14 @@ function resolveAfter(ms: number) {
21
21
function asyncUtils ( addResolver : ( callback : ( ) => void ) => void ) {
22
22
let nextUpdatePromise : Promise < void > | null = null
23
23
24
- const waitForNextUpdate = async ( options : Pick < WaitOptions , 'timeout' > = { } ) => {
24
+ const waitForNextUpdate = async ( { timeout } : Pick < WaitOptions , 'timeout' > = { } ) => {
25
25
if ( ! nextUpdatePromise ) {
26
26
nextUpdatePromise = new Promise ( ( resolve , reject ) => {
27
27
let timeoutId : ReturnType < typeof setTimeout >
28
- if ( options . timeout && options . timeout > 0 ) {
28
+ if ( timeout && timeout > 0 ) {
29
29
timeoutId = setTimeout (
30
- ( ) => reject ( new TimeoutError ( 'waitForNextUpdate' , options ) ) ,
31
- options . timeout
30
+ ( ) => reject ( new TimeoutError ( 'waitForNextUpdate' , timeout ) ) ,
31
+ timeout
32
32
)
33
33
}
34
34
addResolver ( ( ) => {
@@ -73,8 +73,8 @@ function asyncUtils(addResolver: (callback: () => void) => void) {
73
73
return
74
74
}
75
75
} catch ( error : unknown ) {
76
- if ( error instanceof TimeoutError ) {
77
- throw new TimeoutError ( 'waitFor' , { timeout : initialTimeout } )
76
+ if ( error instanceof TimeoutError && initialTimeout ) {
77
+ throw new TimeoutError ( 'waitFor' , initialTimeout )
78
78
}
79
79
throw error as Error
80
80
}
@@ -95,8 +95,8 @@ function asyncUtils(addResolver: (callback: () => void) => void) {
95
95
...options
96
96
} )
97
97
} catch ( error : unknown ) {
98
- if ( error instanceof TimeoutError ) {
99
- throw new TimeoutError ( 'waitForValueToChange' , options )
98
+ if ( error instanceof TimeoutError && options . timeout ) {
99
+ throw new TimeoutError ( 'waitForValueToChange' , options . timeout )
100
100
}
101
101
throw error as Error
102
102
}
0 commit comments