Skip to content

Commit d57491f

Browse files
authored
chore: add unowned signals test (#12275)
1 parent a360e04 commit d57491f

File tree

1 file changed

+36
-0
lines changed
  • packages/svelte/tests/signals

1 file changed

+36
-0
lines changed

packages/svelte/tests/signals/test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,4 +574,40 @@ describe('signals', () => {
574574
assert.equal(d.deps?.length, 1);
575575
};
576576
});
577+
578+
test('unowned deriveds are correctly connected and disconnected from the graph', () => {
579+
var count = source(0);
580+
581+
function create_derived() {
582+
return derived(() => $.get(count) * 2);
583+
}
584+
585+
return () => {
586+
let d = create_derived();
587+
588+
const destroy = effect_root(() => {
589+
render_effect(() => {
590+
assert.equal($.get(d), 0);
591+
});
592+
});
593+
594+
assert.equal($.get(d), 0);
595+
assert.equal(count.reactions?.length, 1);
596+
assert.equal(d.deps?.length, 1);
597+
598+
set(count, 1);
599+
assert.equal($.get(d), 2);
600+
assert.equal(count.reactions?.length, 1);
601+
assert.equal(d.deps?.length, 1);
602+
603+
destroy();
604+
605+
assert.equal(count.reactions, null);
606+
607+
set(count, 2);
608+
assert.equal($.get(d), 4);
609+
assert.equal(count.reactions, null);
610+
assert.equal(d.deps?.length, 1);
611+
};
612+
});
577613
});

0 commit comments

Comments
 (0)