mirror of https://github.com/sveltejs/svelte
parent
28462a5ef7
commit
718056d446
@ -0,0 +1,59 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `
|
||||
<button>1 + 2 + 3 = 6</button>
|
||||
<button>delete 2</button>
|
||||
<button>clear</button>
|
||||
<span>1</span>
|
||||
<span>2</span>
|
||||
<span>3</span>
|
||||
<strong>set.has(2): true</strong>
|
||||
`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [add, delete2, clear] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => add?.click());
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>1 + 2 + 3 + 4 = 10</button>
|
||||
<button>delete 2</button>
|
||||
<button>clear</button>
|
||||
<span>1</span>
|
||||
<span>2</span>
|
||||
<span>3</span>
|
||||
<span>4</span>
|
||||
<strong>set.has(2): true</strong>
|
||||
`
|
||||
);
|
||||
|
||||
flushSync(() => delete2?.click());
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>1 + 3 + 4 = 8</button>
|
||||
<button>delete 2</button>
|
||||
<button>clear</button>
|
||||
<span>1</span>
|
||||
<span>3</span>
|
||||
<span>4</span>
|
||||
<strong>set.has(2): false</strong>
|
||||
`
|
||||
);
|
||||
|
||||
flushSync(() => clear?.click());
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>1 = 1</button>
|
||||
<button>delete 2</button>
|
||||
<button>clear</button>
|
||||
<span>1</span>
|
||||
<strong>set.has(2): false</strong>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
const set = $state(new Set([1, 2, 3]));
|
||||
const sum = $derived(Array.from(set).reduce((a, b) => a + b, 0));
|
||||
</script>
|
||||
|
||||
<button onclick={() => set.add(set.size + 1)}>
|
||||
{[...set].join(' + ')} = {sum}
|
||||
</button>
|
||||
|
||||
<button onclick={() => { set.delete(2) }}>
|
||||
delete 2
|
||||
</button>
|
||||
|
||||
<button onclick={() => { set.clear(); set.add(1) }}>
|
||||
clear
|
||||
</button>
|
||||
|
||||
{#each set as n}
|
||||
<span>{n}</span>
|
||||
{/each}
|
||||
|
||||
<strong>set.has(2): {set.has(2)}</strong>
|
Loading…
Reference in new issue