-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/svelte/tests/runtime-runes/samples/each-dynamic-html/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { flushSync } from '../../../../src/index-client'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: `<button>add item</button><button>make span</button><button>reverse</button>`, | ||
|
||
async test({ assert, target }) { | ||
const [btn1, btn2, btn3] = target.querySelectorAll('button'); | ||
|
||
flushSync(() => { | ||
btn1?.click(); | ||
btn1?.click(); | ||
btn1?.click(); | ||
}); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>add item</button><button>make span</button><button>reverse</button><div>Item 1</div><div>Item 2</div><div>Item 3</div>` | ||
); | ||
|
||
flushSync(() => { | ||
btn2?.click(); | ||
}); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>add item</button><button>make span</button><button>reverse</button><span>Item 1</span><span>Item 2</span><span>Item 3</span>` | ||
); | ||
|
||
flushSync(() => { | ||
btn3?.click(); | ||
}); | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>add item</button><button>make span</button><button>reverse</button><span>Item 3</span><span>Item 2</span><span>Item 1</span>` | ||
); | ||
} | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/svelte/tests/runtime-runes/samples/each-dynamic-html/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script> | ||
let items = $state([]); | ||
function add_item() { | ||
items.push({ | ||
id: items.length, | ||
text: 'Item ' + (items.length + 1), | ||
html: '<div>Item ' + (items.length + 1) + '</div>', | ||
dom: null, | ||
}) | ||
} | ||
function make_span() { | ||
items.forEach(item => { | ||
item.html = item.html.replace(/div/g, 'span') | ||
}) | ||
} | ||
function reverse() { | ||
items.reverse(); | ||
} | ||
</script> | ||
|
||
<button on:click={add_item}>add item</button> | ||
<button on:click={make_span}>make span</button> | ||
<button on:click={reverse}>reverse</button> | ||
|
||
{#each items as item (item.id)} | ||
{@html item.html} | ||
{/each} |