Skip to content

Commit d69a379

Browse files
committed
add test
1 parent a9e7827 commit d69a379

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
async test({ assert, target, logs }) {
6+
const [btn1] = target.querySelectorAll('button');
7+
8+
btn1.click();
9+
flushSync();
10+
11+
await Promise.resolve();
12+
await Promise.resolve();
13+
14+
assert.deepEqual(logs, ['cleanup']);
15+
}
16+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script>
2+
import { createSubscriber } from 'svelte/reactivity';
3+
4+
class MyStore {
5+
#subscribe;
6+
#data = $state([
7+
['a', [1, 2]],
8+
['b', [3, 4]]
9+
]);
10+
#id;
11+
12+
constructor(options) {
13+
options?.someBoolean;
14+
this.#id = options?.id;
15+
this.#subscribe = createSubscriber(() => {
16+
debugger
17+
return () => {
18+
console.log('cleanup');
19+
};
20+
});
21+
}
22+
23+
get data() {
24+
this.#subscribe();
25+
return this.#data;
26+
}
27+
set data(v) {
28+
this.#data = v;
29+
}
30+
}
31+
32+
let storeOptions = $state({
33+
someBoolean: false,
34+
id: 0
35+
});
36+
37+
let myStore = $derived(new MyStore(storeOptions));
38+
</script>
39+
40+
<button
41+
onclick={() => {
42+
storeOptions.someBoolean = !storeOptions.someBoolean;
43+
}}>+</button
44+
>
45+
46+
{#each myStore.data as _}{/each}

0 commit comments

Comments
 (0)