@@ -4,6 +4,7 @@ import { dataTagSymbol, skipToken } from '@tanstack/query-core'
44import { createKey } from '@tanstack/query-test-utils'
55import { QueryClient } from '../queryClient'
66import { queryOptions } from '../queryOptions'
7+ import { useQueries } from '../useQueries'
78import { useQuery } from '../useQuery'
89import type { InitialDataFunction } from '@tanstack/query-core'
910
@@ -54,6 +55,17 @@ describe('queryOptions', () => {
5455 expectTypeOf ( data ) . toEqualTypeOf < number | undefined > ( )
5556 } )
5657
58+ it ( 'should work when passed to useQueries' , ( ) => {
59+ const options = queryOptions ( {
60+ queryKey : createKey ( ) ,
61+ queryFn : ( ) => Promise . resolve ( 5 ) ,
62+ } )
63+
64+ const { value : queriesState } = useQueries ( { queries : [ options ] } )
65+
66+ expectTypeOf ( queriesState [ 0 ] . data ) . toEqualTypeOf < number | undefined > ( )
67+ } )
68+
5769 it ( 'should work when passed to query' , async ( ) => {
5870 const options = queryOptions ( {
5971 queryKey : [ 'key' ] ,
@@ -75,6 +87,27 @@ describe('queryOptions', () => {
7587 expectTypeOf ( data ) . toEqualTypeOf < string > ( )
7688 } )
7789
90+ it ( 'should work when passed to query with enabled: false' , async ( ) => {
91+ const options = queryOptions ( {
92+ queryKey : [ 'key' ] ,
93+ queryFn : ( ) => Promise . resolve ( 5 ) ,
94+ enabled : false ,
95+ } )
96+
97+ const data = await new QueryClient ( ) . query ( options )
98+ expectTypeOf ( data ) . toEqualTypeOf < number > ( )
99+ } )
100+
101+ it ( 'should work when passed to query with skipToken' , async ( ) => {
102+ const options = queryOptions ( {
103+ queryKey : [ 'key' ] ,
104+ queryFn : skipToken ,
105+ } )
106+
107+ const data = await new QueryClient ( ) . query ( options )
108+ expectTypeOf ( data ) . toEqualTypeOf < unknown > ( )
109+ } )
110+
78111 it ( 'should tag the queryKey with the result type of the QueryFn' , ( ) => {
79112 const key = createKey ( )
80113 const { queryKey : tagged } = queryOptions ( {
@@ -327,6 +360,26 @@ describe('queryOptions', () => {
327360 > ( )
328361 } )
329362
363+ it ( 'should allow undefined response in initialData' , ( ) => {
364+ assertType ( ( id : string | null ) =>
365+ queryOptions ( {
366+ queryKey : [ ...createKey ( ) , id ] ,
367+ queryFn : ( ) =>
368+ Promise . resolve ( {
369+ id : '1' ,
370+ title : 'Do Laundry' ,
371+ } ) ,
372+ initialData : ( ) =>
373+ ! id
374+ ? undefined
375+ : {
376+ id,
377+ title : 'Initial Data' ,
378+ } ,
379+ } ) ,
380+ )
381+ } )
382+
330383 it ( 'should allow accessing queryFn and other properties on the returned options object' , ( ) => {
331384 const options = queryOptions ( {
332385 queryKey : createKey ( ) ,
0 commit comments