Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve tests
clean up
  • Loading branch information
dutziworks authored and markerikson committed Sep 24, 2023
commit bd7f3ba23e2734966d08970252feb4e91b4ba56b
5 changes: 1 addition & 4 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@
"dist/**/*.d.ts",
"dist/**/package.json",
"src/",
"query",
"tsconfig.test.json",
"tsconfig.json",
"tsconfig.base.json"
"query"
],
"dependencies": {
"immer": "^9.0.21",
Expand Down
61 changes: 60 additions & 1 deletion packages/toolkit/src/query/tests/optimisticUpdates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('updateQueryData', () => {
expect(result.current.data).toEqual(dataBefore)
})

test.only('updates cache values including provided tags, undos that', async () => {
test('updates (list) cache values including provided tags, undos that', async () => {
baseQuery
.mockResolvedValueOnce([
{
Expand Down Expand Up @@ -253,6 +253,65 @@ describe('updateQueryData', () => {
expect(provided4Next).toEqual([])
})

test('updates (list) cache values excluding provided tags, undos that', async () => {
baseQuery
.mockResolvedValueOnce([
{
id: '3',
title: 'All about cheese.',
contents: 'TODO',
},
])
.mockResolvedValueOnce(42)
const { result } = renderHook(() => api.endpoints.listPosts.useQuery(), {
wrapper: storeRef.wrapper,
})
await hookWaitFor(() => expect(result.current.isSuccess).toBeTruthy())

let provided!: InvalidationState<'Post'>
act(() => {
provided = storeRef.store.getState().api.provided
})

let returnValue!: ReturnType<ReturnType<typeof api.util.updateQueryData>>
act(() => {
returnValue = storeRef.store.dispatch(
api.util.updateQueryData(
'listPosts',
undefined,
(draft) => {
draft.push({
id: '4',
title: 'Mostly about cheese.',
contents: 'TODO',
})
},
false
)
)
})

act(() => {
provided = storeRef.store.getState().api.provided
})

const provided4 = provided['Post']['4']

expect(provided4).toEqual(undefined)

act(() => {
returnValue.undo()
})

act(() => {
provided = storeRef.store.getState().api.provided
})

const provided4Next = provided['Post']['4']

expect(provided4Next).toEqual(undefined)
})

test('does not update non-existing values', async () => {
baseQuery
.mockImplementationOnce(async () => ({
Expand Down