Skip to content

Commit 459e4ec

Browse files
committed
Add invalidateTags tests
1 parent eeaa20c commit 459e4ec

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createApi } from '@reduxjs/toolkit/query'
2-
import { actionsReducer, setupApiStore } from '../../tests/utils/helpers'
32
import { delay } from 'msw'
3+
import { actionsReducer, setupApiStore } from '../../tests/utils/helpers'
44

55
const baseQuery = (args?: any) => ({ data: args })
66
const api = createApi({
@@ -70,3 +70,41 @@ it('invalidates the specified tags', async () => {
7070
getBread.matchFulfilled,
7171
)
7272
})
73+
74+
it('invalidates tags correctly when null or undefined are provided as tags', async() =>{
75+
await storeRef.store.dispatch(getBanana.initiate(1))
76+
await storeRef.store.dispatch(api.util.invalidateTags([undefined, null, 'Banana']))
77+
78+
// Slight pause to let the middleware run and such
79+
await delay(20)
80+
81+
const apiActions = [
82+
api.internalActions.middlewareRegistered.match,
83+
getBanana.matchPending,
84+
getBanana.matchFulfilled,
85+
api.util.invalidateTags.match,
86+
getBanana.matchPending,
87+
getBanana.matchFulfilled,
88+
]
89+
90+
expect(storeRef.store.getState().actions).toMatchSequence(...apiActions)
91+
})
92+
93+
94+
it.each([{ tags: [undefined, null, 'Bread'] as Parameters<typeof api.util.invalidateTags>['0'] }, { tags: [undefined, null], }, { tags: [] }])('does not invalidate with tags=$tags if no query matches', async ({ tags }) => {
95+
await storeRef.store.dispatch(getBanana.initiate(1))
96+
await storeRef.store.dispatch(api.util.invalidateTags(tags))
97+
98+
// Slight pause to let the middleware run and such
99+
await delay(20)
100+
101+
const apiActions = [
102+
api.internalActions.middlewareRegistered.match,
103+
getBanana.matchPending,
104+
getBanana.matchFulfilled,
105+
api.util.invalidateTags.match,
106+
]
107+
108+
expect(storeRef.store.getState().actions).toMatchSequence(...apiActions)
109+
})
110+

0 commit comments

Comments
 (0)