Skip to content

Commit 52d2cf9

Browse files
committed
refactor: add throw instead console.error
1 parent 89bff79 commit 52d2cf9

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

packages/toolkit/src/createSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export function createSlice<
268268
process.env.NODE_ENV === 'development'
269269
) {
270270
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`')
272272
}
273273
}
274274

packages/toolkit/src/tests/createSlice.test.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
import type { PayloadAction } from '@reduxjs/toolkit'
22
import { createSlice, createAction } from '@reduxjs/toolkit'
3-
import {
4-
mockConsole,
5-
createConsole,
6-
getLog,
7-
} from 'console-testing-library/pure'
83

94
describe('createSlice', () => {
10-
let restore: () => void
11-
12-
beforeEach(() => {
13-
restore = mockConsole(createConsole())
14-
})
15-
16-
describe('when slice is undefined', () => {
175
it('should throw an error', () => {
186
expect(() =>
197
// @ts-ignore
@@ -47,13 +35,11 @@ describe('createSlice', () => {
4735

4836
describe('when initial state is undefined', () => {
4937
it('should throw an error', () => {
50-
createSlice({
38+
expect(() => createSlice({
5139
name: 'test',
5240
reducers: {},
5341
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`')
5743
})
5844
})
5945

0 commit comments

Comments
 (0)