forked from TanStack/query
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfiniteQueryOptions.test-d.ts
More file actions
61 lines (53 loc) · 1.89 KB
/
infiniteQueryOptions.test-d.ts
File metadata and controls
61 lines (53 loc) · 1.89 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { describe, expectTypeOf, test } from 'vitest'
import { get } from 'svelte/store'
import { QueryClient } from '@tanstack/query-core'
import { createInfiniteQuery, infiniteQueryOptions } from '../../src/index.js'
import type { InfiniteData } from '@tanstack/query-core'
describe('queryOptions', () => {
// eslint-disable-next-line vitest/expect-expect
test('Should not allow excess properties', () => {
infiniteQueryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve('data'),
getNextPageParam: () => 1,
initialPageParam: 1,
// @ts-expect-error this is a good error, because stallTime does not exist!
stallTime: 1000,
})
})
test('Should infer types for callbacks', () => {
infiniteQueryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve('data'),
staleTime: 1000,
getNextPageParam: () => 1,
initialPageParam: 1,
select: (data) => {
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
},
})
})
test('Should work when passed to createInfiniteQuery', () => {
const options = infiniteQueryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve('string'),
getNextPageParam: () => 1,
initialPageParam: 1,
})
const query = createInfiniteQuery(options)
// known issue: type of pageParams is unknown when returned from useInfiniteQuery
expectTypeOf(get(query).data).toEqualTypeOf<
InfiniteData<string, unknown> | undefined
>()
})
test('Should work when passed to fetchInfiniteQuery', async () => {
const options = infiniteQueryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve('string'),
getNextPageParam: () => 1,
initialPageParam: 1,
})
const data = await new QueryClient().fetchInfiniteQuery(options)
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
})
})