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

queryCache.test.ts

48 lines1.3 KB

1import { ref } from 'vue-demi'
2import { QueryCache as QueryCacheOrigin } from '@tanstack/query-core'
3​
4import { QueryCache } from '../queryCache'
5​
6describe('QueryCache', () => {
7 beforeAll(() => {
8 jest.spyOn(QueryCacheOrigin.prototype, 'find')
9 jest.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 exact: true, //Exact is true, as `find` in QueryCacheOrigin sets exact to true in the passed filters if exact is undefined
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})