chore: add unowned derived memory leak test (#12075)

pull/12078/head
Rich Harris 6 months ago committed by GitHub
parent cabdf97469
commit 90ce1d5f0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -37,6 +37,16 @@ function test(text: string, fn: (runes: boolean) => any) {
it(`${text} (runes mode)`, run_test(true, fn));
}
test.only = (text: string, fn: (runes: boolean) => any) => {
it.only(`${text} (legacy mode)`, run_test(false, fn));
it.only(`${text} (runes mode)`, run_test(true, fn));
};
test.skip = (text: string, fn: (runes: boolean) => any) => {
it.skip(`${text} (legacy mode)`, run_test(false, fn));
it.skip(`${text} (runes mode)`, run_test(true, fn));
};
describe('signals', () => {
test('effect with state and derived in it', () => {
const log: string[] = [];
@ -537,4 +547,29 @@ describe('signals', () => {
assert.deepEqual(branch, 'if');
};
});
test('unowned deriveds are not added as reactions', () => {
var count = source(0);
function create_derived() {
return derived(() => $.get(count) * 2);
}
return () => {
let d = create_derived();
assert.equal($.get(d), 0);
assert.equal(count.reactions, null);
assert.equal(d.deps?.length, 1);
set(count, 1);
assert.equal($.get(d), 2);
assert.equal(count.reactions, null);
assert.equal(d.deps?.length, 1);
d = create_derived();
assert.equal($.get(d), 2);
assert.equal(count.reactions, null);
assert.equal(d.deps?.length, 1);
};
});
});

Loading…
Cancel
Save