Skip to content

Commit 9aafdc2

Browse files
committed
fix: _result -> observable.deep for MobxInfiniteQuery
1 parent b2eab2e commit 9aafdc2

File tree

2 files changed

+10
-78
lines changed

2 files changed

+10
-78
lines changed

src/mobx-infinite-query.test.ts

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MobxInfiniteQueryMock<
6969
}
7070

7171
invalidate(params?: MobxQueryInvalidateParams | undefined): Promise<void> {
72-
this.spies.invalidate(params);
72+
this.spies.invalidate(params)();
7373
return super.invalidate();
7474
}
7575

@@ -79,36 +79,31 @@ class MobxInfiniteQueryMock<
7979
| MobxInfiniteQueryDynamicOptions<TData, TError, TQueryKey, TPageParam>,
8080
) {
8181
const result = super.update(options);
82-
this.spies.update.mockReturnValue(result);
83-
this.spies.update(options);
82+
this.spies.update.mockReturnValue(result)(options);
8483
return result;
8584
}
8685

8786
async fetchNextPage(options?: FetchNextPageOptions | undefined) {
8887
const result = await super.fetchNextPage(options);
89-
this.spies.fetchNextPage.mockReturnValue(result);
90-
this.spies.fetchNextPage(options);
88+
this.spies.fetchNextPage.mockReturnValue(result)(options);
9189
return result;
9290
}
9391

9492
async fetchPreviousPage(options?: FetchPreviousPageOptions | undefined) {
9593
const result = await super.fetchPreviousPage(options);
96-
this.spies.fetchPreviousPage.mockReturnValue(result);
97-
this.spies.fetchPreviousPage(options);
94+
this.spies.fetchPreviousPage.mockReturnValue(result)(options);
9895
return result;
9996
}
10097

10198
setData(updater: any, options?: any) {
10299
const result = super.setData(updater, options);
103-
this.spies.setData.mockReturnValue(result);
104-
this.spies.setData(updater, options);
100+
this.spies.setData.mockReturnValue(result)(updater, options);
105101
return result;
106102
}
107103

108104
dispose(): void {
109105
const result = super.dispose();
110-
this.spies.dispose.mockReturnValue(result);
111-
this.spies.dispose();
106+
this.spies.dispose.mockReturnValue(result)();
112107
return result;
113108
}
114109
}
@@ -411,85 +406,22 @@ describe('MobxInfiniteQuery', () => {
411406
});
412407

413408
describe('"enabled" reactive parameter', () => {
414-
it.skip('should be reactive after change queryKey', async () => {
409+
it('should be reactive after change queryKey', async () => {
415410
const mobxQuery = new MobxInfiniteQueryMock({
416411
queryKey: ['test', 0 as number] as const,
417412
enabled: ({ queryKey }) => queryKey[1] > 0,
413+
getNextPageParam: () => 1,
418414
queryFn: () => 100,
419415
});
420416

421417
mobxQuery.update({ queryKey: ['test', 1] as const });
422418

423-
await when(() => !mobxQuery._rawResult.isFetching);
419+
await when(() => !mobxQuery.result.isLoading);
424420

425421
expect(mobxQuery.spies.queryFn).toBeCalledTimes(1);
426422
expect(mobxQuery.spies.queryFn).nthReturnedWith(1, 100);
427423

428424
mobxQuery.dispose();
429425
});
430-
431-
it.skip('should be reactive dependent on another query (runs before declartion)', async () => {
432-
const disabledMobxQuery = new MobxInfiniteQueryMock({
433-
queryKey: ['test', 0 as number] as const,
434-
enabled: ({ queryKey }) => queryKey[1] > 0,
435-
queryFn: () => 100,
436-
});
437-
438-
disabledMobxQuery.update({ queryKey: ['test', 1] as const });
439-
440-
const dependentMobxQuery = new MobxInfiniteQueryMock({
441-
options: () => ({
442-
enabled: !!disabledMobxQuery.options.enabled,
443-
queryKey: [...disabledMobxQuery.options.queryKey, 'dependent'],
444-
}),
445-
queryFn: ({ queryKey }) => queryKey,
446-
});
447-
448-
await when(() => !disabledMobxQuery._rawResult.isLoading);
449-
await when(() => !dependentMobxQuery._rawResult.isLoading);
450-
451-
expect(dependentMobxQuery.spies.queryFn).toBeCalledTimes(1);
452-
expect(dependentMobxQuery.spies.queryFn).nthReturnedWith(1, [
453-
'test',
454-
1,
455-
'dependent',
456-
]);
457-
458-
disabledMobxQuery.dispose();
459-
dependentMobxQuery.dispose();
460-
});
461-
462-
it.skip('should be reactive dependent on another query (runs after declaration)', async () => {
463-
const tempDisabledMobxQuery = new MobxInfiniteQueryMock({
464-
queryKey: ['test', 0 as number] as const,
465-
enabled: ({ queryKey }) => queryKey[1] > 0,
466-
queryFn: () => 100,
467-
});
468-
469-
const dependentMobxQuery = new MobxInfiniteQueryMock({
470-
options: () => ({
471-
enabled: !!tempDisabledMobxQuery.options.enabled,
472-
queryKey: [...tempDisabledMobxQuery.options.queryKey, 'dependent'],
473-
}),
474-
queryFn: ({ queryKey }) => queryKey,
475-
});
476-
477-
tempDisabledMobxQuery.update({ queryKey: ['test', 1] as const });
478-
479-
await when(() => !tempDisabledMobxQuery._rawResult.isLoading);
480-
await when(() => !dependentMobxQuery._rawResult.isLoading);
481-
482-
expect(dependentMobxQuery.spies.queryFn).toBeCalledTimes(1);
483-
// результат с 0 потому что options.enabled у первой квери - это функция и
484-
// !!tempDisabledMobxQuery.options.enabled будет всегда true
485-
expect(dependentMobxQuery.spies.queryFn).nthReturnedWith(1, [
486-
'test',
487-
0,
488-
'dependent',
489-
]);
490-
491-
tempDisabledMobxQuery.dispose();
492-
dependentMobxQuery.dispose();
493-
});
494426
});
495427
});

src/mobx-inifinite-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class MobxInfiniteQuery<
8585
disposer.add(() => this.dispose());
8686
}
8787

88-
observable.ref(this, '_result');
88+
observable.deep(this, '_result');
8989
observable.ref(this, 'isResultRequsted');
9090
action.bound(this, 'setData');
9191
action.bound(this, 'update');

0 commit comments

Comments
 (0)