From c87f6f5494474352edba01680c4bf4d4333a3378 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 24 Oct 2026 02:00:39 +0900 Subject: [PATCH] test(vue-query/queryOptions): add type tests for 'useQueries', 'query' with 'enabled: false' and 'skipToken', and undefined 'initialData' --- .../src/__tests__/queryOptions.test-d.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/packages/vue-query/src/__tests__/queryOptions.test-d.ts b/packages/vue-query/src/__tests__/queryOptions.test-d.ts index 9d1ec529dbf..929b1118de1 100644 --- a/packages/vue-query/src/__tests__/queryOptions.test-d.ts +++ b/packages/vue-query/src/__tests__/queryOptions.test-d.ts @@ -4,6 +4,7 @@ import { dataTagSymbol, skipToken } from '@tanstack/query-core' import { createKey } from '@tanstack/query-test-utils' import { QueryClient } from '../queryClient' import { queryOptions } from '../queryOptions' +import { useQueries } from '../useQueries' import { useQuery } from '../useQuery' import type { InitialDataFunction } from '@tanstack/query-core' @@ -54,6 +55,17 @@ describe('queryOptions', () => { expectTypeOf(data).toEqualTypeOf() }) + it('should work when passed to useQueries', () => { + const options = queryOptions({ + queryKey: createKey(), + queryFn: () => Promise.resolve(5), + }) + + const { value: queriesState } = useQueries({ queries: [options] }) + + expectTypeOf(queriesState[0].data).toEqualTypeOf() + }) + it('should work when passed to query', async () => { const options = queryOptions({ queryKey: ['key'], @@ -75,6 +87,27 @@ describe('queryOptions', () => { expectTypeOf(data).toEqualTypeOf() }) + it('should work when passed to query with enabled: false', async () => { + const options = queryOptions({ + queryKey: ['key'], + queryFn: () => Promise.resolve(5), + enabled: false, + }) + + const data = await new QueryClient().query(options) + expectTypeOf(data).toEqualTypeOf() + }) + + it('should work when passed to query with skipToken', async () => { + const options = queryOptions({ + queryKey: ['key'], + queryFn: skipToken, + }) + + const data = await new QueryClient().query(options) + expectTypeOf(data).toEqualTypeOf() + }) + it('should tag the queryKey with the result type of the QueryFn', () => { const key = createKey() const { queryKey: tagged } = queryOptions({ @@ -327,6 +360,26 @@ describe('queryOptions', () => { >() }) + it('should allow undefined response in initialData', () => { + assertType((id: string | null) => + queryOptions({ + queryKey: [...createKey(), id], + queryFn: () => + Promise.resolve({ + id: '1', + title: 'Do Laundry', + }), + initialData: () => + !id + ? undefined + : { + id, + title: 'Initial Data', + }, + }), + ) + }) + it('should allow accessing queryFn and other properties on the returned options object', () => { const options = queryOptions({ queryKey: createKey(),