Skip to content

Commit 15a0718

Browse files
committed
Fix console spy related issues in effectScenarios.test.ts
1 parent 90c2d01 commit 15a0718

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

packages/toolkit/src/listenerMiddleware/tests/effectScenarios.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
import { noop } from '@internal/listenerMiddleware/utils'
2+
import type { PayloadAction } from '@reduxjs/toolkit'
13
import {
24
configureStore,
35
createAction,
6+
createListenerMiddleware,
47
createSlice,
58
isAnyOf,
9+
TaskAbortError,
610
} from '@reduxjs/toolkit'
7-
import { vi } from 'vitest'
8-
9-
import type { PayloadAction } from '@reduxjs/toolkit'
10-
11-
import { createListenerMiddleware, TaskAbortError } from '../index'
12-
13-
import type { TypedAddListener } from '../index'
1411

1512
describe('Saga-style Effects Scenarios', () => {
1613
interface CounterState {
@@ -57,10 +54,7 @@ describe('Saga-style Effects Scenarios', () => {
5754
return new Promise((resolve) => setTimeout(resolve, ms))
5855
}
5956

60-
beforeAll(() => {
61-
const noop = () => {}
62-
vi.spyOn(console, 'error').mockImplementation(noop)
63-
})
57+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(noop)
6458

6559
beforeEach(() => {
6660
listenerMiddleware = createListenerMiddleware<CounterState>()
@@ -72,6 +66,14 @@ describe('Saga-style Effects Scenarios', () => {
7266
})
7367
})
7468

69+
afterEach(() => {
70+
consoleErrorSpy.mockClear()
71+
})
72+
73+
afterAll(() => {
74+
consoleErrorSpy.mockRestore()
75+
})
76+
7577
test('throttle', async () => {
7678
// Ignore incoming actions for a given period of time while processing a task.
7779
// Ref: https://redux-saga.js.org/docs/api#throttlems-pattern-saga-args

0 commit comments

Comments
 (0)