File tree 3 files changed +22
-1
lines changed
3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
- import { waitFor , waitForElementToBeRemoved } from '..'
1
+ import { configure , waitFor , waitForElementToBeRemoved } from '..'
2
2
import { render } from './helpers/test-utils'
3
3
4
4
async function runWaitFor ( { time = 300 } = { } , options ) {
@@ -43,6 +43,23 @@ test('fake timer timeout', async () => {
43
43
) . rejects . toMatchInlineSnapshot ( `[Error: always throws]` )
44
44
} )
45
45
46
+ test ( 'fake timer timeout uses default ontimeout' , async ( ) => {
47
+ configure ( {
48
+ defaultOnTimeout : _ => {
49
+ return Error ( 'Test Error' )
50
+ } ,
51
+ } )
52
+ jest . useFakeTimers ( )
53
+ await expect (
54
+ waitFor (
55
+ ( ) => {
56
+ throw new Error ( 'always throws' )
57
+ } ,
58
+ { timeout : 10 } ,
59
+ ) ,
60
+ ) . rejects . toMatchInlineSnapshot ( `[Error: Test Error]` )
61
+ } )
62
+
46
63
test ( 'times out after 1000ms by default' , async ( ) => {
47
64
const startReal = performance . now ( )
48
65
jest . useFakeTimers ( )
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ function waitFor(
24
24
stackTraceError,
25
25
interval = 50 ,
26
26
onTimeout = error => {
27
+ if ( getConfig ( ) . defaultOnTimeout ) {
28
+ return getConfig ( ) . defaultOnTimeout ( error )
29
+ }
27
30
Object . defineProperty ( error , 'message' , {
28
31
value : getConfig ( ) . getElementError ( error . message , container ) . message ,
29
32
} )
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export interface Config {
14
14
defaultHidden : boolean
15
15
/** default value for the `ignore` option in `ByText` queries */
16
16
defaultIgnore : string
17
+ defaultOnTimeout ?: ( error : Error ) => Error
17
18
showOriginalStackTrace : boolean
18
19
throwSuggestions : boolean
19
20
getElementError : ( message : string | null , container : Element ) => Error
You can’t perform that action at this time.
0 commit comments