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

createQueries.test-d.tsx

31 lines885 Bytes

1import { describe, expectTypeOf, it } from 'vitest'
2import { queryOptions, useQueries } from '..'
3import type { UseQueryResult } from '..'
4​
5describe('useQueries', () => {
6 it('should return correct data for dynamic queries with mixed result types', () => {
7 const Queries1 = {
8 get: () =>
9 queryOptions({
10 queryKey: ['key1'],
11 queryFn: () => Promise.resolve(1),
12 }),
13 }
14 const Queries2 = {
15 get: () =>
16 queryOptions({
17 queryKey: ['key2'],
18 queryFn: () => Promise.resolve(true),
19 }),
20 }
21​
22 const queries1List = [1, 2, 3].map(() => ({ ...Queries1.get() }))
23 const result = useQueries(() => ({
24 queries: [...queries1List, { ...Queries2.get() }],
25 }))
26​
27 expectTypeOf(result).toEqualTypeOf<
28 [...Array<UseQueryResult<number, Error>>, UseQueryResult<boolean, Error>]
29 >()
30 })
31})