Skip to content

Commit 3f73e06

Browse files
committed
add test
1 parent 3fe779f commit 3f73e06

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, target, logs }) {
6+
const button = target.querySelector('button');
7+
8+
flushSync(() => button?.click());
9+
10+
assert.htmlEqual(
11+
target.innerHTML,
12+
`
13+
<button>increment</button>
14+
<p>1/2</p
15+
`
16+
);
17+
18+
assert.deepEqual(logs, [0, 0]);
19+
}
20+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script>
2+
class Foo {
3+
value = $state(0);
4+
double = $derived(this.value * 2);
5+
6+
constructor() {
7+
console.log(this.value, this.double);
8+
}
9+
10+
increment() {
11+
this.value++;
12+
}
13+
}
14+
15+
let foo = $state();
16+
17+
$effect(() => {
18+
foo = new Foo();
19+
});
20+
</script>
21+
22+
<button onclick={() => foo.increment()}>increment</button>
23+
24+
{#if foo}
25+
<p>{foo.value}/{foo.double}</p>
26+
{/if}

0 commit comments

Comments
 (0)