Skip to content

Commit ac18a2e

Browse files
committed
tests(solid-query): solid queryOptions tests for new methods
1 parent 5d51700 commit ac18a2e

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expectTypeOf, it } from 'vitest'
2-
import { dataTagSymbol } from '@tanstack/query-core'
2+
import { QueryClient, dataTagSymbol } from '@tanstack/query-core'
33
import { queryKey } from '@tanstack/query-test-utils'
44
import { useInfiniteQuery } from '../useInfiniteQuery'
55
import { infiniteQueryOptions } from '../infiniteQueryOptions'
@@ -10,6 +10,33 @@ import type {
1010
} from '../infiniteQueryOptions'
1111

1212
describe('infiniteQueryOptions', () => {
13+
it('should work when passed to infiniteQuery', async () => {
14+
const options = infiniteQueryOptions({
15+
getNextPageParam: () => 10,
16+
queryKey: ['key'],
17+
queryFn: () => ({ wow: true }),
18+
initialPageParam: 0,
19+
})
20+
21+
const data = await new QueryClient().infiniteQuery(options)
22+
23+
expectTypeOf(data).toEqualTypeOf<InfiniteData<{ wow: boolean }, number>>()
24+
})
25+
26+
it('should work when passed to infiniteQuery with select', async () => {
27+
const options = infiniteQueryOptions({
28+
getNextPageParam: () => 10,
29+
queryKey: ['key'],
30+
queryFn: () => ({ wow: true }),
31+
initialPageParam: 0,
32+
select: (data) => data.pages,
33+
})
34+
35+
const data = await new QueryClient().infiniteQuery(options)
36+
37+
expectTypeOf(data).toEqualTypeOf<Array<{ wow: boolean }>>()
38+
})
39+
1340
it('should infer defined types', () => {
1441
const options = infiniteQueryOptions({
1542
getNextPageParam: () => 10,

packages/solid-query/src/__tests__/queryOptions.test-d.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ describe('queryOptions', () => {
3939
const { data } = useQuery(() => options)
4040
expectTypeOf(data).toEqualTypeOf<number | undefined>()
4141
})
42+
it('should work when passed to query', async () => {
43+
const options = queryOptions({
44+
queryKey: ['key'],
45+
queryFn: () => Promise.resolve(5),
46+
})
47+
48+
const data = await new QueryClient().query(options)
49+
expectTypeOf(data).toEqualTypeOf<number>()
50+
})
51+
it('should work when passed to query with select', async () => {
52+
const options = queryOptions({
53+
queryKey: ['key'],
54+
queryFn: () => Promise.resolve(5),
55+
select: (data) => data.toString(),
56+
})
57+
58+
const data = await new QueryClient().query(options)
59+
expectTypeOf(data).toEqualTypeOf<string>()
60+
})
4261
it('should work when passed to fetchQuery', async () => {
4362
const options = queryOptions({
4463
queryKey: queryKey(),

0 commit comments

Comments
 (0)