1+ import { noop } from '@internal/listenerMiddleware/utils'
12import type { PayloadAction , WithSlice } from '@reduxjs/toolkit'
23import {
34 asyncThunkCreator ,
@@ -7,19 +8,18 @@ import {
78 createAction ,
89 createSlice ,
910} from '@reduxjs/toolkit'
10- import {
11- createConsole ,
12- getLog ,
13- mockConsole ,
14- } from 'console-testing-library/pure'
1511
1612type CreateSlice = typeof createSlice
1713
1814describe ( 'createSlice' , ( ) => {
19- let restore : ( ) => void
15+ const consoleErrorSpy = vi . spyOn ( console , 'error' ) . mockImplementation ( noop )
2016
2117 beforeEach ( ( ) => {
22- restore = mockConsole ( createConsole ( ) )
18+ vi . clearAllMocks ( )
19+ } )
20+
21+ afterAll ( ( ) => {
22+ vi . restoreAllMocks ( )
2323 } )
2424
2525 describe ( 'when slice is undefined' , ( ) => {
@@ -57,8 +57,10 @@ describe('createSlice', () => {
5757 describe ( 'when initial state is undefined' , ( ) => {
5858 beforeEach ( ( ) => {
5959 vi . stubEnv ( 'NODE_ENV' , 'development' )
60+ } )
6061
61- return vi . unstubAllEnvs
62+ afterEach ( ( ) => {
63+ vi . unstubAllEnvs ( )
6264 } )
6365
6466 it ( 'should throw an error' , ( ) => {
@@ -68,7 +70,9 @@ describe('createSlice', () => {
6870 initialState : undefined ,
6971 } )
7072
71- expect ( getLog ( ) . log ) . toBe (
73+ expect ( consoleErrorSpy ) . toHaveBeenCalledOnce ( )
74+
75+ expect ( consoleErrorSpy ) . toHaveBeenLastCalledWith (
7276 'You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`' ,
7377 )
7478 } )
@@ -397,7 +401,6 @@ describe('createSlice', () => {
397401
398402 beforeEach ( ( ) => {
399403 vi . resetModules ( )
400- restore = mockConsole ( createConsole ( ) )
401404 } )
402405
403406 afterEach ( ( ) => {
0 commit comments