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

queryCache.test.ts

47 lines1.2 KB

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