Skip to content

Commit 41b9a50

Browse files
committed
Fix console spy related issues in fakeBaseQuery.test.tsx
1 parent 36b554f commit 41b9a50

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

packages/toolkit/src/query/tests/fakeBaseQuery.test.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { noop } from '@internal/listenerMiddleware/utils'
12
import { configureStore } from '@reduxjs/toolkit'
23
import { createApi, fakeBaseQuery } from '@reduxjs/toolkit/query'
3-
import '../../tests/utils/helpers'
44

55
type CustomErrorType = { type: 'Custom' }
66

@@ -122,13 +122,19 @@ const store = configureStore({
122122
})
123123

124124
test('fakeBaseQuery throws when invoking query', async () => {
125+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(noop)
126+
125127
const thunk = api.endpoints.withQuery.initiate('')
126-
let result: { error?: any } | undefined
127-
await expect(async () => {
128-
result = await store.dispatch(thunk)
129-
}).toHaveConsoleOutput(
130-
`An unhandled error occurred processing a request for the endpoint "withQuery".
131-
In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: When using \`fakeBaseQuery\`, all queries & mutations must use the \`queryFn\` definition syntax.]`,
128+
129+
const result = await store.dispatch(thunk)
130+
131+
expect(consoleErrorSpy).toHaveBeenCalledOnce()
132+
133+
expect(consoleErrorSpy).toHaveBeenLastCalledWith(
134+
`An unhandled error occurred processing a request for the endpoint "withQuery".\nIn the case of an unhandled error, no tags will be "provided" or "invalidated".`,
135+
Error(
136+
'When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.',
137+
),
132138
)
133139

134140
expect(result!.error).toEqual({
@@ -137,4 +143,6 @@ test('fakeBaseQuery throws when invoking query', async () => {
137143
name: 'Error',
138144
stack: expect.any(String),
139145
})
146+
147+
consoleErrorSpy.mockRestore()
140148
})

0 commit comments

Comments
 (0)