Skip to content

Commit 9aef5b1

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master'
2 parents 769e879 + a017425 commit 9aef5b1

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# mobx-tanstack-query
22

3+
## 6.11.2
4+
5+
### Patch Changes
6+
7+
- [#61](https://github.com/js2me/mobx-tanstack-query/pull/61) [`886114c`](https://github.com/js2me/mobx-tanstack-query/commit/886114cdf169c0e9fd520f5879b7ad955eefc653) Thanks [@verylovestars](https://github.com/verylovestars)! - fix the start method of InfiniteQuery
8+
39
## 6.11.1
410

511
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx-tanstack-query",
3-
"version": "6.11.1",
3+
"version": "6.11.2",
44
"scripts": {
55
"prepare": "pnpm dev:install-hooks",
66
"clean": "rimraf dist",

src/infinite-query.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,4 +666,61 @@ describe('InfiniteQuery', () => {
666666
>();
667667
});
668668
});
669+
670+
describe('"start" method', () => {
671+
it('should call queryFn and fetch data', async () => {
672+
const queryFnSpy = vi.fn(async ({ pageParam = 0 }) => {
673+
return Array.from({ length: 3 }, (_, i) => `Item ${pageParam * 3 + i}`);
674+
});
675+
676+
const infiniteQuery = new InfiniteQueryMock({
677+
queryKey: ['test'],
678+
queryFn: queryFnSpy,
679+
enabled: false,
680+
initialPageParam: 0,
681+
getNextPageParam: (_, allPages) => {
682+
return allPages.length < 2 ? allPages.length : undefined;
683+
},
684+
});
685+
686+
await infiniteQuery.start();
687+
688+
await when(() => !infiniteQuery._rawResult.isLoading);
689+
690+
expect(infiniteQuery.result.isFetched).toBeTruthy();
691+
expect(queryFnSpy).toBeCalledTimes(1);
692+
expect(infiniteQuery.data?.pages).toHaveLength(1);
693+
694+
infiniteQuery.destroy();
695+
});
696+
697+
it('should throw error when throwOnError is true', async () => {
698+
vi.useFakeTimers();
699+
700+
const infiniteQuery = new InfiniteQueryMock({
701+
queryKey: ['test-error'],
702+
queryFn: async () => {
703+
throw new Error('InfiniteQueryError');
704+
},
705+
enabled: false,
706+
throwOnError: true,
707+
initialPageParam: 0,
708+
getNextPageParam: () => undefined,
709+
});
710+
711+
let error: Error | undefined;
712+
713+
const promise = infiniteQuery.start().catch((error_) => {
714+
error = error_;
715+
});
716+
717+
await vi.runAllTimersAsync();
718+
await promise;
719+
720+
expect(error?.message).toBe('InfiniteQueryError');
721+
722+
infiniteQuery.destroy();
723+
vi.useRealTimers();
724+
});
725+
});
669726
});

src/inifinite-query.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ export class InfiniteQuery<
503503
return Query.prototype.createQueryHash.call(this, queryKey, options);
504504
}
505505

506+
protected getCurrentThrowableError(options?: RefetchOptions) {
507+
// @ts-expect-error
508+
return Query.prototype.getCurrentThrowableError.call(this, options);
509+
}
510+
506511
setData(
507512
updater: Updater<
508513
NoInfer<InfiniteData<TQueryFnData, TPageParam>> | undefined,

0 commit comments

Comments
 (0)