Skip to content

Commit d99b8ee

Browse files
committed
Revert "refactor: add throw instead console.error"
This reverts commit 52d2cf9.
1 parent 52d2cf9 commit d99b8ee

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
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-
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')
272272
}
273273
}
274274

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
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'
38

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

3648
describe('when initial state is undefined', () => {
3749
it('should throw an error', () => {
38-
expect(() => createSlice({
50+
createSlice({
3951
name: 'test',
4052
reducers: {},
4153
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')
4357
})
4458
})
4559

0 commit comments

Comments
 (0)