Skip to content

Commit bd7f3ba

Browse files
dutziworksmarkerikson
authored andcommittedSep 24, 2023
improve tests
clean up
1 parent 3b9bef1 commit bd7f3ba

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed
 

‎packages/toolkit/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@
9494
"dist/**/*.d.ts",
9595
"dist/**/package.json",
9696
"src/",
97-
"query",
98-
"tsconfig.test.json",
99-
"tsconfig.json",
100-
"tsconfig.base.json"
97+
"query"
10198
],
10299
"dependencies": {
103100
"immer": "^9.0.21",

‎packages/toolkit/src/query/tests/optimisticUpdates.test.tsx

+60-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('updateQueryData', () => {
192192
expect(result.current.data).toEqual(dataBefore)
193193
})
194194

195-
test.only('updates cache values including provided tags, undos that', async () => {
195+
test('updates (list) cache values including provided tags, undos that', async () => {
196196
baseQuery
197197
.mockResolvedValueOnce([
198198
{
@@ -253,6 +253,65 @@ describe('updateQueryData', () => {
253253
expect(provided4Next).toEqual([])
254254
})
255255

256+
test('updates (list) cache values excluding provided tags, undos that', async () => {
257+
baseQuery
258+
.mockResolvedValueOnce([
259+
{
260+
id: '3',
261+
title: 'All about cheese.',
262+
contents: 'TODO',
263+
},
264+
])
265+
.mockResolvedValueOnce(42)
266+
const { result } = renderHook(() => api.endpoints.listPosts.useQuery(), {
267+
wrapper: storeRef.wrapper,
268+
})
269+
await hookWaitFor(() => expect(result.current.isSuccess).toBeTruthy())
270+
271+
let provided!: InvalidationState<'Post'>
272+
act(() => {
273+
provided = storeRef.store.getState().api.provided
274+
})
275+
276+
let returnValue!: ReturnType<ReturnType<typeof api.util.updateQueryData>>
277+
act(() => {
278+
returnValue = storeRef.store.dispatch(
279+
api.util.updateQueryData(
280+
'listPosts',
281+
undefined,
282+
(draft) => {
283+
draft.push({
284+
id: '4',
285+
title: 'Mostly about cheese.',
286+
contents: 'TODO',
287+
})
288+
},
289+
false
290+
)
291+
)
292+
})
293+
294+
act(() => {
295+
provided = storeRef.store.getState().api.provided
296+
})
297+
298+
const provided4 = provided['Post']['4']
299+
300+
expect(provided4).toEqual(undefined)
301+
302+
act(() => {
303+
returnValue.undo()
304+
})
305+
306+
act(() => {
307+
provided = storeRef.store.getState().api.provided
308+
})
309+
310+
const provided4Next = provided['Post']['4']
311+
312+
expect(provided4Next).toEqual(undefined)
313+
})
314+
256315
test('does not update non-existing values', async () => {
257316
baseQuery
258317
.mockImplementationOnce(async () => ({

0 commit comments

Comments
 (0)
Please sign in to comment.