Skip to content

Commit 49f4338

Browse files
committed
Apply codemod
1 parent 82ee012 commit 49f4338

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

Diff for: src/__tests__/error-handlers.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ const isReact19 = React.version.startsWith('19.')
88

99
const testGateReact19 = isReact19 ? test : test.skip
1010

11-
test('render errors', () => {
11+
test('render errors', async () => {
1212
function Thrower() {
1313
throw new Error('Boom!')
1414
}
1515

1616
if (isReact19) {
17-
expect(() => {
18-
render(<Thrower />)
17+
await expect(async () => {
18+
await render(<Thrower />)
1919
}).toThrow('Boom!')
2020
} 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!')
2525
}).toErrorDev([
2626
'Error: Uncaught [Error: Boom!]',
2727
// React retries on error
@@ -30,26 +30,26 @@ test('render errors', () => {
3030
}
3131
})
3232

33-
test('onUncaughtError is not supported in render', () => {
33+
test('onUncaughtError is not supported in render', async () => {
3434
function Thrower() {
3535
throw new Error('Boom!')
3636
}
3737
const onUncaughtError = jest.fn(() => {})
3838

39-
expect(() => {
40-
render(<Thrower />, {
39+
await expect(async () => {
40+
await render(<Thrower />, {
4141
onUncaughtError(error, errorInfo) {
4242
console.log({error, errorInfo})
4343
},
4444
})
45-
}).toThrow(
45+
}).rejects.toThrow(
4646
'onUncaughtError is not supported. The `render` call will already throw on uncaught errors.',
4747
)
4848

4949
expect(onUncaughtError).toHaveBeenCalledTimes(0)
5050
})
5151

52-
testGateReact19('onCaughtError is supported in render', () => {
52+
testGateReact19('onCaughtError is supported in render', async () => {
5353
const thrownError = new Error('Boom!')
5454
const handleComponentDidCatch = jest.fn()
5555
const onCaughtError = jest.fn()
@@ -72,7 +72,7 @@ testGateReact19('onCaughtError is supported in render', () => {
7272
throw thrownError
7373
}
7474

75-
render(
75+
await render(
7676
<ErrorBoundary>
7777
<Thrower />
7878
</ErrorBoundary>,
@@ -87,7 +87,7 @@ testGateReact19('onCaughtError is supported in render', () => {
8787
})
8888
})
8989

90-
test('onRecoverableError is supported in render', () => {
90+
test('onRecoverableError is supported in render', async () => {
9191
const onRecoverableError = jest.fn()
9292

9393
const container = document.createElement('div')
@@ -96,15 +96,15 @@ test('onRecoverableError is supported in render', () => {
9696
// Frankly, I'm too lazy to assert on React 18 hydration errors since they're a mess.
9797
// eslint-disable-next-line jest/no-conditional-in-test
9898
if (isReact19) {
99-
render(<div>client</div>, {
99+
await render(<div>client</div>, {
100100
container,
101101
hydrate: true,
102102
onRecoverableError,
103103
})
104104
expect(onRecoverableError).toHaveBeenCalledTimes(1)
105105
} else {
106-
expect(() => {
107-
render(<div>client</div>, {
106+
await expect(async () => {
107+
await render(<div>client</div>, {
108108
container,
109109
hydrate: true,
110110
onRecoverableError,
@@ -114,26 +114,26 @@ test('onRecoverableError is supported in render', () => {
114114
}
115115
})
116116

117-
test('onUncaughtError is not supported in renderHook', () => {
117+
test('onUncaughtError is not supported in renderHook', async () => {
118118
function useThrower() {
119119
throw new Error('Boom!')
120120
}
121121
const onUncaughtError = jest.fn(() => {})
122122

123-
expect(() => {
124-
renderHook(useThrower, {
123+
await expect(async () => {
124+
await renderHook(useThrower, {
125125
onUncaughtError(error, errorInfo) {
126126
console.log({error, errorInfo})
127127
},
128128
})
129-
}).toThrow(
129+
}).rejects.toThrow(
130130
'onUncaughtError is not supported. The `render` call will already throw on uncaught errors.',
131131
)
132132

133133
expect(onUncaughtError).toHaveBeenCalledTimes(0)
134134
})
135135

136-
testGateReact19('onCaughtError is supported in renderHook', () => {
136+
testGateReact19('onCaughtError is supported in renderHook', async () => {
137137
const thrownError = new Error('Boom!')
138138
const handleComponentDidCatch = jest.fn()
139139
const onCaughtError = jest.fn()
@@ -156,7 +156,7 @@ testGateReact19('onCaughtError is supported in renderHook', () => {
156156
throw thrownError
157157
}
158158

159-
renderHook(useThrower, {
159+
await renderHook(useThrower, {
160160
onCaughtError,
161161
wrapper: ErrorBoundary,
162162
})
@@ -169,10 +169,10 @@ testGateReact19('onCaughtError is supported in renderHook', () => {
169169

170170
// Currently, there's no recoverable error without hydration.
171171
// The option is still supported though.
172-
test('onRecoverableError is supported in renderHook', () => {
172+
test('onRecoverableError is supported in renderHook', async () => {
173173
const onRecoverableError = jest.fn()
174174

175-
renderHook(
175+
await renderHook(
176176
() => {
177177
// TODO: trigger recoverable error
178178
},

0 commit comments

Comments
 (0)