Skip to content

Commit 3566dde

Browse files
committed
tests(svelte-query): svelte queryOptions tests for new query methods
1 parent 5d51700 commit 3566dde

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

packages/svelte-query/tests/infiniteQueryOptions.test-d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ describe('infiniteQueryOptions', () => {
5050
>()
5151
})
5252

53+
it('should work when passed to infiniteQuery', async () => {
54+
const options = infiniteQueryOptions({
55+
queryKey: ['key'],
56+
queryFn: () => Promise.resolve('string'),
57+
getNextPageParam: () => 1,
58+
initialPageParam: 1,
59+
})
60+
61+
const data = await new QueryClient().infiniteQuery(options)
62+
63+
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
64+
})
65+
66+
it('should work when passed to infiniteQuery with select', async () => {
67+
const options = infiniteQueryOptions({
68+
queryKey: ['key'],
69+
queryFn: () => Promise.resolve('string'),
70+
getNextPageParam: () => 1,
71+
initialPageParam: 1,
72+
select: (data) => data.pages,
73+
})
74+
75+
const data = await new QueryClient().infiniteQuery(options)
76+
77+
expectTypeOf(data).toEqualTypeOf<Array<string>>()
78+
})
79+
5380
it('should work when passed to fetchInfiniteQuery', async () => {
5481
const key = queryKey()
5582
const options = infiniteQueryOptions({

packages/svelte-query/tests/queryOptions.test-d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ describe('queryOptions', () => {
3434
})
3535
})
3636

37+
it('should work when passed to query', async () => {
38+
const options = queryOptions({
39+
queryKey: ['key'],
40+
queryFn: () => Promise.resolve(5),
41+
})
42+
43+
const data = await new QueryClient().query(options)
44+
expectTypeOf(data).toEqualTypeOf<number>()
45+
})
46+
47+
it('should work when passed to query with select', async () => {
48+
const options = queryOptions({
49+
queryKey: ['key'],
50+
queryFn: () => Promise.resolve(5),
51+
select: (data) => data.toString(),
52+
})
53+
54+
const data = await new QueryClient().query(options)
55+
expectTypeOf(data).toEqualTypeOf<string>()
56+
})
57+
3758
it('should work when passed to fetchQuery', async () => {
3859
const key = queryKey()
3960
const options = queryOptions({

0 commit comments

Comments
 (0)