mirror of https://github.com/sveltejs/svelte
set select multiple value with spread (#4894)
parent
d61a7a0b95
commit
24ef4e1181
@ -0,0 +1,39 @@
|
|||||||
|
export default {
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const [input1, input2] = target.querySelectorAll('input');
|
||||||
|
const select = target.querySelector('select');
|
||||||
|
const [option1, option2] = select.childNodes;
|
||||||
|
|
||||||
|
let selections = Array.from(select.selectedOptions);
|
||||||
|
assert.equal(selections.length, 2);
|
||||||
|
assert.ok(selections.includes(option1));
|
||||||
|
assert.ok(selections.includes(option2));
|
||||||
|
|
||||||
|
const event = new window.Event('change');
|
||||||
|
|
||||||
|
input1.checked = false;
|
||||||
|
await input1.dispatchEvent(event);
|
||||||
|
|
||||||
|
selections = Array.from(select.selectedOptions);
|
||||||
|
assert.equal(selections.length, 1);
|
||||||
|
assert.ok(!selections.includes(option1));
|
||||||
|
assert.ok(selections.includes(option2));
|
||||||
|
|
||||||
|
input2.checked = false;
|
||||||
|
await input2.dispatchEvent(event);
|
||||||
|
input1.checked = true;
|
||||||
|
await input1.dispatchEvent(event);
|
||||||
|
|
||||||
|
selections = Array.from(select.selectedOptions);
|
||||||
|
assert.equal(selections.length, 1);
|
||||||
|
assert.ok(selections.includes(option1));
|
||||||
|
assert.ok(!selections.includes(option2));
|
||||||
|
|
||||||
|
component.spread = { value: ['Hello', 'World'] };
|
||||||
|
|
||||||
|
selections = Array.from(select.selectedOptions);
|
||||||
|
assert.equal(selections.length, 2);
|
||||||
|
assert.ok(selections.includes(option1));
|
||||||
|
assert.ok(selections.includes(option2));
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
let value = ['Hello', 'World'];
|
||||||
|
export let spread = {};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<select multiple {value} {...spread}>
|
||||||
|
<option>Hello</option>
|
||||||
|
<option>World</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input type="checkbox" value="Hello" bind:group={value}>
|
||||||
|
<input type="checkbox" value="World" bind:group={value}>
|
Loading…
Reference in new issue