Skip to content

Commit cf11f58

Browse files
committed
more tests
1 parent b9bc80d commit cf11f58

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
const { initial = 0 } = $props();
3+
4+
let count = $state(initial);
5+
6+
$effect.pre(() => {
7+
if (count > 1) {
8+
throw new Error('too high');
9+
}
10+
});
11+
</script>
12+
13+
{count}
14+
15+
<button onclick={() => count++}>+</button>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ assert, target, logs }) {
6+
let btn = target.querySelector('button');
7+
8+
btn?.click();
9+
btn?.click();
10+
flushSync();
11+
12+
assert.deepEqual(logs, ['error caught 1', 'error caught 2']);
13+
assert.htmlEqual(target.innerHTML, `<div>content before</div><div>content after</div>`);
14+
}
15+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
</script>
4+
5+
<div>content before</div>
6+
7+
<svelte:boundary onerror={(e) => console.log('error caught 2')}>
8+
<svelte:boundary onerror={(e) => console.log('error caught 1')}>
9+
<Child />
10+
11+
{#snippet failed(err, reset)}
12+
<div>An error occurred! {err}</div>
13+
<Child initial={2} />
14+
{/snippet}
15+
</svelte:boundary>
16+
</svelte:boundary>
17+
18+
<div>content after</div>

0 commit comments

Comments
 (0)