File size: 1,212 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { beforeAll, describe, expect, test, vi } from 'vitest'
import { ref } from 'vue-demi'
import { QueryCache as QueryCacheOrigin } from '@tanstack/query-core'
import { QueryCache } from '../queryCache'

describe('QueryCache', () => {
  beforeAll(() => {
    vi.spyOn(QueryCacheOrigin.prototype, 'find')
    vi.spyOn(QueryCacheOrigin.prototype, 'findAll')
  })

  describe('find', () => {
    test('should properly unwrap parameters', () => {
      const queryCache = new QueryCache()

      queryCache.find({
        queryKey: ['foo', ref('bar')],
      })

      expect(QueryCacheOrigin.prototype.find).toBeCalledWith({
        queryKey: ['foo', 'bar'],
      })
    })
  })

  describe('findAll', () => {
    test('should properly unwrap two parameters', () => {
      const queryCache = new QueryCache()

      queryCache.findAll({
        queryKey: ['foo', ref('bar')],
      })

      expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({
        queryKey: ['foo', 'bar'],
      })
    })

    test('should default to empty filters', () => {
      const queryCache = new QueryCache()

      queryCache.findAll()

      expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({})
    })
  })
})