pull/9442/head
baseballyama 3 years ago
parent 8118efd115
commit 22398f390e

@ -0,0 +1,38 @@
import { test, ok } from '../../test';
import { flushSync } from 'svelte';
const log = console.log;
/** @type {string[]} */
let messages = [];
export default test({
before_test: () => {
console.log = (msg) => messages.push(msg);
messages = [];
},
after_test: () => {
console.log = log;
},
test({ assert, target, window }) {
const [button1, button2] = target.querySelectorAll('button');
ok(button1);
ok(button2);
button1.click();
flushSync();
button2.click();
flushSync();
assert.deepEqual(messages, ['after update 0, 0', 'after update 1, 0', 'after update 1, 1']);
assert.htmlEqual(
target.innerHTML,
`
<button>count:
1</button><button>count
2:
1</button><hr>
1
`
);
}
});

@ -0,0 +1,21 @@
<script>
import AfterUpdate from "./sub.svelte";
let count = 0;
let count2 = 0;
function increment() {
count += 1;
}
function increment2() {
count2 += 1;
}
</script>
<button on:click={increment}>
count: {count}
</button>
<button on:click={increment2}>
count 2: {count2}
</button>
<hr />
<AfterUpdate {count} {count2}/>

@ -0,0 +1,12 @@
<script>
import { afterUpdate } from "svelte";
export let count;
export let count2;
afterUpdate(()=>{
console.log(`after update ${count}, ${count2}`);
});
</script>
{count}
Loading…
Cancel
Save