Skip to content

Commit 458817d

Browse files
committed
up
1 parent 0066523 commit 458817d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tests/derived.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ describe("derived", () => {
3535

3636
expectSpy(spyEffect, 1, []);
3737
expectSpy(spyDerived, 1, [], 2);
38-
state.a = 3;
3938
await waitScheduler();
4039
expectSpy(spyEffect, 2, []);
4140
expectSpy(spyDerived, 2, [], 6);
@@ -45,15 +44,20 @@ describe("derived", () => {
4544
expectSpy(spyDerived, 3, [], 12);
4645
});
4746

48-
test("derived does not update when unrelated property changes", async () => {
47+
test("derived does not update when unrelated property changes, but updates when dependencies change", async () => {
4948
const state = reactive({ a: 1, b: 2, c: 3 });
50-
const d = derived(() => state.a + state.b);
51-
const spy = jest.fn();
52-
effect(() => spy(d()));
53-
expectSpy(spy, 1, [3]);
49+
const spyDerived = jest.fn(() => state.a + state.b);
50+
const d = derived(spyDerived);
51+
const spyEffect = jest.fn(() => d());
52+
effect(spyEffect);
53+
54+
expectSpy(spyEffect, 1, []);
55+
expectSpy(spyDerived, 1, [], 3);
56+
5457
state.c = 10;
5558
await waitScheduler();
56-
expectSpy(spy, 1, [3]);
59+
expectSpy(spyEffect, 1, []);
60+
expectSpy(spyDerived, 1, [], 3);
5761
});
5862

5963
test("derived does not notify when value is unchanged", async () => {

0 commit comments

Comments
 (0)