mirror of https://github.com/sveltejs/svelte
parent
6d7caf3fd3
commit
1e81913a50
@ -0,0 +1,13 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<button>10</button>`,
|
||||||
|
ssrHtml: `<button>0</button>`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>10</button>`);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
<script>
|
||||||
|
class Counter {
|
||||||
|
count = $state(0);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
$effect(() => {
|
||||||
|
this.count = 10;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const counter = new Counter();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={() => counter.count++}>{counter.count}</button>
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<button>10</button>`,
|
||||||
|
ssrHtml: `<button>0</button>`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>10</button>`);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
class Counter {
|
||||||
|
#count = $state(0);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
$effect(() => {
|
||||||
|
this.#count = 10;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getCount() {
|
||||||
|
return this.#count;
|
||||||
|
}
|
||||||
|
|
||||||
|
increment() {
|
||||||
|
this.#count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const counter = new Counter();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={() => counter.increment()}>{counter.getCount()}</button>
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
import { flushSync } from 'svelte';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
get props() {
|
||||||
|
return { log: [] };
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target, component }) {
|
||||||
|
const [b1] = target.querySelectorAll('button');
|
||||||
|
flushSync(() => {
|
||||||
|
b1.click();
|
||||||
|
});
|
||||||
|
flushSync(() => {
|
||||||
|
b1.click();
|
||||||
|
});
|
||||||
|
assert.deepEqual(component.log, ['init 0', 'cleanup 2', 'init 2', 'cleanup 4', 'init 4']);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
<script>
|
||||||
|
const {log} = $props();
|
||||||
|
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
let double = $derived(count * 2)
|
||||||
|
|
||||||
|
log.push('init ' + double);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
log.push('cleanup ' + double);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={() => count++ }>Click</button>
|
||||||
Loading…
Reference in new issue