@@ -111,15 +111,16 @@ describe('New v8 serverState behavior', () => {
111
111
112
112
const Spinner = ( ) => < div />
113
113
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 ( ( ) => { } )
114
+ const consoleErrorSpy = vi
115
+ . spyOn ( console , 'error' )
116
+ . mockImplementation ( ( ) => { } )
120
117
121
118
afterEach ( ( ) => {
122
- vi . clearAllMocks ( )
119
+ consoleErrorSpy . mockClear ( )
120
+ } )
121
+
122
+ afterAll ( ( ) => {
123
+ consoleErrorSpy . mockRestore ( )
123
124
} )
124
125
125
126
it ( 'Handles hydration correctly' , async ( ) => {
@@ -154,19 +155,21 @@ describe('New v8 serverState behavior', () => {
154
155
< Provider store = { clientStore } >
155
156
< App />
156
157
</ Provider > ,
158
+ {
159
+ onRecoverableError : ( error , errorInfo ) => {
160
+ console . error ( 'Hydration error' )
161
+ } ,
162
+ } ,
157
163
)
158
164
} )
159
165
160
- const [ lastCall = [ ] ] = consoleError . mock . calls . slice ( - 1 )
161
- const [ errorArg ] = lastCall
162
- expect ( errorArg ) . toBeInstanceOf ( Error )
163
- expect ( / T h e r e w a s a n e r r o r w h i l e h y d r a t i n g / . test ( errorArg . message ) ) . toBe (
164
- true ,
165
- )
166
+ expect ( consoleErrorSpy ) . toHaveBeenCalledOnce ( )
167
+
168
+ expect ( consoleErrorSpy ) . toHaveBeenLastCalledWith ( 'Hydration error' )
166
169
167
- vi . resetAllMocks ( )
170
+ consoleErrorSpy . mockClear ( )
168
171
169
- expect ( consoleError . mock . calls . length ) . toBe ( 0 )
172
+ expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( )
170
173
171
174
document . body . removeChild ( rootDiv )
172
175
@@ -187,7 +190,7 @@ describe('New v8 serverState behavior', () => {
187
190
)
188
191
} )
189
192
190
- expect ( consoleError . mock . calls . length ) . toBe ( 0 )
193
+ expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( )
191
194
192
195
// Buttons should both exist, and have the updated count due to later render
193
196
const button1 = rtl . screen . getByText ( 'useSelector:Hydrated. Count: 1' )
0 commit comments