mirror of https://github.com/sveltejs/svelte
parent
3e962b9c90
commit
e022b4b00b
@ -1,23 +1,32 @@
|
||||
export default {
|
||||
test(assert, component) {
|
||||
test(assert, component, target, window) {
|
||||
const buttons = target.querySelectorAll('button');
|
||||
const click = new window.MouseEvent('click');
|
||||
|
||||
const events = [];
|
||||
component.on('foo', (shouldThrow) => {
|
||||
component.$on('foo', event => {
|
||||
const shouldThrow = event.detail;
|
||||
|
||||
events.push(shouldThrow);
|
||||
if (shouldThrow) {
|
||||
throw new Error();
|
||||
}
|
||||
});
|
||||
component.fire('foo', false);
|
||||
|
||||
buttons[1].dispatchEvent(click);
|
||||
assert.equal(events.toString(), 'false');
|
||||
|
||||
let threw = false;
|
||||
try {
|
||||
component.fire('foo', true);
|
||||
buttons[0].dispatchEvent(click);
|
||||
} catch (err) {
|
||||
threw = true;
|
||||
}
|
||||
|
||||
assert.equal(threw, true);
|
||||
assert.equal(events.toString(), 'false,true');
|
||||
component.fire('foo', false);
|
||||
|
||||
buttons[1].dispatchEvent(click);
|
||||
assert.equal(events.toString(), 'false,true,false');
|
||||
},
|
||||
};
|
||||
|
@ -1 +1,8 @@
|
||||
Foo
|
||||
<script>
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
</script>
|
||||
|
||||
<button on:click="{() => dispatch('foo', true)}">throw</button>
|
||||
<button on:click="{() => dispatch('foo', false)}">don't throw</button>
|
@ -1,13 +0,0 @@
|
||||
export default {
|
||||
test ( assert, component ) {
|
||||
let count = 0;
|
||||
|
||||
component.on( 'destroy', function () {
|
||||
assert.equal( this, component );
|
||||
count += 1;
|
||||
});
|
||||
|
||||
component.destroy();
|
||||
assert.equal( count, 1 );
|
||||
}
|
||||
};
|
@ -1 +0,0 @@
|
||||
<div></div>
|
Loading…
Reference in new issue