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

queryCache.test.ts

54 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(['foo', ref('bar')], {
17 queryKey: ref(['baz']),
18 })
19​
20 expect(QueryCacheOrigin.prototype.find).toBeCalledWith(['foo', 'bar'], {
21 queryKey: ['baz'],
22 })
23 })
24 })
25​
26 describe('findAll', () => {
27 test('should properly unwrap two parameters', async () => {
28 const queryCache = new QueryCache()
29​
30 queryCache.findAll(['foo', ref('bar')], {
31 queryKey: ref(['baz']),
32 })
33​
34 expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith(
35 ['foo', 'bar'],
36 {
37 queryKey: ['baz'],
38 },
39 )
40 })
41​
42 test('should properly unwrap one parameter', async () => {
43 const queryCache = new QueryCache()
44​
45 queryCache.findAll({
46 queryKey: ref(['baz']),
47 })
48​
49 expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({
50 queryKey: ['baz'],
51 })
52 })
53 })
54})