mirror of https://github.com/sveltejs/svelte
commit
d6207ac900
@ -0,0 +1 @@
|
||||
<button on:click='fire("foo")'>click me</button>
|
@ -0,0 +1,27 @@
|
||||
export default {
|
||||
data: {
|
||||
items: [ 'a', 'b', 'c' ]
|
||||
},
|
||||
|
||||
html: `
|
||||
<div><button>click me</button><button>click me</button><button>click me</button></div>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const buttons = target.querySelectorAll( 'button' );
|
||||
|
||||
const clicks = [];
|
||||
|
||||
component.on( 'foo', item => {
|
||||
clicks.push( item );
|
||||
});
|
||||
|
||||
const event = new window.MouseEvent( 'click' );
|
||||
|
||||
buttons[0].dispatchEvent( event );
|
||||
buttons[2].dispatchEvent( event );
|
||||
|
||||
assert.deepEqual( clicks, [ 'a', 'c' ]);
|
||||
component.teardown();
|
||||
}
|
||||
};
|
@ -0,0 +1,19 @@
|
||||
<div>
|
||||
{{#each items as item}}
|
||||
<Widget on:foo='foo(item)'/>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
components: { Widget },
|
||||
|
||||
methods: {
|
||||
foo ( item ) {
|
||||
this.fire( 'foo', item );
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,31 @@
|
||||
export default {
|
||||
data: {
|
||||
item: {
|
||||
name: 'One',
|
||||
key: 'a'
|
||||
}
|
||||
},
|
||||
|
||||
html: `
|
||||
<select>
|
||||
<option value="a">One</option>
|
||||
<option value="b">Two</option>
|
||||
<option value="c">Three</option>
|
||||
</select>
|
||||
`,
|
||||
|
||||
test ( assert, component, target ) {
|
||||
assert.htmlEqual( target.innerHTML,`
|
||||
<select>
|
||||
<option value="a">One</option>
|
||||
<option value="b">Two</option>
|
||||
<option value="c">Three</option>
|
||||
</select>
|
||||
`);
|
||||
|
||||
assert.equal( target.querySelector( 'select' ).value, 'a' );
|
||||
|
||||
component.teardown();
|
||||
assert.htmlEqual( target.innerHTML, '' );
|
||||
}
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
<select>
|
||||
<option value="{{item.key}}">{{item.name}}</option>
|
||||
<option value="b">Two</option>
|
||||
<option value="c">Three</option>
|
||||
</select>
|
Loading…
Reference in new issue