File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 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 '..'
22import { render } from './helpers/test-utils'
33
44async function runWaitFor ( { time = 300 } = { } , options ) {
@@ -43,6 +43,23 @@ test('fake timer timeout', async () => {
4343 ) . rejects . toMatchInlineSnapshot ( `[Error: always throws]` )
4444} )
4545
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+
4663test ( 'times out after 1000ms by default' , async ( ) => {
4764 const startReal = performance . now ( )
4865 jest . useFakeTimers ( )
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ function waitFor(
2424 stackTraceError,
2525 interval = 50 ,
2626 onTimeout = error => {
27+ if ( getConfig ( ) . defaultOnTimeout ) {
28+ return getConfig ( ) . defaultOnTimeout ( error )
29+ }
2730 Object . defineProperty ( error , 'message' , {
2831 value : getConfig ( ) . getElementError ( error . message , container ) . message ,
2932 } )
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export interface Config {
1414 defaultHidden : boolean
1515 /** default value for the `ignore` option in `ByText` queries */
1616 defaultIgnore : string
17+ defaultOnTimeout ?: ( error : Error ) => Error
1718 showOriginalStackTrace : boolean
1819 throwSuggestions : boolean
1920 getElementError : ( message : string | null , container : Element ) => Error
You can’t perform that action at this time.
0 commit comments