Skip to content

Commit 4cb4847

Browse files
committed
tests
1 parent 0c0662b commit 4cb4847

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { tick } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
async test({ assert, target }) {
6+
await tick();
7+
8+
const [input] = target.querySelectorAll('input');
9+
10+
input.focus();
11+
input.value = '3';
12+
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
13+
await tick();
14+
15+
assert.equal(input.value, '3');
16+
assert.htmlEqual(target.innerHTML, `<p>3</p> <input type="number" />`);
17+
18+
input.focus();
19+
input.value = '1';
20+
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
21+
await tick();
22+
23+
assert.equal(input.value, '2');
24+
assert.htmlEqual(target.innerHTML, `<p>2</p> <input type="number" />`);
25+
}
26+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script>
2+
let value = $state(0)
3+
const min = 2
4+
const max = 5
5+
6+
$effect(() => {
7+
setValue()
8+
})
9+
10+
function setValue() {
11+
if (value < min) {
12+
value = min
13+
}
14+
if (value > max) {
15+
value = max
16+
}
17+
}
18+
</script>
19+
20+
<svelte:boundary>
21+
<p>{await value}</p>
22+
<input type="number" bind:value />
23+
24+
{#snippet pending()}
25+
<p>loading...</p>
26+
{/snippet}
27+
</svelte:boundary>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, target }) {
6+
const [input] = target.querySelectorAll('input');
7+
8+
input.focus();
9+
input.value = '3';
10+
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
11+
flushSync();
12+
13+
assert.equal(input.value, '3');
14+
assert.htmlEqual(target.innerHTML, `<p>3</p> <input type="number" />`);
15+
16+
input.focus();
17+
input.value = '1';
18+
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
19+
flushSync();
20+
21+
assert.equal(input.value, '2');
22+
assert.htmlEqual(target.innerHTML, `<p>2</p> <input type="number" />`);
23+
}
24+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script>
2+
let value = $state(0)
3+
const min = 2
4+
const max = 5
5+
6+
$effect(() => {
7+
setValue()
8+
})
9+
10+
function setValue() {
11+
if (value < min) {
12+
value = min
13+
}
14+
if (value > max) {
15+
value = max
16+
}
17+
}
18+
</script>
19+
20+
<p>{value}</p>
21+
<input type="number" bind:value />

0 commit comments

Comments
 (0)