Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

queryCache.test.ts

48 lines1.2 KB

1import { ref } from 'vue-demi'
2import { QueryCache as QueryCacheOrigin } from '@tanstack/query-core'
3​
4import { QueryCache } from '../queryCache'
5import { vi } from 'vitest'
6​
7describe('QueryCache', () => {
8 beforeAll(() => {
9 vi.spyOn(QueryCacheOrigin.prototype, 'find')
10 vi.spyOn(QueryCacheOrigin.prototype, 'findAll')
11 })
12​
13 describe('find', () => {
14 test('should properly unwrap parameters', async () => {
15 const queryCache = new QueryCache()
16​
17 queryCache.find({
18 queryKey: ['foo', ref('bar')],
19 })
20​
21 expect(QueryCacheOrigin.prototype.find).toBeCalledWith({
22 queryKey: ['foo', 'bar'],
23 })
24 })
25 })
26​
27 describe('findAll', () => {
28 test('should properly unwrap two parameters', async () => {
29 const queryCache = new QueryCache()
30​
31 queryCache.findAll({
32 queryKey: ['foo', ref('bar')],
33 })
34​
35 expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({
36 queryKey: ['foo', 'bar'],
37 })
38 })
39​
40 test('should default to empty filters', async () => {
41 const queryCache = new QueryCache()
42​
43 queryCache.findAll()
44​
45 expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({})
46 })
47 })
48})