diff --git a/packages/svelte/tests/runtime-runes/samples/array-push-in-effect/_config.js b/packages/svelte/tests/runtime-runes/samples/array-push-in-effect/_config.js new file mode 100644 index 0000000000..a8ad512ed9 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/array-push-in-effect/_config.js @@ -0,0 +1,33 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + /** + * Ensure that mutating an array with push inside an $effect + * does not cause an infinite re-execution loop. + */ + test({ assert, target }) { + const button = target.querySelector('button'); + + // initial render — effect should have run once + assert.htmlEqual( + target.innerHTML, + ` + +
0
+ ` + ); + + // increment count; effect should append one new entry only + flushSync(() => button?.click()); + + assert.htmlEqual( + target.innerHTML, + ` + +0
+1
+ ` + ); + } +}); \ No newline at end of file diff --git a/packages/svelte/tests/runtime-runes/samples/array-push-in-effect/main.svelte b/packages/svelte/tests/runtime-runes/samples/array-push-in-effect/main.svelte new file mode 100644 index 0000000000..a99567b86f --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/array-push-in-effect/main.svelte @@ -0,0 +1,17 @@ + + + +{#each log as item} +{item}
+{/each} \ No newline at end of file