Skip to content

Commit d9c37e4

Browse files
committed
tests(angular-query-experimental): query method tests for angular query options
1 parent 07a10f3 commit d9c37e4

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@ describe('infiniteQueryOptions', () => {
6767

6868
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
6969
})
70+
71+
it('should work when passed to infiniteQuery', async () => {
72+
const options = infiniteQueryOptions({
73+
queryKey: ['key'],
74+
queryFn: () => Promise.resolve('string'),
75+
getNextPageParam: () => 1,
76+
initialPageParam: 1,
77+
})
78+
79+
const data = await new QueryClient().infiniteQuery(options)
80+
81+
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
82+
})
83+
84+
it('should work when passed to infiniteQuery with select', async () => {
85+
const options = infiniteQueryOptions({
86+
queryKey: ['key'],
87+
queryFn: () => Promise.resolve('string'),
88+
getNextPageParam: () => 1,
89+
initialPageParam: 1,
90+
select: (data) => data.pages,
91+
})
92+
93+
const data = await new QueryClient().infiniteQuery(options)
94+
95+
expectTypeOf(data).toEqualTypeOf<Array<string>>()
96+
})
97+
7098
it('should tag the queryKey with the result type of the QueryFn', () => {
7199
const key = queryKey()
72100
const { queryKey: tagged } = infiniteQueryOptions({

packages/angular-query-experimental/src/__tests__/query-options.test-d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ it('should work when passed to fetchQuery', () => {
6767
assertType<Promise<number>>(data)
6868
})
6969

70+
it('should work when passed to query', () => {
71+
const options = queryOptions({
72+
queryKey: ['key'],
73+
queryFn: () => Promise.resolve(5),
74+
})
75+
76+
const data = new QueryClient().query(options)
77+
assertType<Promise<number>>(data)
78+
})
79+
80+
it('should work when passed to query with select', () => {
81+
const options = queryOptions({
82+
queryKey: ['key'],
83+
queryFn: () => Promise.resolve(5),
84+
select: (data) => data.toString(),
85+
})
86+
87+
const data = new QueryClient().query(options)
88+
assertType<Promise<string>>(data)
89+
})
90+
7091
it('should tag the queryKey with the result type of the QueryFn', () => {
7192
const key = queryKey()
7293
const { queryKey: tagged } = queryOptions({

0 commit comments

Comments
 (0)