mirror of https://github.com/sveltejs/svelte
parent
abd8b77106
commit
24e768e4d2
@ -0,0 +1,3 @@
|
||||
<button on:click='fire("select", { selection: "foo" })'>select foo</button>
|
||||
<button on:click='fire("select", { selection: "bar" })'>select bar</button>
|
||||
<button on:click='fire("select", { selection: "baz" })'>select baz</button>
|
@ -0,0 +1,26 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
export default {
|
||||
test ( component, target, window ) {
|
||||
const buttons = target.querySelectorAll( 'button' );
|
||||
const click = new window.MouseEvent( 'click' );
|
||||
|
||||
const selected = [];
|
||||
|
||||
component.on( 'select', selection => {
|
||||
selected.push( selection );
|
||||
});
|
||||
|
||||
buttons[1].dispatchEvent( click );
|
||||
buttons[2].dispatchEvent( click );
|
||||
buttons[1].dispatchEvent( click );
|
||||
buttons[0].dispatchEvent( click );
|
||||
|
||||
assert.deepEqual( selected, [
|
||||
'bar',
|
||||
'baz',
|
||||
'bar',
|
||||
'foo'
|
||||
]);
|
||||
}
|
||||
};
|
@ -0,0 +1,11 @@
|
||||
<div>
|
||||
<Widget on:select='fire("select", event.selection)'/>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
components: { Widget }
|
||||
};
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
<p>i am a widget</p>
|
@ -0,0 +1,23 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
visible: true
|
||||
},
|
||||
html: '<div><!--#if visible--><p>i am a widget</p></div>', // TODO comment should follow component...
|
||||
test ( component ) {
|
||||
let count = 0;
|
||||
|
||||
component.on( 'widgetTornDown', function () {
|
||||
assert.equal( this, component );
|
||||
count += 1;
|
||||
});
|
||||
|
||||
component.set({ visible: false });
|
||||
assert.equal( count, 1 );
|
||||
|
||||
component.set({ visible: true });
|
||||
component.set({ visible: false });
|
||||
assert.equal( count, 2 );
|
||||
}
|
||||
};
|
@ -0,0 +1,13 @@
|
||||
<div>
|
||||
{{#if visible}}
|
||||
<Widget on:teardown='fire("widgetTornDown")'/>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
components: { Widget }
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue