mirror of https://github.com/sveltejs/svelte
parent
48f1f6b4d0
commit
f991a41d83
@ -0,0 +1,40 @@
|
||||
import { writable } from '../../../../store.js';
|
||||
|
||||
export default {
|
||||
skip: true,
|
||||
|
||||
props: {
|
||||
things: [
|
||||
writable('a'),
|
||||
writable('b'),
|
||||
writable('c')
|
||||
]
|
||||
},
|
||||
|
||||
html: `
|
||||
<button>a</button>
|
||||
<button>b</button>
|
||||
<button>c</button>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window }) {
|
||||
const buttons = target.querySelectorAll('button');
|
||||
const click = new window.MouseEvent('click');
|
||||
|
||||
await buttons[1].dispatchEvent(click);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>a</button>
|
||||
<button>B</button>
|
||||
<button>c</button>
|
||||
`);
|
||||
|
||||
await component.things[1].set('d');
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>d</button>
|
||||
<button>B</button>
|
||||
<button>c</button>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
export let things;
|
||||
</script>
|
||||
|
||||
{#each things as thing}
|
||||
<button on:click="{() => thing.update(n => n.toUpperCase())}">{$thing}</button>
|
||||
{/each}
|
@ -0,0 +1,28 @@
|
||||
import { writable } from '../../../../store.js';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
count: writable(0)
|
||||
},
|
||||
|
||||
html: `
|
||||
<button>double 0</button>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window }) {
|
||||
const button = target.querySelector('button');
|
||||
const click = new window.MouseEvent('click');
|
||||
|
||||
await button.dispatchEvent(click);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>double 2</button>
|
||||
`);
|
||||
|
||||
await component.count.set(42);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>double 84</button>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
export let count;
|
||||
|
||||
let double;
|
||||
$: double = $count * 2;
|
||||
</script>
|
||||
|
||||
<button on:click="{() => count.update(n => n + 1)}">double {double}</button>
|
@ -0,0 +1,28 @@
|
||||
import { writable } from '../../../../store.js';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
count: writable(0)
|
||||
},
|
||||
|
||||
html: `
|
||||
<button>count 0</button>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window }) {
|
||||
const button = target.querySelector('button');
|
||||
const click = new window.MouseEvent('click');
|
||||
|
||||
await button.dispatchEvent(click);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>count 1</button>
|
||||
`);
|
||||
|
||||
await component.count.set(42);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>count 42</button>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
export let count;
|
||||
</script>
|
||||
|
||||
<button on:click="{() => count.update(n => n + 1)}">count {$count}</button>
|
@ -0,0 +1,11 @@
|
||||
export default {
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
props: {
|
||||
count: 0
|
||||
},
|
||||
|
||||
error: `'count' is not a store with a 'subscribe' method`
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
export let count;
|
||||
</script>
|
||||
|
||||
<button on:click="{() => count.update(n => n + 1)}">count {$count}</button>
|
@ -0,0 +1,9 @@
|
||||
import { writable } from '../../../../store.js';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
count: writable(0)
|
||||
},
|
||||
|
||||
error: `The $ prefix is reserved, and cannot be used for variable and import names`
|
||||
};
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
export let count;
|
||||
let $count;
|
||||
</script>
|
||||
|
||||
<button on:click="{() => count.update(n => n + 1)}">count {$count}</button>
|
Loading…
Reference in new issue