mirror of https://github.com/sveltejs/svelte
Add $$dispatch (#3488)
parent
7ea6a2994a
commit
c324878d6b
@ -0,0 +1,24 @@
|
||||
export default {
|
||||
props: {
|
||||
|
||||
},
|
||||
html: `
|
||||
<button></button>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window}) {
|
||||
const button = target.querySelector('button');
|
||||
const event = new window.MouseEvent('click');
|
||||
|
||||
const clicked = [];
|
||||
|
||||
component.$on('clicked', event => {
|
||||
clicked.push(event.detail);
|
||||
});
|
||||
|
||||
button.dispatchEvent(event);
|
||||
|
||||
assert.equal(clicked.length, 1);
|
||||
assert.equal(clicked[0], 'info');
|
||||
}
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
|
||||
function onClick() {
|
||||
$$dispatch('clicked', 'info')
|
||||
}
|
||||
</script>
|
||||
<button on:click={onClick} />
|
@ -0,0 +1,24 @@
|
||||
export default {
|
||||
props: {
|
||||
|
||||
},
|
||||
html: `
|
||||
<button></button>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window}) {
|
||||
const button = target.querySelector('button');
|
||||
const event = new window.MouseEvent('click');
|
||||
|
||||
const clicked = [];
|
||||
|
||||
component.$on('clicked', event => {
|
||||
clicked.push(event.detail);
|
||||
});
|
||||
|
||||
button.dispatchEvent(event);
|
||||
|
||||
assert.equal(clicked.length, 1);
|
||||
assert.equal(clicked[0], 'info');
|
||||
}
|
||||
};
|
@ -0,0 +1,2 @@
|
||||
|
||||
<button on:click={() => $$dispatch('clicked', 'info')} />
|
Loading…
Reference in new issue