Skip to content

Commit 2de88c0

Browse files
aryaemami59markerikson
authored andcommitted
Fix skipped tests in ssr.spec.tsx
1 parent 834f70b commit 2de88c0

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

test/integration/ssr.spec.tsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IS_REACT_19 } from '@internal/utils/react-is.js'
12
import type { PayloadAction } from '@reduxjs/toolkit'
23
import { createSlice, createStore } from '@reduxjs/toolkit'
34
import * as rtl from '@testing-library/react'
@@ -111,17 +112,18 @@ describe('New v8 serverState behavior', () => {
111112

112113
const Spinner = () => <div />
113114

114-
if (!IS_REACT_18) {
115-
it('Dummy test for React 17, ignore', () => {})
116-
return
117-
}
118-
119-
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
115+
const consoleErrorSpy = vi
116+
.spyOn(console, 'error')
117+
.mockImplementation(() => {})
120118

121119
afterEach(() => {
122120
vi.clearAllMocks()
123121
})
124122

123+
afterAll(() => {
124+
vi.restoreAllMocks()
125+
})
126+
125127
it('Handles hydration correctly', async () => {
126128
const ssrStore = createStore(dataSlice.reducer)
127129

@@ -154,19 +156,35 @@ describe('New v8 serverState behavior', () => {
154156
<Provider store={clientStore}>
155157
<App />
156158
</Provider>,
159+
{
160+
onRecoverableError: IS_REACT_19
161+
? (error, errorInfo) => {
162+
console.error(error)
163+
}
164+
: undefined,
165+
},
157166
)
158167
})
159168

160-
const [lastCall = []] = consoleError.mock.calls.slice(-1)
169+
const { lastCall = [] } = consoleErrorSpy.mock
161170
const [errorArg] = lastCall
162171
expect(errorArg).toBeInstanceOf(Error)
163-
expect(/There was an error while hydrating/.test(errorArg.message)).toBe(
164-
true,
165-
)
166172

167-
vi.resetAllMocks()
173+
if (IS_REACT_19) {
174+
expect(consoleErrorSpy).toHaveBeenCalledOnce()
175+
176+
expect(errorArg.message).toMatch(
177+
/Hydration failed because the server rendered HTML didn't match the client/,
178+
)
179+
} else if (IS_REACT_18) {
180+
expect(consoleErrorSpy).toHaveBeenCalledTimes(8)
181+
182+
expect(errorArg.message).toMatch(/There was an error while hydrating/)
183+
}
184+
185+
vi.clearAllMocks()
168186

169-
expect(consoleError.mock.calls.length).toBe(0)
187+
expect(consoleErrorSpy).not.toHaveBeenCalled()
170188

171189
document.body.removeChild(rootDiv)
172190

@@ -187,7 +205,7 @@ describe('New v8 serverState behavior', () => {
187205
)
188206
})
189207

190-
expect(consoleError.mock.calls.length).toBe(0)
208+
expect(consoleErrorSpy).not.toHaveBeenCalled()
191209

192210
// Buttons should both exist, and have the updated count due to later render
193211
const button1 = rtl.screen.getByText('useSelector:Hydrated. Count: 1')

0 commit comments

Comments
 (0)