File size: 773 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
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { render } from '@testing-library/svelte'
import { QueryCache } from '@tanstack/query-core'
import ParentComponent from './ParentComponent.svelte'

describe('QueryClientProvider', () => {
  beforeEach(() => {
    vi.useFakeTimers()
  })

  afterEach(() => {
    vi.useRealTimers()
  })

  test('Sets a specific cache for all queries to use', async () => {
    const queryCache = new QueryCache()

    const rendered = render(ParentComponent, {
      props: {
        queryCache: queryCache,
      },
    })

    await vi.advanceTimersByTimeAsync(11)
    expect(rendered.getByText('Data: test')).toBeInTheDocument()

    expect(queryCache.find({ queryKey: ['hello'] })).toBeDefined()
  })
})