@@ -8,20 +8,20 @@ const isReact19 = React.version.startsWith('19.')
8
8
9
9
const testGateReact19 = isReact19 ? test : test . skip
10
10
11
- test ( 'render errors' , ( ) => {
11
+ test ( 'render errors' , async ( ) => {
12
12
function Thrower ( ) {
13
13
throw new Error ( 'Boom!' )
14
14
}
15
15
16
16
if ( isReact19 ) {
17
- expect ( ( ) => {
18
- render ( < Thrower /> )
17
+ await expect ( async ( ) => {
18
+ await render ( < Thrower /> )
19
19
} ) . toThrow ( 'Boom!' )
20
20
} else {
21
- expect ( ( ) => {
22
- expect ( ( ) => {
23
- render ( < Thrower /> )
24
- } ) . toThrow ( 'Boom!' )
21
+ await expect ( async ( ) => {
22
+ await expect ( async ( ) => {
23
+ await render ( < Thrower /> )
24
+ } ) . rejects . toThrow ( 'Boom!' )
25
25
} ) . toErrorDev ( [
26
26
'Error: Uncaught [Error: Boom!]' ,
27
27
// React retries on error
@@ -30,26 +30,26 @@ test('render errors', () => {
30
30
}
31
31
} )
32
32
33
- test ( 'onUncaughtError is not supported in render' , ( ) => {
33
+ test ( 'onUncaughtError is not supported in render' , async ( ) => {
34
34
function Thrower ( ) {
35
35
throw new Error ( 'Boom!' )
36
36
}
37
37
const onUncaughtError = jest . fn ( ( ) => { } )
38
38
39
- expect ( ( ) => {
40
- render ( < Thrower /> , {
39
+ await expect ( async ( ) => {
40
+ await render ( < Thrower /> , {
41
41
onUncaughtError ( error , errorInfo ) {
42
42
console . log ( { error, errorInfo} )
43
43
} ,
44
44
} )
45
- } ) . toThrow (
45
+ } ) . rejects . toThrow (
46
46
'onUncaughtError is not supported. The `render` call will already throw on uncaught errors.' ,
47
47
)
48
48
49
49
expect ( onUncaughtError ) . toHaveBeenCalledTimes ( 0 )
50
50
} )
51
51
52
- testGateReact19 ( 'onCaughtError is supported in render' , ( ) => {
52
+ testGateReact19 ( 'onCaughtError is supported in render' , async ( ) => {
53
53
const thrownError = new Error ( 'Boom!' )
54
54
const handleComponentDidCatch = jest . fn ( )
55
55
const onCaughtError = jest . fn ( )
@@ -72,7 +72,7 @@ testGateReact19('onCaughtError is supported in render', () => {
72
72
throw thrownError
73
73
}
74
74
75
- render (
75
+ await render (
76
76
< ErrorBoundary >
77
77
< Thrower />
78
78
</ ErrorBoundary > ,
@@ -87,7 +87,7 @@ testGateReact19('onCaughtError is supported in render', () => {
87
87
} )
88
88
} )
89
89
90
- test ( 'onRecoverableError is supported in render' , ( ) => {
90
+ test ( 'onRecoverableError is supported in render' , async ( ) => {
91
91
const onRecoverableError = jest . fn ( )
92
92
93
93
const container = document . createElement ( 'div' )
@@ -96,15 +96,15 @@ test('onRecoverableError is supported in render', () => {
96
96
// Frankly, I'm too lazy to assert on React 18 hydration errors since they're a mess.
97
97
// eslint-disable-next-line jest/no-conditional-in-test
98
98
if ( isReact19 ) {
99
- render ( < div > client</ div > , {
99
+ await render ( < div > client</ div > , {
100
100
container,
101
101
hydrate : true ,
102
102
onRecoverableError,
103
103
} )
104
104
expect ( onRecoverableError ) . toHaveBeenCalledTimes ( 1 )
105
105
} else {
106
- expect ( ( ) => {
107
- render ( < div > client</ div > , {
106
+ await expect ( async ( ) => {
107
+ await render ( < div > client</ div > , {
108
108
container,
109
109
hydrate : true ,
110
110
onRecoverableError,
@@ -114,26 +114,26 @@ test('onRecoverableError is supported in render', () => {
114
114
}
115
115
} )
116
116
117
- test ( 'onUncaughtError is not supported in renderHook' , ( ) => {
117
+ test ( 'onUncaughtError is not supported in renderHook' , async ( ) => {
118
118
function useThrower ( ) {
119
119
throw new Error ( 'Boom!' )
120
120
}
121
121
const onUncaughtError = jest . fn ( ( ) => { } )
122
122
123
- expect ( ( ) => {
124
- renderHook ( useThrower , {
123
+ await expect ( async ( ) => {
124
+ await renderHook ( useThrower , {
125
125
onUncaughtError ( error , errorInfo ) {
126
126
console . log ( { error, errorInfo} )
127
127
} ,
128
128
} )
129
- } ) . toThrow (
129
+ } ) . rejects . toThrow (
130
130
'onUncaughtError is not supported. The `render` call will already throw on uncaught errors.' ,
131
131
)
132
132
133
133
expect ( onUncaughtError ) . toHaveBeenCalledTimes ( 0 )
134
134
} )
135
135
136
- testGateReact19 ( 'onCaughtError is supported in renderHook' , ( ) => {
136
+ testGateReact19 ( 'onCaughtError is supported in renderHook' , async ( ) => {
137
137
const thrownError = new Error ( 'Boom!' )
138
138
const handleComponentDidCatch = jest . fn ( )
139
139
const onCaughtError = jest . fn ( )
@@ -156,7 +156,7 @@ testGateReact19('onCaughtError is supported in renderHook', () => {
156
156
throw thrownError
157
157
}
158
158
159
- renderHook ( useThrower , {
159
+ await renderHook ( useThrower , {
160
160
onCaughtError,
161
161
wrapper : ErrorBoundary ,
162
162
} )
@@ -169,10 +169,10 @@ testGateReact19('onCaughtError is supported in renderHook', () => {
169
169
170
170
// Currently, there's no recoverable error without hydration.
171
171
// The option is still supported though.
172
- test ( 'onRecoverableError is supported in renderHook' , ( ) => {
172
+ test ( 'onRecoverableError is supported in renderHook' , async ( ) => {
173
173
const onRecoverableError = jest . fn ( )
174
174
175
- renderHook (
175
+ await renderHook (
176
176
( ) => {
177
177
// TODO: trigger recoverable error
178
178
} ,
0 commit comments