mirror of https://github.com/sveltejs/svelte
invalidate correctly inside event handlers - fixes #2305
parent
fa47f76447
commit
d614cfa1c7
@ -0,0 +1,35 @@
|
||||
export default {
|
||||
html: `
|
||||
<button>off</button>
|
||||
<button>on</button>
|
||||
<button>off</button>
|
||||
<p>on: 1</p>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window }) {
|
||||
const buttons = target.querySelectorAll('button');
|
||||
const event = new window.MouseEvent('click');
|
||||
|
||||
await buttons[0].dispatchEvent(event);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>on</button>
|
||||
<button>on</button>
|
||||
<button>off</button>
|
||||
<p>on: 2</p>
|
||||
`);
|
||||
|
||||
await buttons[2].dispatchEvent(event);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>on</button>
|
||||
<button>on</button>
|
||||
<button>on</button>
|
||||
<p>on: 3</p>
|
||||
`);
|
||||
|
||||
assert.deepEqual(component.switches, [
|
||||
{ on: true },
|
||||
{ on: true },
|
||||
{ on: true }
|
||||
]);
|
||||
}
|
||||
};
|
@ -0,0 +1,15 @@
|
||||
<script>
|
||||
export let switches = [
|
||||
{ on: false },
|
||||
{ on: true },
|
||||
{ on: false }
|
||||
];
|
||||
</script>
|
||||
|
||||
{#each switches as s}
|
||||
<button on:click="{() => s.on = !s.on}">
|
||||
{s.on ? 'on' : 'off'}
|
||||
</button>
|
||||
{/each}
|
||||
|
||||
<p>on: {switches.filter(s => !!s.on).length}</p>
|
Loading…
Reference in new issue