Skip to content

Commit 3353faf

Browse files
committed
chore: add tests for arrays
1 parent 807ffbb commit 3353faf

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

packages/svelte/tests/runtime-runes/samples/state-onchange/_config.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { test } from '../../test';
33

44
export default test({
55
async test({ assert, target, logs }) {
6-
const [btn, btn2, btn3, btn4, btn5, btn6] = target.querySelectorAll('button');
6+
const [btn, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9] = target.querySelectorAll('button');
77
flushSync(() => {
88
btn.click();
99
});
@@ -40,5 +40,47 @@ export default test({
4040
'class proxy',
4141
'class proxy'
4242
]);
43+
44+
flushSync(() => {
45+
btn7.click();
46+
});
47+
assert.deepEqual(logs, [
48+
'count',
49+
'proxy',
50+
'proxy',
51+
'class count',
52+
'class proxy',
53+
'class proxy',
54+
'arr'
55+
]);
56+
57+
flushSync(() => {
58+
btn8.click();
59+
});
60+
assert.deepEqual(logs, [
61+
'count',
62+
'proxy',
63+
'proxy',
64+
'class count',
65+
'class proxy',
66+
'class proxy',
67+
'arr',
68+
'arr'
69+
]);
70+
71+
flushSync(() => {
72+
btn9.click();
73+
});
74+
assert.deepEqual(logs, [
75+
'count',
76+
'proxy',
77+
'proxy',
78+
'class count',
79+
'class proxy',
80+
'class proxy',
81+
'arr',
82+
'arr',
83+
'arr'
84+
]);
4385
}
4486
});

packages/svelte/tests/runtime-runes/samples/state-onchange/main.svelte

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
}
2626
2727
const class_test = new Test();
28+
29+
let arr = $state([0,1,2], {
30+
onchange(){
31+
console.log("arr");
32+
}
33+
})
2834
</script>
2935

3036
<button onclick={()=> count++}>{count}</button>
@@ -33,4 +39,8 @@
3339

3440
<button onclick={()=> class_test.count++}>{class_test.count}</button>
3541
<button onclick={()=> class_test.proxy.count++}>{class_test.proxy.count}</button>
36-
<button onclick={()=> class_test.proxy = {count: class_test.proxy.count+1}}>{class_test.proxy.count}</button>
42+
<button onclick={()=> class_test.proxy = {count: class_test.proxy.count+1}}>{class_test.proxy.count}</button>
43+
44+
<button onclick={()=> arr.push(arr.length)}>push</button>
45+
<button onclick={()=>arr.splice(0, 2)}>splice</button>
46+
<button onclick={()=>arr.sort((a,b)=>b-a)}>sort</button>

0 commit comments

Comments
 (0)