1
- import { waitFor , waitForElementToBeRemoved } from '..'
1
+ import { configure , getConfig , waitFor , waitForElementToBeRemoved } from '..'
2
2
import { render } from './helpers/test-utils'
3
3
4
4
async function runWaitFor ( { time = 300 } = { } , options ) {
@@ -11,8 +11,14 @@ async function runWaitFor({time = 300} = {}, options) {
11
11
await waitFor ( ( ) => expect ( result ) . toBe ( response ) , options )
12
12
}
13
13
14
+ let originalConfig
15
+ beforeAll ( ( ) => {
16
+ originalConfig = getConfig ( )
17
+ } )
18
+
14
19
afterEach ( ( ) => {
15
20
jest . useRealTimers ( )
21
+ configure ( originalConfig )
16
22
} )
17
23
18
24
test ( 'real timers' , async ( ) => {
@@ -43,6 +49,23 @@ test('fake timer timeout', async () => {
43
49
) . rejects . toMatchInlineSnapshot ( `[Error: always throws]` )
44
50
} )
45
51
52
+ test ( 'fake timer timeout uses default ontimeout' , async ( ) => {
53
+ configure ( {
54
+ defaultOnTimeout : _ => {
55
+ return Error ( 'Test Error' )
56
+ } ,
57
+ } )
58
+ jest . useFakeTimers ( )
59
+ await expect (
60
+ waitFor (
61
+ ( ) => {
62
+ throw new Error ( 'always throws' )
63
+ } ,
64
+ { timeout : 10 } ,
65
+ ) ,
66
+ ) . rejects . toMatchInlineSnapshot ( `[Error: Test Error]` )
67
+ } )
68
+
46
69
test ( 'times out after 1000ms by default' , async ( ) => {
47
70
const startReal = performance . now ( )
48
71
jest . useFakeTimers ( )
0 commit comments