mirror of https://github.com/sveltejs/svelte
parent
a4d412fb53
commit
d7bd924bbd
@ -0,0 +1,39 @@
|
||||
export default {
|
||||
data: {
|
||||
cats: [
|
||||
{
|
||||
name: "cat 0",
|
||||
checked: false,
|
||||
},
|
||||
{
|
||||
name: "cat 1",
|
||||
checked: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
html: `
|
||||
<input type="checkbox">
|
||||
<input type="checkbox">
|
||||
`,
|
||||
|
||||
test(assert, component, target, window) {
|
||||
const { cats } = component.get();
|
||||
const newCats = cats.slice();
|
||||
newCats.push({
|
||||
name: "cat " + cats.length,
|
||||
checked: false,
|
||||
});
|
||||
component.set({ cats: newCats });
|
||||
|
||||
let inputs = target.querySelectorAll('input');
|
||||
assert.equal(inputs.length, 3);
|
||||
|
||||
const event = new window.Event('change');
|
||||
inputs[0].checked = true;
|
||||
inputs[0].dispatchEvent(event);
|
||||
|
||||
inputs = target.querySelectorAll('input');
|
||||
assert.equal(inputs.length, 3);
|
||||
}
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
{#each cats as cat (cat.name)}
|
||||
<input type="checkbox" bind:checked="cat.checked" on:change="someCheck()">
|
||||
{/each}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
oncreate() {},
|
||||
methods: {
|
||||
someCheck() {
|
||||
console.log('Check');
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue