mirror of https://github.com/sveltejs/svelte
better solution for preventing blowback with inter-component bindings, also fixes #19
parent
20bf76b578
commit
7736866397
@ -0,0 +1,9 @@
|
|||||||
|
<button on:click='set({ count: count + 1 })'>+1</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data: () => ({
|
||||||
|
count: 0
|
||||||
|
})
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,27 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<button>+1</button>
|
||||||
|
<p>count: 10</p>
|
||||||
|
`,
|
||||||
|
|
||||||
|
test ( assert, component, target, window ) {
|
||||||
|
const click = new window.MouseEvent( 'click' );
|
||||||
|
const button = target.querySelector( 'button' );
|
||||||
|
|
||||||
|
button.dispatchEvent( click );
|
||||||
|
|
||||||
|
assert.equal( component.get( 'x' ), 11 );
|
||||||
|
assert.htmlEqual( target.innerHTML, `
|
||||||
|
<button>+1</button>
|
||||||
|
<p>count: 11</p>
|
||||||
|
` );
|
||||||
|
|
||||||
|
button.dispatchEvent( click );
|
||||||
|
|
||||||
|
assert.equal( component.get( 'x' ), 12 );
|
||||||
|
assert.htmlEqual( target.innerHTML, `
|
||||||
|
<button>+1</button>
|
||||||
|
<p>count: 12</p>
|
||||||
|
` );
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
<Counter bind:count='x'/>
|
||||||
|
<p>count: {{x}}</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Counter from './Counter.html';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data: () => ({
|
||||||
|
x: 10
|
||||||
|
}),
|
||||||
|
|
||||||
|
components: {
|
||||||
|
Counter
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue