File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
packages/svelte/tests/runtime-runes/samples/error-boundary-17 Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments