This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7cbf48
commit bcc3e00
Showing
11 changed files
with
152 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { createApi } from '@rtk-incubator/rtk-query/react'; | ||
import { actionsReducer, matchSequence, setupApiStore, waitMs } from './helpers'; | ||
|
||
const baseQuery = (args?: any) => ({ data: args }); | ||
const api = createApi({ | ||
baseQuery, | ||
entityTypes: ['Banana', 'Bread'], | ||
endpoints: (build) => ({ | ||
getBanana: build.query<unknown, number>({ | ||
query(id) { | ||
return { url: `banana/${id}` }; | ||
}, | ||
provides: ['Banana'], | ||
}), | ||
getBread: build.query<unknown, number>({ | ||
query(id) { | ||
return { url: `bread/${id}` }; | ||
}, | ||
provides: ['Bread'], | ||
}), | ||
}), | ||
}); | ||
const { getBanana, getBread } = api.endpoints; | ||
|
||
const storeRef = setupApiStore(api, { | ||
...actionsReducer, | ||
}); | ||
|
||
it('invalidates the specified entities', async () => { | ||
await storeRef.store.dispatch(getBanana.initiate(1)); | ||
matchSequence(storeRef.store.getState().actions, getBanana.matchPending, getBanana.matchFulfilled); | ||
|
||
await storeRef.store.dispatch(api.util.invalidateEntities(['Banana', 'Bread'])); | ||
|
||
// Slight pause to let the middleware run and such | ||
await waitMs(20); | ||
|
||
const firstSequence = [ | ||
getBanana.matchPending, | ||
getBanana.matchFulfilled, | ||
api.util.invalidateEntities.match, | ||
getBanana.matchPending, | ||
getBanana.matchFulfilled, | ||
]; | ||
matchSequence(storeRef.store.getState().actions, ...firstSequence); | ||
|
||
await storeRef.store.dispatch(getBread.initiate(1)); | ||
await storeRef.store.dispatch(api.util.invalidateEntities([{ type: 'Bread' }])); | ||
|
||
await waitMs(20); | ||
|
||
matchSequence( | ||
storeRef.store.getState().actions, | ||
...firstSequence, | ||
getBread.matchPending, | ||
getBread.matchFulfilled, | ||
api.util.invalidateEntities.match, | ||
getBread.matchPending, | ||
getBread.matchFulfilled | ||
); | ||
}); | ||
|
||
describe.skip('TS only tests', () => { | ||
it('should allow for an array of string EntityTypes', () => { | ||
api.util.invalidateEntities(['Banana', 'Bread']); | ||
}); | ||
it('should allow for an array of full EntityTypes descriptions', () => { | ||
api.util.invalidateEntities([{ type: 'Banana' }, { type: 'Bread', id: 1 }]); | ||
}); | ||
|
||
it('should allow for a mix of full descriptions as well as plain strings', () => { | ||
api.util.invalidateEntities(['Banana', { type: 'Bread', id: 1 }]); | ||
}); | ||
it('should error when using non-existing EntityTypes', () => { | ||
// @ts-expect-error | ||
api.util.invalidateEntities(['Missing Entity']); | ||
}); | ||
it('should error when using non-existing EntityTypes in the full format', () => { | ||
// @ts-expect-error | ||
api.util.invalidateEntities([{ type: 'Missing' }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters