1+ import { IS_REACT_19 } from '@internal/utils/react-is.js'
12import type { PayloadAction } from '@reduxjs/toolkit'
23import { createSlice , createStore } from '@reduxjs/toolkit'
34import * as rtl from '@testing-library/react'
@@ -111,17 +112,18 @@ describe('New v8 serverState behavior', () => {
111112
112113const 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
121119afterEach ( ( ) => {
122120vi . clearAllMocks ( )
123121} )
124122
123+ afterAll ( ( ) => {
124+ vi . restoreAllMocks ( )
125+ } )
126+
125127it ( 'Handles hydration correctly' , async ( ) => {
126128const 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
161170const [ errorArg ] = lastCall
162171expect ( 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- )
166172
167- vi . resetAllMocks ( )
173+ if ( IS_REACT_19 ) {
174+ expect ( consoleErrorSpy ) . toHaveBeenCalledOnce ( )
175+
176+ expect ( errorArg . message ) . toMatch (
177+ / H y d r a t i o n f a i l e d b e c a u s e t h e s e r v e r r e n d e r e d H T M L d i d n ' t m a t c h t h e c l i e n t / ,
178+ )
179+ } else if ( IS_REACT_18 ) {
180+ expect ( consoleErrorSpy ) . toHaveBeenCalledTimes ( 8 )
181+
182+ expect ( errorArg . message ) . toMatch ( / 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 / )
183+ }
184+
185+ vi . clearAllMocks ( )
168186
169- expect ( consoleError . mock . calls . length ) . toBe ( 0 )
187+ expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( )
170188
171189document . 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
193211const button1 = rtl . screen . getByText ( 'useSelector:Hydrated. Count: 1' )