mirror of https://github.com/sveltejs/svelte
parent
e394493f71
commit
75bbd6b878
@ -0,0 +1,16 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<button>0</button>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
const event = new window.MouseEvent('click');
|
||||||
|
|
||||||
|
await button.dispatchEvent(event);
|
||||||
|
assert.equal(component.count, 1);
|
||||||
|
|
||||||
|
await button.dispatchEvent(event);
|
||||||
|
assert.equal(component.count, 1);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
export let count = 0;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click|once="{() => count += 1}">{count}</button>
|
@ -0,0 +1,16 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<button>click me</button>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
const event = new window.MouseEvent('click', {
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
await button.dispatchEvent(event);
|
||||||
|
|
||||||
|
assert.ok(component.default_was_prevented);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
export let default_was_prevented;
|
||||||
|
|
||||||
|
function handle_click(event) {
|
||||||
|
default_was_prevented = event.defaultPrevented;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click|preventDefault={handle_click}>click me</button>
|
@ -0,0 +1,19 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<div>
|
||||||
|
<button>click me</button>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
const event = new window.MouseEvent('click', {
|
||||||
|
bubbles: true
|
||||||
|
});
|
||||||
|
|
||||||
|
await button.dispatchEvent(event);
|
||||||
|
|
||||||
|
assert.ok(component.inner_clicked);
|
||||||
|
assert.ok(!component.outer_clicked);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
export let inner_clicked;
|
||||||
|
export let outer_clicked;
|
||||||
|
|
||||||
|
function handle_inner_click(event) {
|
||||||
|
inner_clicked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_outer_click(event) {
|
||||||
|
outer_clicked = true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div on:click={handle_outer_click}>
|
||||||
|
<button on:click|stopPropagation={handle_inner_click}>click me</button>
|
||||||
|
</div>
|
Loading…
Reference in new issue