Skip to content

Commit dd93cb1

Browse files
committed
test: fix React hooks rule violation in useHistoryState error test
Remove try-catch around hook call and use router's default error boundary
1 parent 50a7dba commit dd93cb1

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

packages/react-router/tests/useHistoryState.test.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,16 @@ describe('useHistoryState', () => {
209209

210210
test('throws when match not found and shouldThrow=true', async () => {
211211
function RootComponent() {
212-
try {
213-
useHistoryState({ from: '/non-existent', shouldThrow: true })
214-
return <div>No error</div>
215-
} catch (e) {
216-
return <div>Error occurred: {(e as Error).message}</div>
217-
}
212+
useHistoryState({ from: '/non-existent', shouldThrow: true })
213+
return <div>No error</div>
218214
}
219215

220216
setup({ RootComponent })
221217

222-
const errorMessage = await screen.findByText(/Error occurred:/)
218+
const errorMessage = await screen.findByText(
219+
'Invariant failed: Could not find an active match from "/non-existent"',
220+
)
223221
expect(errorMessage).toBeInTheDocument()
224-
expect(errorMessage).toHaveTextContent(/Could not find an active match/)
225222
})
226223

227224
test('returns undefined when match not found and shouldThrow=false', async () => {

0 commit comments

Comments
 (0)