Skip to content

Commit

Permalink
Fix issues related to console spies in createReducer.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed May 16, 2024
1 parent 2ec929d commit 8625470
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions packages/toolkit/src/tests/createReducer.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { vi } from 'vitest'
import type {
CaseReducer,
PayloadAction,
Draft,
PayloadAction,
Reducer,
UnknownAction,
} from '@reduxjs/toolkit'
import { isPlainObject } from '@reduxjs/toolkit'
import { createReducer, createAction, createNextState } from '@reduxjs/toolkit'
import {
mockConsole,
createConsole,
getLog,
} from 'console-testing-library/pure'
createAction,
createNextState,
createReducer,
isPlainObject,
} from '@reduxjs/toolkit'

interface Todo {
text: string
Expand Down Expand Up @@ -42,11 +40,6 @@ type ToggleTodoReducer = CaseReducer<
type CreateReducer = typeof createReducer

describe('createReducer', () => {
let restore: () => void

beforeEach(() => {
restore = mockConsole(createConsole())
})
describe('given impure reducers with immer', () => {
const addTodo: AddTodoReducer = (state, action) => {
const { newTodo } = action.payload
Expand Down Expand Up @@ -84,8 +77,11 @@ describe('createReducer', () => {
it('Throws an error if the legacy object notation is used', async () => {
const { createReducer } = await import('../createReducer')
const wrapper = () => {
// @ts-ignore
let dummyReducer = (createReducer as CreateReducer)([] as TodoState, {})
const dummyReducer = (createReducer as CreateReducer)(
[] as TodoState,
// @ts-ignore
{},
)
}

expect(wrapper).toThrowError(
Expand All @@ -101,8 +97,11 @@ describe('createReducer', () => {
process.env.NODE_ENV = 'production'
const { createReducer } = await import('../createReducer')
const wrapper = () => {
// @ts-ignore
let dummyReducer = (createReducer as CreateReducer)([] as TodoState, {})
const dummyReducer = (createReducer as CreateReducer)(
[] as TodoState,
// @ts-ignore
{},
)
}

expect(wrapper).toThrowError()
Expand Down

0 comments on commit 8625470

Please sign in to comment.