Skip to content

Commit dcfe0b6

Browse files
committed
Fix issues related to console spies in createAsyncThunk.test.ts
1 parent 328a058 commit dcfe0b6

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1+
import { noop } from '@internal/listenerMiddleware/utils'
2+
import { delay } from '@internal/utils'
13
import type { UnknownAction } from '@reduxjs/toolkit'
24
import {
35
configureStore,
46
createAsyncThunk,
57
createReducer,
6-
unwrapResult,
78
miniSerializeError,
9+
unwrapResult,
810
} from '@reduxjs/toolkit'
9-
import { vi } from 'vitest'
10-
11-
import {
12-
createConsole,
13-
getLog,
14-
mockConsole,
15-
} from 'console-testing-library/pure'
16-
import { delay } from '@internal/utils'
1711

1812
declare global {
1913
interface Window {
@@ -498,22 +492,19 @@ describe('createAsyncThunk with abortController', () => {
498492
describe('behavior with missing AbortController', () => {
499493
let keepAbortController: (typeof window)['AbortController']
500494
let freshlyLoadedModule: typeof import('../createAsyncThunk')
501-
let restore: () => void = () => {}
502495
let nodeEnv: string
503496

504497
beforeEach(async () => {
505498
keepAbortController = window.AbortController
506499
delete (window as any).AbortController
507500
vi.resetModules()
508501
freshlyLoadedModule = await import('../createAsyncThunk')
509-
restore = mockConsole(createConsole())
510502
nodeEnv = process.env.NODE_ENV!
511503
;(process.env as any).NODE_ENV = 'development'
512504
})
513505

514506
afterEach(() => {
515507
;(process.env as any).NODE_ENV = nodeEnv
516-
restore()
517508
window.AbortController = keepAbortController
518509
vi.resetModules()
519510
})
@@ -532,16 +523,17 @@ describe('createAsyncThunk with abortController', () => {
532523
})
533524

534525
test('non-serializable arguments are ignored by serializableStateInvariantMiddleware', async () => {
535-
const restore = mockConsole(createConsole())
526+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(noop)
536527
const nonSerializableValue = new Map()
537528
const asyncThunk = createAsyncThunk('test', (arg: Map<any, any>) => {})
538529

539530
configureStore({
540531
reducer: () => 0,
541532
}).dispatch(asyncThunk(nonSerializableValue))
542533

543-
expect(getLog().log).toMatchInlineSnapshot(`""`)
544-
restore()
534+
expect(consoleErrorSpy).not.toHaveBeenCalled()
535+
536+
consoleErrorSpy.mockRestore()
545537
})
546538

547539
describe('conditional skipping of asyncThunks', () => {

0 commit comments

Comments
 (0)