File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
packages/svelte/tests/runtime-runes/samples/async-effect-triggers-await Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
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 [ increment ] = target . querySelectorAll ( 'button' ) ;
9
+
10
+ increment . click ( ) ;
11
+ await tick ( ) ;
12
+ assert . htmlEqual (
13
+ target . innerHTML ,
14
+ `
15
+ <button>increment</button>
16
+ <p>1</p>
17
+ <p>1</p>
18
+ `
19
+ ) ;
20
+
21
+ increment . click ( ) ;
22
+ await tick ( ) ;
23
+ assert . htmlEqual (
24
+ target . innerHTML ,
25
+ `
26
+ <button>increment</button>
27
+ <p>2</p>
28
+ <p>2</p>
29
+ `
30
+ ) ;
31
+ }
32
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ let data = $state (Promise .resolve (0 ));
3
+
4
+ let count = $state (0 );
5
+ let unrelated = $state (0 );
6
+
7
+ $effect (() => {
8
+ data = Promise .resolve (count )
9
+ unrelated = count ;
10
+ });
11
+ </script >
12
+
13
+ <svelte:boundary >
14
+ <button onclick ={() => count += 1 }>increment</button >
15
+ <p >{JSON .stringify ((await data ), null , 2 )}</p >
16
+ {#if true }
17
+ <!-- inside if block to force it into a different render effect -->
18
+ <p >{unrelated }</p >
19
+ {/if }
20
+
21
+ {#snippet pending ()}
22
+ <p >loading...</p >
23
+ {/ snippet }
24
+ </svelte:boundary >
You can’t perform that action at this time.
0 commit comments