mirror of https://github.com/sveltejs/svelte
update stores when assigning to store values - fixes #2170
parent
e87976dc21
commit
3e4dbc630f
@ -0,0 +1,32 @@
|
||||
import { writable } from '../../../../store.js';
|
||||
|
||||
export default {
|
||||
show: 1,
|
||||
props: {
|
||||
count: writable(0)
|
||||
},
|
||||
|
||||
html: `
|
||||
<button>count 0</button>
|
||||
<p>doubled: 0</p>
|
||||
`,
|
||||
|
||||
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>
|
||||
<p>doubled: 2</p>
|
||||
`);
|
||||
|
||||
await component.count.set(42);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>count 42</button>
|
||||
<p>doubled: 84</p>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
import { derive } from 'svelte/store';
|
||||
|
||||
export let count;
|
||||
|
||||
const doubled = derive(count, $count => $count * 2);
|
||||
</script>
|
||||
|
||||
<button on:click="{() => $count += 1}">count {$count}</button>
|
||||
<p>doubled: {$doubled}</p>
|
Loading…
Reference in new issue