From b985eea817c1b1cddf10d9ad9b6c0d3b2e0f4b8c Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 5 Jul 2024 14:46:49 +0100 Subject: [PATCH] add test --- .../samples/effect-root-3/_config.js | 28 +++++++++++++++++++ .../samples/effect-root-3/main.svelte | 11 ++++++++ .../samples/effect-root-3/root.svelte.js | 20 +++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 packages/svelte/tests/runtime-runes/samples/effect-root-3/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/effect-root-3/main.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/effect-root-3/root.svelte.js diff --git a/packages/svelte/tests/runtime-runes/samples/effect-root-3/_config.js b/packages/svelte/tests/runtime-runes/samples/effect-root-3/_config.js new file mode 100644 index 0000000000..fe2a8bb499 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/effect-root-3/_config.js @@ -0,0 +1,28 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + async test({ assert, target, logs }) { + const [b1, b2, b3] = target.querySelectorAll('button'); + + flushSync(() => { + b1.click(); + b2.click(); + }); + + assert.deepEqual(logs, [0, 1]); + + flushSync(() => { + b3.click(); + }); + + assert.deepEqual(logs, [0, 1, 'cleanup 1', 'cleanup 2']); + + flushSync(() => { + b1.click(); + b2.click(); + }); + + assert.deepEqual(logs, [0, 1, 'cleanup 1', 'cleanup 2']); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/effect-root-3/main.svelte b/packages/svelte/tests/runtime-runes/samples/effect-root-3/main.svelte new file mode 100644 index 0000000000..fb37dfe47d --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/effect-root-3/main.svelte @@ -0,0 +1,11 @@ + + + + + diff --git a/packages/svelte/tests/runtime-runes/samples/effect-root-3/root.svelte.js b/packages/svelte/tests/runtime-runes/samples/effect-root-3/root.svelte.js new file mode 100644 index 0000000000..4e05cdf8ef --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/effect-root-3/root.svelte.js @@ -0,0 +1,20 @@ +export function with_root(get_x) { + const cleanup = $effect.root(() => { + $effect(() => { + console.log(get_x()); + }); + + const nested_cleanup = $effect.root(() => { + return () => { + console.log('cleanup 2'); + }; + }); + + return () => { + console.log('cleanup 1'); + nested_cleanup(); + }; + }); + + return cleanup; +}