Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

usePrefetchInfiniteQuery.test-d.tsx

61 lines1.6 KB

1import { assertType, describe, expectTypeOf, it } from 'vitest'
2import { queryKey } from '@tanstack/query-test-utils'
3import { usePrefetchInfiniteQuery } from '..'
4​
5describe('usePrefetchInfiniteQuery', () => {
6 it('should return nothing', () => {
7 const result = usePrefetchInfiniteQuery({
8 queryKey: queryKey(),
9 queryFn: () => Promise.resolve(5),
10 initialPageParam: 1,
11 getNextPageParam: () => 1,
12 })
13​
14 expectTypeOf(result).toEqualTypeOf<void>()
15 })
16​
17 it('should require initialPageParam and getNextPageParam', () => {
18 assertType(
19 // @ts-expect-error TS2345
20 usePrefetchInfiniteQuery({
21 queryKey: queryKey(),
22 queryFn: () => Promise.resolve(5),
23 }),
24 )
25 })
26​
27 it('should not allow refetchInterval, enabled or throwOnError options', () => {
28 assertType(
29 usePrefetchInfiniteQuery({
30 queryKey: queryKey(),
31 queryFn: () => Promise.resolve(5),
32 initialPageParam: 1,
33 getNextPageParam: () => 1,
34 // @ts-expect-error TS2353
35 refetchInterval: 1000,
36 }),
37 )
38​
39 assertType(
40 usePrefetchInfiniteQuery({
41 queryKey: queryKey(),
42 queryFn: () => Promise.resolve(5),
43 initialPageParam: 1,
44 getNextPageParam: () => 1,
45 // @ts-expect-error TS2353
46 enabled: true,
47 }),
48 )
49​
50 assertType(
51 usePrefetchInfiniteQuery({
52 queryKey: queryKey(),
53 queryFn: () => Promise.resolve(5),
54 initialPageParam: 1,
55 getNextPageParam: () => 1,
56 // @ts-expect-error TS2353
57 throwOnError: true,
58 }),
59 )
60 })
61})