Skip to content

Commit 89bff79

Browse files
committed
test: should return an console.error with correct message
1 parent e9a379c commit 89bff79

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
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+
516
describe('when slice is undefined', () => {
617
it('should throw an error', () => {
718
expect(() =>
@@ -36,13 +47,13 @@ describe('createSlice', () => {
3647

3748
describe('when initial state is undefined', () => {
3849
it('should throw an error', () => {
39-
expect(() =>
40-
createSlice({
41-
name: 'test',
42-
reducers: {},
43-
initialState: undefined,
44-
})
45-
).toThrowErrorMatchingInlineSnapshot(`"initial state must be different of undefined"`)
50+
createSlice({
51+
name: 'test',
52+
reducers: {},
53+
initialState: undefined,
54+
})
55+
56+
expect(getLog().log).toBe('initial state must be different of undefined')
4657
})
4758
})
4859

0 commit comments

Comments
 (0)