diff --git a/test/integration/ssr.spec.tsx b/test/integration/ssr.spec.tsx
index cb3424874..578417bb6 100644
--- a/test/integration/ssr.spec.tsx
+++ b/test/integration/ssr.spec.tsx
@@ -111,15 +111,16 @@ describe('New v8 serverState behavior', () => {
const Spinner = () =>
- if (!IS_REACT_18) {
- it('Dummy test for React 17, ignore', () => {})
- return
- }
-
- const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
+ const consoleErrorSpy = vi
+ .spyOn(console, 'error')
+ .mockImplementation(() => {})
afterEach(() => {
- vi.clearAllMocks()
+ consoleErrorSpy.mockClear()
+ })
+
+ afterAll(() => {
+ consoleErrorSpy.mockRestore()
})
it('Handles hydration correctly', async () => {
@@ -154,19 +155,21 @@ describe('New v8 serverState behavior', () => {
,
+ {
+ onRecoverableError: (error, errorInfo) => {
+ console.error('Hydration error')
+ },
+ },
)
})
- const [lastCall = []] = consoleError.mock.calls.slice(-1)
- const [errorArg] = lastCall
- expect(errorArg).toBeInstanceOf(Error)
- expect(/There was an error while hydrating/.test(errorArg.message)).toBe(
- true,
- )
+ expect(consoleErrorSpy).toHaveBeenCalledOnce()
+
+ expect(consoleErrorSpy).toHaveBeenLastCalledWith('Hydration error')
- vi.resetAllMocks()
+ consoleErrorSpy.mockClear()
- expect(consoleError.mock.calls.length).toBe(0)
+ expect(consoleErrorSpy).not.toHaveBeenCalled()
document.body.removeChild(rootDiv)
@@ -187,7 +190,7 @@ describe('New v8 serverState behavior', () => {
)
})
- expect(consoleError.mock.calls.length).toBe(0)
+ expect(consoleErrorSpy).not.toHaveBeenCalled()
// Buttons should both exist, and have the updated count due to later render
const button1 = rtl.screen.getByText('useSelector:Hydrated. Count: 1')