Skip to content

Commit 75ca59e

Browse files
committed
test: add more type units for infinite query (select param)
1 parent b497830 commit 75ca59e

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

src/infinite-query.test.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ describe('InfiniteQuery', () => {
442442

443443
const getFoo = (): Foo[] => [];
444444

445+
const queryClient = new QueryClient({});
446+
445447
const infiniteQuery = new InfiniteQuery({
446-
queryClient: new QueryClient({}),
448+
queryClient,
447449
select: (data) => ({
448450
pageParams: data.pageParams,
449451
pages: data.pages,
@@ -475,6 +477,68 @@ describe('InfiniteQuery', () => {
475477
kek: number;
476478
}
477479
>();
480+
481+
type Foo2 = {
482+
foo2: { bar: 1 }[];
483+
rofls: string;
484+
};
485+
486+
const getFoo2 = (): Foo2 => null as any;
487+
488+
const infiniteQueryAnother = new InfiniteQuery({
489+
queryClient,
490+
enableOnDemand: true,
491+
abortSignal: new AbortController().signal,
492+
queryFn: async ({ pageParam, signal }) => {
493+
// eslint-disable-next-line sonarjs/no-invalid-await
494+
const response = await getFoo2();
495+
return { ...response, lastSearch: 'aaa', pageParam, signal };
496+
},
497+
select: (data) => ({
498+
pageParams: data.pageParams,
499+
pages: data.pages,
500+
kek: 1,
501+
}),
502+
queryKey: ['1', '2', '3'],
503+
initialPageParam: { offset: 0, limit: 30 },
504+
getNextPageParam: (page) => {
505+
expectTypeOf(page).branded.toEqualTypeOf<
506+
Foo2 & {
507+
lastSearch: string;
508+
signal: AbortSignal;
509+
pageParam: { offset: number; limit: number };
510+
}
511+
>();
512+
513+
return {
514+
limit: 1,
515+
offset: 1,
516+
};
517+
},
518+
});
519+
520+
expectTypeOf(infiniteQueryAnother.result.data).branded.toEqualTypeOf<
521+
| undefined
522+
| {
523+
pageParams: {
524+
offset: number;
525+
limit: number;
526+
}[];
527+
pages: {
528+
lastSearch: string;
529+
pageParam: {
530+
offset: number;
531+
limit: number;
532+
};
533+
signal: AbortSignal;
534+
foo2: {
535+
bar: 1;
536+
}[];
537+
rofls: string;
538+
}[];
539+
kek: number;
540+
}
541+
>();
478542
});
479543

480544
it('should work fine "result" typings without "select" property', () => {

0 commit comments

Comments
 (0)