mirror of https://github.com/sveltejs/svelte
update select value bindings at the end of the cycle (fixes #476)
parent
ef630b1483
commit
02e55e8f7a
@ -0,0 +1,34 @@
|
|||||||
|
export default {
|
||||||
|
data: {
|
||||||
|
items: [],
|
||||||
|
selected: null
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `
|
||||||
|
<select></select>
|
||||||
|
<p>selected: nothing</p>
|
||||||
|
`,
|
||||||
|
|
||||||
|
test ( assert, component, target ) {
|
||||||
|
component.set({
|
||||||
|
items: [ 'one', 'two', 'three' ],
|
||||||
|
selected: 'two'
|
||||||
|
});
|
||||||
|
|
||||||
|
const options = target.querySelectorAll( 'option' );
|
||||||
|
assert.ok( !options[0].selected );
|
||||||
|
assert.ok( options[1].selected );
|
||||||
|
assert.ok( !options[2].selected );
|
||||||
|
|
||||||
|
assert.htmlEqual( target.innerHTML, `
|
||||||
|
<select>
|
||||||
|
<option>one</option>
|
||||||
|
<option>two</option>
|
||||||
|
<option>three</option>
|
||||||
|
</select>
|
||||||
|
<p>selected: two</p>
|
||||||
|
` );
|
||||||
|
|
||||||
|
component.destroy();
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,7 @@
|
|||||||
|
<select bind:value='selected'>
|
||||||
|
{{#each items as item}}
|
||||||
|
<option>{{item}}</option>
|
||||||
|
{{/each}}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<p>selected: {{selected || 'nothing'}}</p>
|
Loading…
Reference in new issue