11import { assertType , describe , expectTypeOf , it , test } from 'vitest'
22import { QueryClient , dataTagSymbol , skipToken } from '@tanstack/query-core'
3+ import { queryKey } from '@tanstack/query-test-utils'
34import { infiniteQueryOptions } from '../infiniteQueryOptions'
45import { useInfiniteQuery } from '../useInfiniteQuery'
56import { useSuspenseInfiniteQuery } from '../useSuspenseInfiniteQuery'
@@ -14,7 +15,7 @@ describe('infiniteQueryOptions', () => {
1415 it ( 'should not allow excess properties' , ( ) => {
1516 assertType (
1617 infiniteQueryOptions ( {
17- queryKey : [ 'key' ] ,
18+ queryKey : queryKey ( ) ,
1819 queryFn : ( ) => Promise . resolve ( 'data' ) ,
1920 getNextPageParam : ( ) => 1 ,
2021 initialPageParam : 1 ,
@@ -25,7 +26,7 @@ describe('infiniteQueryOptions', () => {
2526 } )
2627 it ( 'should infer types for callbacks' , ( ) => {
2728 infiniteQueryOptions ( {
28- queryKey : [ 'key' ] ,
29+ queryKey : queryKey ( ) ,
2930 queryFn : ( ) => Promise . resolve ( 'data' ) ,
3031 staleTime : 1000 ,
3132 getNextPageParam : ( ) => 1 ,
@@ -37,7 +38,7 @@ describe('infiniteQueryOptions', () => {
3738 } )
3839 it ( 'should work when passed to useInfiniteQuery' , ( ) => {
3940 const options = infiniteQueryOptions ( {
40- queryKey : [ 'key' ] ,
41+ queryKey : queryKey ( ) ,
4142 queryFn : ( ) => Promise . resolve ( 'string' ) ,
4243 getNextPageParam : ( ) => 1 ,
4344 initialPageParam : 1 ,
@@ -52,7 +53,7 @@ describe('infiniteQueryOptions', () => {
5253 } )
5354 it ( 'should work when passed to useSuspenseInfiniteQuery' , ( ) => {
5455 const options = infiniteQueryOptions ( {
55- queryKey : [ 'key' ] ,
56+ queryKey : queryKey ( ) ,
5657 queryFn : ( ) => Promise . resolve ( 'string' ) ,
5758 getNextPageParam : ( ) => 1 ,
5859 initialPageParam : 1 ,
@@ -64,7 +65,7 @@ describe('infiniteQueryOptions', () => {
6465 } )
6566 it ( 'should work when passed to fetchInfiniteQuery' , async ( ) => {
6667 const options = infiniteQueryOptions ( {
67- queryKey : [ 'key' ] ,
68+ queryKey : queryKey ( ) ,
6869 queryFn : ( ) => Promise . resolve ( 'string' ) ,
6970 getNextPageParam : ( ) => 1 ,
7071 initialPageParam : 1 ,
@@ -75,61 +76,61 @@ describe('infiniteQueryOptions', () => {
7576 expectTypeOf ( data ) . toEqualTypeOf < InfiniteData < string , number > > ( )
7677 } )
7778 it ( 'should tag the queryKey with the result type of the QueryFn' , ( ) => {
78- const { queryKey } = infiniteQueryOptions ( {
79- queryKey : [ 'key' ] ,
79+ const { queryKey : tagged } = infiniteQueryOptions ( {
80+ queryKey : queryKey ( ) ,
8081 queryFn : ( ) => Promise . resolve ( 'string' ) ,
8182 getNextPageParam : ( ) => 1 ,
8283 initialPageParam : 1 ,
8384 } )
8485
85- expectTypeOf ( queryKey [ dataTagSymbol ] ) . toEqualTypeOf < InfiniteData < string > > ( )
86+ expectTypeOf ( tagged [ dataTagSymbol ] ) . toEqualTypeOf < InfiniteData < string > > ( )
8687 } )
8788 it ( 'should tag the queryKey even if no promise is returned' , ( ) => {
88- const { queryKey } = infiniteQueryOptions ( {
89- queryKey : [ 'key' ] ,
89+ const { queryKey : tagged } = infiniteQueryOptions ( {
90+ queryKey : queryKey ( ) ,
9091 queryFn : ( ) => 'string' ,
9192 getNextPageParam : ( ) => 1 ,
9293 initialPageParam : 1 ,
9394 } )
9495
95- expectTypeOf ( queryKey [ dataTagSymbol ] ) . toEqualTypeOf < InfiniteData < string > > ( )
96+ expectTypeOf ( tagged [ dataTagSymbol ] ) . toEqualTypeOf < InfiniteData < string > > ( )
9697 } )
9798 it ( 'should tag the queryKey with the result type of the QueryFn if select is used' , ( ) => {
98- const { queryKey } = infiniteQueryOptions ( {
99- queryKey : [ 'key' ] ,
99+ const { queryKey : tagged } = infiniteQueryOptions ( {
100+ queryKey : queryKey ( ) ,
100101 queryFn : ( ) => Promise . resolve ( 'string' ) ,
101102 select : ( data ) => data . pages ,
102103 getNextPageParam : ( ) => 1 ,
103104 initialPageParam : 1 ,
104105 } )
105106
106- expectTypeOf ( queryKey [ dataTagSymbol ] ) . toEqualTypeOf < InfiniteData < string > > ( )
107+ expectTypeOf ( tagged [ dataTagSymbol ] ) . toEqualTypeOf < InfiniteData < string > > ( )
107108 } )
108109 it ( 'should return the proper type when passed to getQueryData' , ( ) => {
109- const { queryKey } = infiniteQueryOptions ( {
110- queryKey : [ 'key' ] ,
110+ const { queryKey : tagged } = infiniteQueryOptions ( {
111+ queryKey : queryKey ( ) ,
111112 queryFn : ( ) => Promise . resolve ( 'string' ) ,
112113 getNextPageParam : ( ) => 1 ,
113114 initialPageParam : 1 ,
114115 } )
115116
116117 const queryClient = new QueryClient ( )
117- const data = queryClient . getQueryData ( queryKey )
118+ const data = queryClient . getQueryData ( tagged )
118119
119120 expectTypeOf ( data ) . toEqualTypeOf <
120121 InfiniteData < string , unknown > | undefined
121122 > ( )
122123 } )
123124 it ( 'should properly type when passed to setQueryData' , ( ) => {
124- const { queryKey } = infiniteQueryOptions ( {
125- queryKey : [ 'key' ] ,
125+ const { queryKey : tagged } = infiniteQueryOptions ( {
126+ queryKey : queryKey ( ) ,
126127 queryFn : ( ) => Promise . resolve ( 'string' ) ,
127128 getNextPageParam : ( ) => 1 ,
128129 initialPageParam : 1 ,
129130 } )
130131
131132 const queryClient = new QueryClient ( )
132- const data = queryClient . setQueryData ( queryKey , ( prev ) => {
133+ const data = queryClient . setQueryData ( tagged , ( prev ) => {
133134 expectTypeOf ( prev ) . toEqualTypeOf <
134135 InfiniteData < string , unknown > | undefined
135136 > ( )
@@ -142,7 +143,7 @@ describe('infiniteQueryOptions', () => {
142143 } )
143144 it ( 'should throw a type error when using queryFn with skipToken in a suspense query' , ( ) => {
144145 const options = infiniteQueryOptions ( {
145- queryKey : [ 'key' ] ,
146+ queryKey : queryKey ( ) ,
146147 queryFn :
147148 Math . random ( ) > 0.5 ? skipToken : ( ) => Promise . resolve ( 'string' ) ,
148149 getNextPageParam : ( ) => 1 ,
@@ -156,7 +157,7 @@ describe('infiniteQueryOptions', () => {
156157 test ( 'should not be allowed to be passed to non-infinite query functions' , ( ) => {
157158 const queryClient = new QueryClient ( )
158159 const options = infiniteQueryOptions ( {
159- queryKey : [ 'key' ] ,
160+ queryKey : queryKey ( ) ,
160161 queryFn : ( ) => Promise . resolve ( 'string' ) ,
161162 getNextPageParam : ( ) => 1 ,
162163 initialPageParam : 1 ,
@@ -182,7 +183,7 @@ describe('infiniteQueryOptions', () => {
182183 test ( 'allow optional initialData function' , ( ) => {
183184 const initialData : { example : boolean } | undefined = { example : true }
184185 const queryOptions = infiniteQueryOptions ( {
185- queryKey : [ 'example' ] ,
186+ queryKey : queryKey ( ) ,
186187 queryFn : ( ) => initialData ,
187188 initialData : initialData
188189 ? ( ) => ( { pages : [ initialData ] , pageParams : [ ] } )
@@ -200,7 +201,7 @@ describe('infiniteQueryOptions', () => {
200201 test ( 'allow optional initialData object' , ( ) => {
201202 const initialData : { example : boolean } | undefined = { example : true }
202203 const queryOptions = infiniteQueryOptions ( {
203- queryKey : [ 'example' ] ,
204+ queryKey : queryKey ( ) ,
204205 queryFn : ( ) => initialData ,
205206 initialData : initialData
206207 ? { pages : [ initialData ] , pageParams : [ ] }
0 commit comments