Skip to content

Commit

Permalink
chore: add unowned signals test
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Jul 3, 2024
1 parent a360e04 commit 032340b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/svelte/tests/signals/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,40 @@ describe('signals', () => {
assert.equal(d.deps?.length, 1);
};
});

test('unowned deriveds are correctly connected and disconnected from the graph', () => {
var count = source(0);

function create_derived() {
return derived(() => $.get(count) * 2);
}

return () => {
let d = create_derived();

const destroy = effect_root(() => {
render_effect(() => {
assert.equal($.get(d), 0);
});
});

assert.equal($.get(d), 0);
assert.equal(count.reactions?.length, 1);
assert.equal(d.deps?.length, 1);

set(count, 1);
assert.equal($.get(d), 2);
assert.equal(count.reactions?.length, 1);
assert.equal(d.deps?.length, 1);

destroy();

assert.equal(count.reactions, null);

set(count, 2);
assert.equal($.get(d), 4);
assert.equal(count.reactions, null);
assert.equal(d.deps?.length, 1);
};
});
});

0 comments on commit 032340b

Please sign in to comment.