Skip to content

Commit

Permalink
test: placeholderData
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 27, 2024
1 parent 0999498 commit eb3bf5f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/use-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,38 @@ describe('useQuery', () => {
expect(placeholderData).toHaveBeenCalledWith(42)
expect(wrapper.vm.data).toBe(24)
})

it('does not change the cache state', async () => {
const pinia = createPinia()
const options = {
key: ['id'],
query: async () => 42,
placeholderData: 24,
} satisfies UseQueryOptions
const [w1] = mountSimple(options, { plugins: [pinia] })

// ensure data is there
expect(w1.vm.data).toBe(24)

const cache = useQueryCache(pinia)
expect(cache.getEntries({
key: ['id'],
}).at(0)?.state.value).toEqual({
status: 'pending',
data: undefined,
error: null,
})
expect(cache.getQueryData(['id'])).toBe(undefined)
await flushPromises()
expect(cache.getEntries({
key: ['id'],
}).at(0)?.state.value).toEqual({
status: 'success',
data: 42,
error: null,
})
expect(cache.getQueryData(['id'])).toBe(42)
})
})

describe('refresh data', () => {
Expand Down

0 comments on commit eb3bf5f

Please sign in to comment.