Skip to content

Commit b71cad2

Browse files
committed
add test
1 parent 418957b commit b71cad2

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { flushSync } from '../../../../src/index-client.js';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, raf, target }) {
6+
const [btn1, btn2] = target.querySelectorAll('button');
7+
8+
btn1?.click();
9+
btn1?.click();
10+
btn1?.click();
11+
flushSync();
12+
assert.htmlEqual(
13+
target.innerHTML,
14+
'<button>Push</button><button>Remove</button><ul><li>0</li><li>1</li><li>2</li></ul'
15+
);
16+
17+
btn2?.click();
18+
flushSync();
19+
raf.tick(50);
20+
21+
const li = /** @type {HTMLElement & { foo: number }} */ (target.querySelector('ul > li'));
22+
23+
assert.equal(li.foo, 0.5);
24+
25+
btn1?.click();
26+
flushSync();
27+
28+
assert.equal(li.foo, 0.5);
29+
assert.htmlEqual(
30+
target.innerHTML,
31+
'<button>Push</button><button>Remove</button><ul><li>0</li><li>1</li><li>2</li><li>3</li></ul'
32+
);
33+
}
34+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script>
2+
function foo(node, params) {
3+
return {
4+
duration: 100,
5+
tick: (t, u) => {
6+
node.foo = t;
7+
}
8+
};
9+
}
10+
11+
let list = $state([]);
12+
let id = 0;
13+
14+
function push() {
15+
list.push({ id: id++ })
16+
}
17+
18+
function removeFirst() {
19+
list.splice(0, 1);
20+
}
21+
</script>
22+
23+
<button onclick={push}>Push</button>
24+
<button onclick={removeFirst}>Remove</button>
25+
26+
<ul>
27+
{#each list as item (item.id)}
28+
<li out:foo>{item.id}</li>
29+
{/each}
30+
</ul>

0 commit comments

Comments
 (0)