-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathcreateQuery.svelte.test.ts
More file actions
36 lines (28 loc) · 1.21 KB
/
createQuery.svelte.test.ts
File metadata and controls
36 lines (28 loc) · 1.21 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
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('createQuery', () => {
beforeEach(() => {
vi.useFakeTimers()
})
afterEach(() => {
vi.useRealTimers()
})
it('should not fetch for the duration of the restoring period when isRestoring is true', async () => {
const queryFn = vi.fn(() => sleep(10).then(() => 'data'))
const rendered = render(IsRestoringExample, {
props: { queryFn },
})
await vi.advanceTimersByTimeAsync(0)
expect(rendered.getByTestId('status')).toHaveTextContent('pending')
expect(rendered.getByTestId('fetchStatus')).toHaveTextContent('idle')
expect(rendered.getByTestId('data')).toHaveTextContent('undefined')
expect(queryFn).toHaveBeenCalledTimes(0)
await vi.advanceTimersByTimeAsync(11)
expect(rendered.getByTestId('status')).toHaveTextContent('pending')
expect(rendered.getByTestId('fetchStatus')).toHaveTextContent('idle')
expect(rendered.getByTestId('data')).toHaveTextContent('undefined')
expect(queryFn).toHaveBeenCalledTimes(0)
})
})