1+ import { trackForMutations } from '@internal/immutableStateInvariantMiddleware'
2+ import { noop } from '@internal/listenerMiddleware/utils'
13import type {
2- Store ,
3- MiddlewareAPI ,
44 ImmutableStateInvariantMiddlewareOptions ,
55 Middleware ,
6+ MiddlewareAPI ,
7+ Store ,
68} from '@reduxjs/toolkit'
79import {
810 createImmutableStateInvariantMiddleware ,
911 isImmutableDefault ,
1012} from '@reduxjs/toolkit'
1113
12- import { trackForMutations } from '@internal/immutableStateInvariantMiddleware'
13- import {
14- mockConsole ,
15- createConsole ,
16- getLog ,
17- } from 'console-testing-library/pure'
18-
1914type MWNext = Parameters < ReturnType < Middleware > > [ 0 ]
2015
2116describe ( 'createImmutableStateInvariantMiddleware' , ( ) => {
@@ -147,14 +142,20 @@ describe('createImmutableStateInvariantMiddleware', () => {
147142
148143 const dispatch = middleware ( { warnAfter : 4 } ) ( next )
149144
150- const restore = mockConsole ( createConsole ( ) )
145+ const consoleWarnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( noop )
146+
151147 try {
152148 dispatch ( { type : 'SOME_ACTION' } )
153- expect ( getLog ( ) . log ) . toMatch (
154- / ^ I m m u t a b l e S t a t e I n v a r i a n t M i d d l e w a r e t o o k \d * m s , w h i c h i s m o r e t h a n t h e w a r n i n g t h r e s h o l d o f 4 m s ./ ,
149+
150+ expect ( consoleWarnSpy ) . toHaveBeenCalledOnce ( )
151+
152+ expect ( consoleWarnSpy ) . toHaveBeenLastCalledWith (
153+ expect . stringMatching (
154+ / ^ I m m u t a b l e S t a t e I n v a r i a n t M i d d l e w a r e t o o k \d * m s , w h i c h i s m o r e t h a n t h e w a r n i n g t h r e s h o l d o f 4 m s ./ ,
155+ ) ,
155156 )
156157 } finally {
157- restore ( )
158+ consoleWarnSpy . mockRestore ( )
158159 }
159160 } )
160161
@@ -167,12 +168,14 @@ describe('createImmutableStateInvariantMiddleware', () => {
167168
168169 const dispatch = middleware ( { warnAfter : 4 } ) ( next )
169170
170- const restore = mockConsole ( createConsole ( ) )
171+ const consoleWarnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( noop )
172+
171173 try {
172174 dispatch ( { type : 'SOME_ACTION' } )
173- expect ( getLog ( ) . log ) . toEqual ( '' )
175+
176+ expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( )
174177 } finally {
175- restore ( )
178+ consoleWarnSpy . mockRestore ( )
176179 }
177180 } )
178181} )
0 commit comments