mirror of https://github.com/sveltejs/svelte
parent
1b454bad4a
commit
b934fba544
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
export let count
|
||||||
|
|
||||||
|
function handleClick() {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={handleClick}>
|
||||||
|
button {count}
|
||||||
|
</button>
|
@ -0,0 +1,38 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<button>main 0</button>
|
||||||
|
<button>button 0</button>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const event = new window.MouseEvent('click');
|
||||||
|
|
||||||
|
const buttons = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
await buttons[0].dispatchEvent(event);
|
||||||
|
assert.htmlEqual(target.innerHTML, `
|
||||||
|
<button>main 1</button>
|
||||||
|
<button>button 1</button>
|
||||||
|
`);
|
||||||
|
|
||||||
|
await buttons[1].dispatchEvent(event);
|
||||||
|
assert.htmlEqual(target.innerHTML, `
|
||||||
|
<button>main 2</button>
|
||||||
|
<button>button 2</button>
|
||||||
|
`);
|
||||||
|
|
||||||
|
// reactive update, reset to 2
|
||||||
|
await buttons[0].dispatchEvent(event);
|
||||||
|
assert.htmlEqual(target.innerHTML, `
|
||||||
|
<button>main 2</button>
|
||||||
|
<button>button 2</button>
|
||||||
|
`);
|
||||||
|
|
||||||
|
// bound to main, reset to 2
|
||||||
|
await buttons[1].dispatchEvent(event);
|
||||||
|
assert.htmlEqual(target.innerHTML, `
|
||||||
|
<button>main 2</button>
|
||||||
|
<button>button 2</button>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
import Button from './Button.svelte';
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
$: if (count > 2) {
|
||||||
|
count = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClick() {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={handleClick}>
|
||||||
|
main {count}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Button bind:count />
|
Loading…
Reference in new issue