-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathcreateQueries.svelte.test.ts
More file actions
45 lines (37 loc) · 1.82 KB
/
createQueries.svelte.test.ts
File metadata and controls
45 lines (37 loc) · 1.82 KB
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
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { render } from '@testing-library/svelte'
import { sleep } from '@tanstack/query-test-utils'
import IsRestoringExample from './IsRestoringExample.svelte'
describe('createQueries', () => {
beforeEach(() => {
vi.useFakeTimers()
})
afterEach(() => {
vi.useRealTimers()
})
it('should not fetch for the duration of the restoring period when isRestoring is true', async () => {
const queryFn1 = vi.fn(() => sleep(10).then(() => 'data1'))
const queryFn2 = vi.fn(() => sleep(10).then(() => 'data2'))
const rendered = render(IsRestoringExample, {
props: { queryFn1, queryFn2 },
})
await vi.advanceTimersByTimeAsync(0)
expect(rendered.getByTestId('status1')).toHaveTextContent('pending')
expect(rendered.getByTestId('status2')).toHaveTextContent('pending')
expect(rendered.getByTestId('fetchStatus1')).toHaveTextContent('idle')
expect(rendered.getByTestId('fetchStatus2')).toHaveTextContent('idle')
expect(rendered.getByTestId('data1')).toHaveTextContent('undefined')
expect(rendered.getByTestId('data2')).toHaveTextContent('undefined')
expect(queryFn1).toHaveBeenCalledTimes(0)
expect(queryFn2).toHaveBeenCalledTimes(0)
await vi.advanceTimersByTimeAsync(11)
expect(rendered.getByTestId('status1')).toHaveTextContent('pending')
expect(rendered.getByTestId('status2')).toHaveTextContent('pending')
expect(rendered.getByTestId('fetchStatus1')).toHaveTextContent('idle')
expect(rendered.getByTestId('fetchStatus2')).toHaveTextContent('idle')
expect(rendered.getByTestId('data1')).toHaveTextContent('undefined')
expect(rendered.getByTestId('data2')).toHaveTextContent('undefined')
expect(queryFn1).toHaveBeenCalledTimes(0)
expect(queryFn2).toHaveBeenCalledTimes(0)
})
})