Skip to content

Commit 2cd6ddf

Browse files
committed
add test sample
1 parent 435da13 commit 2cd6ddf

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
class Y {
3+
foo = $state(0);
4+
}
5+
6+
let y = $derived(new Y());
7+
</script>
8+
9+
<button onclick={() => y.foo++}>click</button>
10+
<p>{y.foo}</p>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
skip_no_async: true,
6+
async test({ assert, target }) {
7+
const forkButton = target.querySelector('button');
8+
9+
flushSync(() => {
10+
forkButton?.click();
11+
});
12+
13+
const [, clickButton] = target.querySelectorAll('button');
14+
const p = target.querySelector('p');
15+
16+
assert.equal(p?.textContent, '0');
17+
18+
flushSync(() => {
19+
clickButton?.click();
20+
});
21+
22+
assert.equal(p?.textContent, '1');
23+
}
24+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
import { fork } from 'svelte';
3+
import Child from './Child.svelte';
4+
5+
let x = $state(false);
6+
</script>
7+
8+
<button onclick={() => {
9+
const f = fork(() => {
10+
x = true;
11+
});
12+
f.commit();
13+
}}>fork</button>
14+
15+
{#if x}
16+
<Child />
17+
{/if}

0 commit comments

Comments
 (0)