Skip to content

Commit 644677e

Browse files
committed
test: add type tests of expected behaviour (currently failing)
1 parent 01a81ee commit 644677e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

packages/query-core/src/__tests__/infiniteQueryObserver.test-d.tsx

+43
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,47 @@ describe('InfiniteQueryObserver', () => {
7272
expectTypeOf(result.status).toEqualTypeOf<'success'>()
7373
}
7474
})
75+
76+
it('should not allow pageParam on fetchNextPage / fetchPreviousPage if getNextPageParam is defined', async () => {
77+
const observer = new InfiniteQueryObserver(queryClient, {
78+
queryKey: queryKey(),
79+
queryFn: ({ pageParam }) => String(pageParam),
80+
initialPageParam: 1,
81+
getNextPageParam: (page) => Number(page) + 1,
82+
})
83+
84+
expectTypeOf<typeof observer.fetchNextPage>()
85+
.parameter(0)
86+
.toEqualTypeOf<
87+
{ cancelRefetch?: boolean; throwOnError?: boolean } | undefined
88+
>()
89+
90+
expectTypeOf<typeof observer.fetchPreviousPage>()
91+
.parameter(0)
92+
.toEqualTypeOf<
93+
{ cancelRefetch?: boolean; throwOnError?: boolean } | undefined
94+
>()
95+
})
96+
97+
it('should require pageParam on fetchNextPage / fetchPreviousPage if getNextPageParam is missing', async () => {
98+
const observer = new InfiniteQueryObserver(queryClient, {
99+
queryKey: queryKey(),
100+
queryFn: ({ pageParam }) => String(pageParam),
101+
initialPageParam: 1,
102+
})
103+
104+
expectTypeOf<typeof observer.fetchNextPage>()
105+
.parameter(0)
106+
.toEqualTypeOf<
107+
| { pageParam: number; cancelRefetch?: boolean; throwOnError?: boolean }
108+
| undefined
109+
>()
110+
111+
expectTypeOf<typeof observer.fetchPreviousPage>()
112+
.parameter(0)
113+
.toEqualTypeOf<
114+
| { pageParam: number; cancelRefetch?: boolean; throwOnError?: boolean }
115+
| undefined
116+
>()
117+
})
75118
})

0 commit comments

Comments
 (0)