File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,7 @@ export function createSlice<
268
268
process . env . NODE_ENV === 'development'
269
269
) {
270
270
if ( options . initialState === undefined ) {
271
- throw new Error ( 'You must provide an `initialState` value that is not ` undefined`. You may have misspelled `initialState` ')
271
+ console . error ( 'initial state must be different of undefined')
272
272
}
273
273
}
274
274
Original file line number Diff line number Diff line change 1
1
import type { PayloadAction } from '@reduxjs/toolkit'
2
2
import { createSlice , createAction } from '@reduxjs/toolkit'
3
+ import {
4
+ mockConsole ,
5
+ createConsole ,
6
+ getLog ,
7
+ } from 'console-testing-library/pure'
3
8
4
9
describe ( 'createSlice' , ( ) => {
10
+ let restore : ( ) => void
11
+
12
+ beforeEach ( ( ) => {
13
+ restore = mockConsole ( createConsole ( ) )
14
+ } )
15
+
16
+ describe ( 'when slice is undefined' , ( ) => {
5
17
it ( 'should throw an error' , ( ) => {
6
18
expect ( ( ) =>
7
19
// @ts -ignore
@@ -35,11 +47,13 @@ describe('createSlice', () => {
35
47
36
48
describe ( 'when initial state is undefined' , ( ) => {
37
49
it ( 'should throw an error' , ( ) => {
38
- expect ( ( ) => createSlice ( {
50
+ createSlice ( {
39
51
name : 'test' ,
40
52
reducers : { } ,
41
53
initialState : undefined ,
42
- } ) ) . toThrowError ( 'You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`' )
54
+ } )
55
+
56
+ expect ( getLog ( ) . log ) . toBe ( 'initial state must be different of undefined' )
43
57
} )
44
58
} )
45
59
You can’t perform that action at this time.
0 commit comments