Skip to content

Commit a8108d4

Browse files
committed
add test
1 parent 635319f commit a8108d4

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
async test({ assert, target, logs }) {
6+
const [b1, b2] = target.querySelectorAll('button');
7+
8+
flushSync(() => b1.click());
9+
assert.deepEqual(logs, [0, 1]);
10+
11+
flushSync(() => b1.click());
12+
assert.deepEqual(logs, [0, 1, 2]);
13+
14+
flushSync(() => b2.click());
15+
assert.deepEqual(logs, [0, 1, 2]);
16+
}
17+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script>
2+
let obj = $state({ count: 0 });
3+
4+
$effect.root(() => {
5+
let teardown;
6+
7+
$effect.pre(() => {
8+
if (obj) {
9+
teardown ??= $effect.root(() => {
10+
$effect.pre(() => {
11+
console.log(obj.count);
12+
});
13+
});
14+
} else {
15+
teardown?.();
16+
teardown = null;
17+
}
18+
});
19+
});
20+
</script>
21+
22+
<button onclick={() => ((obj ??= { count: 0 }).count += 1)}>+1</button>
23+
<button onclick={() => (obj = null)}>null</button>

0 commit comments

Comments
 (0)