Skip to content

Commit a454dbf

Browse files
committed
test: add more reaction tests for resultObservable
1 parent 3202a86 commit a454dbf

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/query.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,5 +5206,40 @@ describe('Query', () => {
52065206
query.destroy();
52075207
});
52085208
});
5209+
5210+
it.each([
5211+
{ mode: 'deep' as const, calls: 2 },
5212+
{ mode: 'ref' as const, calls: 1 },
5213+
{ mode: 'shallow' as const, calls: 1 },
5214+
{ mode: 'struct' as const, calls: 1 },
5215+
{ mode: false as const, calls: 1 },
5216+
])('nested direct mutation affects reactions only in deep mode ($mode)', async ({
5217+
mode,
5218+
calls,
5219+
}) => {
5220+
const query = await createProceedQuery(
5221+
`nested-mutation-${String(mode)}`,
5222+
mode,
5223+
);
5224+
await query.tricks.runQuery();
5225+
5226+
const reactionSpy = vi.fn();
5227+
const dispose = reaction(
5228+
() => query.result.data?.bar.baz,
5229+
(curr, prev) => reactionSpy(curr, prev),
5230+
{ fireImmediately: true },
5231+
);
5232+
5233+
runInAction(() => {
5234+
if (query.result.data) {
5235+
query.result.data.bar.baz += 1;
5236+
}
5237+
});
5238+
5239+
expect(reactionSpy).toHaveBeenCalledTimes(calls);
5240+
5241+
dispose();
5242+
query.destroy();
5243+
});
52095244
});
52105245
});

0 commit comments

Comments
 (0)