mirror of https://github.com/sveltejs/svelte
bind this in bubbled events (#6417)
parent
b9e19004cb
commit
7d39e676c5
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
</script>
|
||||
|
||||
<button on:click={() => dispatch('bar')} />
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
import Inner from './Inner.svelte';
|
||||
</script>
|
||||
|
||||
<button on:click>click me</button>
|
||||
<Inner on:bar />
|
@ -0,0 +1,11 @@
|
||||
export default {
|
||||
test({ assert, component, target, window }) {
|
||||
const [button1, button2] = target.querySelectorAll('button');
|
||||
|
||||
button1.dispatchEvent(new window.MouseEvent('click'));
|
||||
button2.dispatchEvent(new window.MouseEvent('click'));
|
||||
|
||||
assert.strictEqual(component.logs[0], button1);
|
||||
assert.ok(component.logs[1] instanceof component.Inner);
|
||||
}
|
||||
};
|
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
import Widget from './Widget.svelte';
|
||||
import Inner from './Inner.svelte';
|
||||
|
||||
export let logs = [];
|
||||
export { Inner };
|
||||
|
||||
function foo() {
|
||||
logs.push(this);
|
||||
}
|
||||
function bar() {
|
||||
logs.push(this);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Widget on:click={foo} on:bar={bar} />
|
Loading…
Reference in new issue