File tree Expand file tree Collapse file tree 2 files changed +3
-17
lines changed Expand file tree Collapse file tree 2 files changed +3
-17
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
- console . error ( 'initial state must be different of undefined')
271
+ throw new Error ( 'You must provide an `initialState` value that is not ` undefined`. You may have misspelled `initialState` ')
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'
8
3
9
4
describe ( 'createSlice' , ( ) => {
10
- let restore : ( ) => void
11
-
12
- beforeEach ( ( ) => {
13
- restore = mockConsole ( createConsole ( ) )
14
- } )
15
-
16
- describe ( 'when slice is undefined' , ( ) => {
17
5
it ( 'should throw an error' , ( ) => {
18
6
expect ( ( ) =>
19
7
// @ts -ignore
@@ -47,13 +35,11 @@ describe('createSlice', () => {
47
35
48
36
describe ( 'when initial state is undefined' , ( ) => {
49
37
it ( 'should throw an error' , ( ) => {
50
- createSlice ( {
38
+ expect ( ( ) => createSlice ( {
51
39
name : 'test' ,
52
40
reducers : { } ,
53
41
initialState : undefined ,
54
- } )
55
-
56
- expect ( getLog ( ) . log ) . toBe ( 'initial state must be different of undefined' )
42
+ } ) ) . toThrowError ( 'You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`' )
57
43
} )
58
44
} )
59
45
You can’t perform that action at this time.
0 commit comments