mirror of https://github.com/sveltejs/svelte
parent
ed83c00f88
commit
4041f0e734
@ -0,0 +1,28 @@
|
|||||||
|
<script>
|
||||||
|
export let items = ['foo', 'bar', 'baz'];
|
||||||
|
export let fromDom = '';
|
||||||
|
export let fromState = '';
|
||||||
|
export let x = 0;
|
||||||
|
export let y = 0;
|
||||||
|
|
||||||
|
function tap(node, callback) {
|
||||||
|
function clickHandler(event) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
node.addEventListener('click', clickHandler, false);
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy() {
|
||||||
|
node.addEventListener('click', clickHandler, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each items as item}
|
||||||
|
<button use:tap='{() => fromDom = this.textContent, fromState = item}'>{item}</button>
|
||||||
|
{/each}
|
||||||
|
|
||||||
|
<p>fromDom: {fromDom}</p>
|
||||||
|
<p>fromState: {fromState}</p>
|
@ -0,0 +1,15 @@
|
|||||||
|
export default {
|
||||||
|
'skip-ssr': true,
|
||||||
|
|
||||||
|
html: '<button>10</button>',
|
||||||
|
|
||||||
|
async test(assert, component, target, window) {
|
||||||
|
const event = new window.MouseEvent('click');
|
||||||
|
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
await button.dispatchEvent(event);
|
||||||
|
|
||||||
|
assert.equal(target.innerHTML, '<button>11</button>');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
export let z = 10;
|
||||||
|
|
||||||
|
function tap(node, callback) {
|
||||||
|
const clickHandler = event => {
|
||||||
|
callback(event);
|
||||||
|
};
|
||||||
|
|
||||||
|
node.addEventListener('click', clickHandler, false);
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy() {
|
||||||
|
node.addEventListener('click', clickHandler, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button use:tap='{() => z += 1}'>{z}</button>
|
@ -0,0 +1,16 @@
|
|||||||
|
export default {
|
||||||
|
html: '<button>???</button>',
|
||||||
|
|
||||||
|
async test(assert, component, target, window) {
|
||||||
|
const event = new window.MouseEvent('click', {
|
||||||
|
clientX: 42,
|
||||||
|
clientY: 42
|
||||||
|
});
|
||||||
|
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
await button.dispatchEvent(event);
|
||||||
|
|
||||||
|
assert.equal(target.innerHTML, '<button>42</button>');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
export default {
|
||||||
|
html: '<button>0, 0</button>',
|
||||||
|
|
||||||
|
test(assert, component, target, window) {
|
||||||
|
const event = new window.MouseEvent('click', {
|
||||||
|
clientX: 42,
|
||||||
|
clientY: 42
|
||||||
|
});
|
||||||
|
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
button.dispatchEvent(event);
|
||||||
|
|
||||||
|
assert.equal(target.innerHTML, '<button>42, 42</button>');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,23 @@
|
|||||||
|
<script>
|
||||||
|
export let x = 0;
|
||||||
|
export let y = 0;
|
||||||
|
|
||||||
|
function tap(node, callback) {
|
||||||
|
function clickHandler(event) {
|
||||||
|
callback({
|
||||||
|
x: event.clientX,
|
||||||
|
y: event.clientY
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
node.addEventListener('click', clickHandler, false);
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy() {
|
||||||
|
node.addEventListener('click', clickHandler, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button use:tap='{event => x = event.x, y = event.y}'>{x}, {y}</button>
|
@ -1 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
export let foo;
|
||||||
|
</script>
|
||||||
|
|
||||||
<button on:click='{() => console.log(foo)}'>click me</button>
|
<button on:click='{() => console.log(foo)}'>click me</button>
|
@ -1,16 +0,0 @@
|
|||||||
export default {
|
|
||||||
html: '<button>???</button>',
|
|
||||||
|
|
||||||
test ( assert, component, target, window ) {
|
|
||||||
const event = new window.MouseEvent( 'click', {
|
|
||||||
clientX: 42,
|
|
||||||
clientY: 42
|
|
||||||
});
|
|
||||||
|
|
||||||
const button = target.querySelector( 'button' );
|
|
||||||
|
|
||||||
button.dispatchEvent( event );
|
|
||||||
|
|
||||||
assert.equal( target.innerHTML, '<button>42</button>' );
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,28 +0,0 @@
|
|||||||
<script>
|
|
||||||
export let items = [ 'foo', 'bar', 'baz' ];
|
|
||||||
export let fromDom = '';
|
|
||||||
export let fromState = '';
|
|
||||||
export let x = 0;
|
|
||||||
export let y = 0;
|
|
||||||
|
|
||||||
function tap(node, callback) {
|
|
||||||
function clickHandler ( event ) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
node.addEventListener( 'click', clickHandler, false );
|
|
||||||
|
|
||||||
return {
|
|
||||||
destroy () {
|
|
||||||
node.addEventListener( 'click', clickHandler, false );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#each items as item}
|
|
||||||
<button on:tap='{() => fromDom = this.textContent, fromState = item}'>{item}</button>
|
|
||||||
{/each}
|
|
||||||
|
|
||||||
<p>fromDom: {fromDom}</p>
|
|
||||||
<p>fromState: {fromState}</p>
|
|
@ -1,15 +0,0 @@
|
|||||||
export default {
|
|
||||||
'skip-ssr': true,
|
|
||||||
|
|
||||||
html: '<button>10</button>',
|
|
||||||
|
|
||||||
test ( assert, component, target, window ) {
|
|
||||||
const event = new window.MouseEvent( 'click' );
|
|
||||||
|
|
||||||
const button = target.querySelector( 'button' );
|
|
||||||
|
|
||||||
button.dispatchEvent( event );
|
|
||||||
|
|
||||||
assert.equal( target.innerHTML, '<button>11</button>' );
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,19 +0,0 @@
|
|||||||
<script>
|
|
||||||
export let z = 10;
|
|
||||||
|
|
||||||
function tap(node, callback) {
|
|
||||||
const clickHandler = event => {
|
|
||||||
callback(event);
|
|
||||||
};
|
|
||||||
|
|
||||||
node.addEventListener( 'click', clickHandler, false );
|
|
||||||
|
|
||||||
return {
|
|
||||||
destroy () {
|
|
||||||
node.addEventListener( 'click', clickHandler, false );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<button on:tap='{() => z += 1}'>{z}</button>
|
|
@ -1,15 +0,0 @@
|
|||||||
export default {
|
|
||||||
html: '<button>0, 0</button>',
|
|
||||||
test ( assert, component, target, window ) {
|
|
||||||
const event = new window.MouseEvent( 'click', {
|
|
||||||
clientX: 42,
|
|
||||||
clientY: 42
|
|
||||||
});
|
|
||||||
|
|
||||||
const button = target.querySelector( 'button' );
|
|
||||||
|
|
||||||
button.dispatchEvent( event );
|
|
||||||
|
|
||||||
assert.equal( target.innerHTML, '<button>42, 42</button>' );
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,23 +0,0 @@
|
|||||||
<script>
|
|
||||||
export let x = 0;
|
|
||||||
export let y = 0;
|
|
||||||
|
|
||||||
function tap(node, callback) {
|
|
||||||
function clickHandler ( event ) {
|
|
||||||
callback({
|
|
||||||
x: event.clientX,
|
|
||||||
y: event.clientY
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
node.addEventListener( 'click', clickHandler, false );
|
|
||||||
|
|
||||||
return {
|
|
||||||
destroy () {
|
|
||||||
node.addEventListener( 'click', clickHandler, false );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<button on:tap='{event => x = event.x, y = event.y}'>{x}, {y}</button>
|
|
@ -1,9 +1,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
export let items;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each items as item}
|
{#each items as item}
|
||||||
<button on:click='{() => dispatch("clicked", { node: this })}'>{item}</button>
|
<button on:click='{e => dispatch("clicked", { node: e.target })}'>{item}</button>
|
||||||
{/each}
|
{/each}
|
@ -1,19 +1,20 @@
|
|||||||
// TODO gah, JSDOM appears to behave differently to real browsers here... probably need to raise an issue
|
// TODO gah, JSDOM appears to behave differently to real browsers here... probably need to raise an issue
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
html: '<input><!---->',
|
html: '<input>',
|
||||||
|
|
||||||
test(assert, component) {
|
test(assert, component) {
|
||||||
component.refs.input.focus();
|
component.input.focus();
|
||||||
|
|
||||||
// this should NOT trigger blur event
|
// this should NOT trigger blur event
|
||||||
component.visible = false;
|
component.visible = false;
|
||||||
assert.ok(!component.blurred);
|
assert.ok(!component.blurred);
|
||||||
|
|
||||||
component.visible = true;
|
component.visible = true;
|
||||||
component.refs.input.focus();
|
component.input.focus();
|
||||||
|
|
||||||
// this SHOULD trigger blur event
|
// this SHOULD trigger blur event
|
||||||
component.refs.input.blur();
|
component.input.blur();
|
||||||
assert.ok(component.blurred);
|
assert.ok(component.blurred);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{#each Object.keys(todos) as key}
|
{#each Object.keys(todos) as key}
|
||||||
<div class='todo {todos[key].done ? "done": ""}'>
|
<div class='todo {todos[key].done ? "done": ""}'>
|
||||||
<input type='checkbox' bind:checked='todos[key].done'>
|
<input type='checkbox' bind:checked={todos[key].done}>
|
||||||
<input type='text' bind:value='todos[key].description'>
|
<input type='text' bind:value={todos[key].description}>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
Loading…
Reference in new issue