|
|
|
@ -7,7 +7,7 @@ import type { ComputationSignal } from '../../src/internal/client/types';
|
|
|
|
|
* @param fn A function that returns a function because we first need to setup all the signals
|
|
|
|
|
* and then execute the test in order to simulate a real component
|
|
|
|
|
*/
|
|
|
|
|
function run_test(runes: boolean, fn: () => () => void) {
|
|
|
|
|
function run_test(runes: boolean, fn: (runes: boolean) => () => void) {
|
|
|
|
|
return () => {
|
|
|
|
|
// Create a component context to test runes vs legacy mode
|
|
|
|
|
$.push({}, runes);
|
|
|
|
@ -15,7 +15,7 @@ function run_test(runes: boolean, fn: () => () => void) {
|
|
|
|
|
let execute: any;
|
|
|
|
|
const signal = $.render_effect(
|
|
|
|
|
() => {
|
|
|
|
|
execute = fn();
|
|
|
|
|
execute = fn(runes);
|
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
true,
|
|
|
|
@ -27,7 +27,7 @@ function run_test(runes: boolean, fn: () => () => void) {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test(text: string, fn: () => any) {
|
|
|
|
|
function test(text: string, fn: (runes: boolean) => any) {
|
|
|
|
|
it(`${text} (legacy mode)`, run_test(false, fn));
|
|
|
|
|
it(`${text} (runes mode)`, run_test(true, fn));
|
|
|
|
|
}
|
|
|
|
@ -262,4 +262,25 @@ describe('signals', () => {
|
|
|
|
|
assert.deepEqual(count.c, null);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('schedules rerun when writing to signal before reading it', (runes) => {
|
|
|
|
|
if (!runes) return () => {};
|
|
|
|
|
|
|
|
|
|
const value = $.source({ count: 0 });
|
|
|
|
|
$.user_effect(() => {
|
|
|
|
|
$.set(value, { count: 0 });
|
|
|
|
|
$.get(value);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
let errored = false;
|
|
|
|
|
try {
|
|
|
|
|
$.flushSync();
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
assert.include(e.message, 'ERR_SVELTE_TOO_MANY_UPDATES');
|
|
|
|
|
errored = true;
|
|
|
|
|
}
|
|
|
|
|
assert.equal(errored, true);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|