mirror of https://github.com/sveltejs/svelte
parent
114a7b4b73
commit
b51bcdd4cc
@ -1,24 +1,7 @@
|
||||
import { test } from '../../test';
|
||||
import { tick } from 'svelte';
|
||||
|
||||
export default test({
|
||||
html: `<button>mutate</button><button>reassign</button><div>0</div>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
|
||||
btn1.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>mutate</button><button>reassign</button><div>1</div>`
|
||||
);
|
||||
|
||||
btn2.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>mutate</button><button>reassign</button><div>2</div>`
|
||||
);
|
||||
async test({ assert, logs }) {
|
||||
assert.deepEqual(logs, ['1', '2', '3', '4', '5', '6']);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,16 +1,18 @@
|
||||
<script>
|
||||
let foo = $state({ count: 0 });
|
||||
let count = $state(0);
|
||||
|
||||
function action() {
|
||||
return {
|
||||
update(foo) {
|
||||
count = foo.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
const action = (element) => {
|
||||
console.log(element.id);
|
||||
};
|
||||
</script>
|
||||
|
||||
<button onclick={() => foo.count++}>mutate</button>
|
||||
<button onclick={() => foo = {...foo, count: foo.count + 1 }}>reassign</button>
|
||||
<div use:action={foo}>{count}</div>
|
||||
<div use:action id="5">
|
||||
<div use:action id="3">
|
||||
<div use:action id="1">
|
||||
</div>
|
||||
<div use:action id="2">
|
||||
</div>
|
||||
</div>
|
||||
<div use:action id="4">
|
||||
</div>
|
||||
</div>
|
||||
<div use:action id="6">
|
||||
</div>
|
||||
|
||||
@ -1,7 +1,24 @@
|
||||
import { test } from '../../test';
|
||||
import { tick } from 'svelte';
|
||||
|
||||
export default test({
|
||||
async test({ assert, logs }) {
|
||||
assert.deepEqual(logs, ['1', '2', '3', '4', '5', '6']);
|
||||
html: `<button>mutate</button><button>reassign</button><div>0</div>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
|
||||
btn1.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>mutate</button><button>reassign</button><div>1</div>`
|
||||
);
|
||||
|
||||
btn2.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>mutate</button><button>reassign</button><div>2</div>`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in new issue