mirror of https://github.com/sveltejs/svelte
parent
9561a36eb2
commit
1e2c8593f2
@ -0,0 +1,32 @@
|
||||
export default {
|
||||
html: `
|
||||
<button>foo</button>
|
||||
<button>bar</button>
|
||||
<button>baz</button>
|
||||
|
||||
<p>fromDom: </p>
|
||||
<p>fromState: </p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const event = new window.MouseEvent( 'click' );
|
||||
|
||||
const buttons = target.querySelectorAll( 'button' );
|
||||
|
||||
buttons[1].dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<button>foo</button>
|
||||
<button>bar</button>
|
||||
<button>baz</button>
|
||||
|
||||
<p>fromDom: bar</p>
|
||||
<p>fromState: bar</p>
|
||||
` );
|
||||
|
||||
assert.equal( component.get( 'fromDom' ), 'bar' );
|
||||
assert.equal( component.get( 'fromState' ), 'bar' );
|
||||
|
||||
component.destroy();
|
||||
}
|
||||
};
|
@ -0,0 +1,34 @@
|
||||
{{#each items as item}}
|
||||
<button on:tap='set({ fromDom: this.textContent, fromState: item })'>{{item}}</button>
|
||||
{{/each}}
|
||||
|
||||
<p>fromDom: {{fromDom}}</p>
|
||||
<p>fromState: {{fromState}}</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
x: 0,
|
||||
y: 0,
|
||||
fromDom: '',
|
||||
fromState: '',
|
||||
items: [ 'foo', 'bar', 'baz' ]
|
||||
}),
|
||||
|
||||
events: {
|
||||
tap ( node, callback ) {
|
||||
function clickHandler ( event ) {
|
||||
callback();
|
||||
}
|
||||
|
||||
node.addEventListener( 'click', clickHandler, false );
|
||||
|
||||
return {
|
||||
teardown () {
|
||||
node.addEventListener( 'click', clickHandler, false );
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,32 @@
|
||||
export default {
|
||||
data: {
|
||||
items: [
|
||||
'foo',
|
||||
'bar',
|
||||
'baz'
|
||||
],
|
||||
selected: 'foo'
|
||||
},
|
||||
|
||||
html: `
|
||||
<button>foo</button>
|
||||
<button>bar</button>
|
||||
<button>baz</button>
|
||||
<p>selected: foo</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const buttons = target.querySelectorAll( 'button' );
|
||||
const event = new window.MouseEvent( 'click' );
|
||||
|
||||
buttons[1].dispatchEvent( event );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<button>foo</button>
|
||||
<button>bar</button>
|
||||
<button>baz</button>
|
||||
<p>selected: bar</p>
|
||||
` );
|
||||
|
||||
component.destroy();
|
||||
}
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
{{#each items as item}}
|
||||
<button on:click='set({ selected: item })'>{{item}}</button>
|
||||
{{/each}}
|
||||
|
||||
<p>selected: {{selected}}</p>
|
@ -1,13 +1,21 @@
|
||||
export default {
|
||||
html: '<button>toggle</button>\n\n<!---->',
|
||||
html: `
|
||||
<button>toggle</button>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const button = target.querySelector( 'button' );
|
||||
const event = new window.MouseEvent( 'click' );
|
||||
|
||||
button.dispatchEvent( event );
|
||||
assert.equal( target.innerHTML, '<button>toggle</button>\n\n<p>hello!</p><!---->' );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<button>toggle</button>
|
||||
<p>hello!</p>
|
||||
` );
|
||||
|
||||
button.dispatchEvent( event );
|
||||
assert.equal( target.innerHTML, '<button>toggle</button>\n\n<!---->' );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<button>toggle</button>
|
||||
` );
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in new issue