From e39eb77cb9ce1e9130d47f081977b0f926db38ab Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Thu, 16 May 2024 09:56:44 -0500 Subject: [PATCH] Fix skipped tests in `ssr.spec.tsx` --- test/integration/ssr.spec.tsx | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) 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')