@@ -111,15 +111,16 @@ describe('New v8 serverState behavior', () => {
111111
112112 const Spinner = ( ) => < div />
113113
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 ( ( ) => { } )
120117
121118 afterEach ( ( ) => {
122- vi . clearAllMocks ( )
119+ consoleErrorSpy . mockClear ( )
120+ } )
121+
122+ afterAll ( ( ) => {
123+ consoleErrorSpy . mockRestore ( )
123124 } )
124125
125126 it ( 'Handles hydration correctly' , async ( ) => {
@@ -154,19 +155,21 @@ describe('New v8 serverState behavior', () => {
154155 < Provider store = { clientStore } >
155156 < App />
156157 </ Provider > ,
158+ {
159+ onRecoverableError : ( error , errorInfo ) => {
160+ console . error ( 'Hydration error' )
161+ } ,
162+ } ,
157163 )
158164 } )
159165
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' )
166169
167- vi . resetAllMocks ( )
170+ consoleErrorSpy . mockClear ( )
168171
169- expect ( consoleError . mock . calls . length ) . toBe ( 0 )
172+ expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( )
170173
171174 document . body . removeChild ( rootDiv )
172175
@@ -187,7 +190,7 @@ describe('New v8 serverState behavior', () => {
187190 )
188191 } )
189192
190- expect ( consoleError . mock . calls . length ) . toBe ( 0 )
193+ expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( )
191194
192195 // Buttons should both exist, and have the updated count due to later render
193196 const button1 = rtl . screen . getByText ( 'useSelector:Hydrated. Count: 1' )
0 commit comments