Skip to content

Commit d82ee9f

Browse files
committed
improve tests
clean up
1 parent 88e2280 commit d82ee9f

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

packages/toolkit/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reduxjs/toolkit",
3-
"version": "1.9.2-11",
3+
"version": "1.9.1",
44
"description": "The official, opinionated, batteries-included toolset for efficient Redux development",
55
"author": "Mark Erikson <mark@isquaredsoftware.com>",
66
"license": "MIT",
@@ -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.16",

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

Lines changed: 60 additions & 1 deletion
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)