Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2de88c0

Browse files
aryaemami59markerikson
authored andcommitted
Fix skipped tests inssr.spec.tsx
1 parent834f70b commit2de88c0

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
importtype{PayloadAction}from'@reduxjs/toolkit'
23
import{createSlice,createStore}from'@reduxjs/toolkit'
34
import*asrtlfrom'@testing-library/react'
@@ -111,17 +112,18 @@ describe('New v8 serverState behavior', () => {
111112

112113
constSpinner=()=><div/>
113114

114-
if(!IS_REACT_18){
115-
it('Dummy test for React 17, ignore',()=>{})
116-
return
117-
}
118-
119-
constconsoleError=vi.spyOn(console,'error').mockImplementation(()=>{})
115+
constconsoleErrorSpy=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
constssrStore=createStore(dataSlice.reducer)
127129

@@ -154,19 +156,35 @@ describe('New v8 serverState behavior', () => {
154156
<Providerstore={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(/Therewasanerrorwhilehydrating/.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+
/HydrationfailedbecausetheserverrenderedHTMLdidn'tmatchtheclient/,
178+
)
179+
}elseif(IS_REACT_18){
180+
expect(consoleErrorSpy).toHaveBeenCalledTimes(8)
181+
182+
expect(errorArg.message).toMatch(/Therewasanerrorwhilehydrating/)
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
constbutton1=rtl.screen.getByText('useSelector:Hydrated. Count: 1')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp