Skip to content

Commit 90a0095

Browse files
committed
Add tests for Computed.peek() cycle detection
1 parent dafa95b commit 90a0095

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/core/test/signal.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,19 @@ describe("computed()", () => {
10421042
expect(b.peek()).to.equal(2);
10431043
});
10441044

1045+
it("should detect simple dependency cycles", () => {
1046+
const a: Signal = computed(() => a.peek());
1047+
expect(() => a.peek()).to.throw(/Cycle detected/);
1048+
});
1049+
1050+
it("should detect deep dependency cycles", () => {
1051+
const a: Signal = computed(() => b.value);
1052+
const b: Signal = computed(() => c.value);
1053+
const c: Signal = computed(() => d.value);
1054+
const d: Signal = computed(() => a.peek());
1055+
expect(() => a.peek()).to.throw(/Cycle detected/);
1056+
});
1057+
10451058
it("should not make surrounding effect depend on the computed", () => {
10461059
const s = signal(1);
10471060
const c = computed(() => s.value);

0 commit comments

Comments
 (0)