File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
packages/svelte/tests/runtime-runes/samples/const-async-function-await Expand file tree Collapse file tree 2 files changed +68
-0
lines changed 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+ html : `<nav><ul><button>Tab 1</button><button>Tab 2</button><button>Tab 3</button></ul></nav> <h1>Tab 1</h1>` ,
6+
7+ async test ( { assert, target } ) {
8+ const [ btn1 , btn2 , btn3 ] = target . querySelectorAll ( 'button' ) ;
9+
10+ btn2 . click ( ) ;
11+ flushSync ( ) ;
12+ assert . htmlEqual (
13+ target . innerHTML ,
14+ `<nav><ul><button>Tab 1</button><button>Tab 2</button><button>Tab 3</button></ul></nav> <h1>Tab 2</h1>`
15+ ) ;
16+
17+ btn3 . click ( ) ;
18+ flushSync ( ) ;
19+ assert . htmlEqual (
20+ target . innerHTML ,
21+ `<nav><ul><button>Tab 1</button><button>Tab 2</button><button>Tab 3</button></ul></nav> <h1>Tab 3</h1>`
22+ ) ;
23+
24+ btn1 . click ( ) ;
25+ flushSync ( ) ;
26+ assert . htmlEqual (
27+ target . innerHTML ,
28+ `<nav><ul><button>Tab 1</button><button>Tab 2</button><button>Tab 3</button></ul></nav> <h1>Tab 1</h1>`
29+ ) ;
30+ }
31+ } ) ;
Original file line number Diff line number Diff line change 1+ <script >
2+ const tabs = [
3+ { id: ' tab1' , label: ' Tab 1' },
4+ { id: ' tab2' , label: ' Tab 2' },
5+ { id: ' tab3' , label: ' Tab 3' }
6+ ]
7+
8+ let activeTab = $state (' tab1' )
9+
10+ const doSomething = async () => {
11+ console .log (' doSomething called' )
12+ }
13+ </script >
14+
15+ <nav >
16+ <ul >
17+ {#each tabs as tab (tab .id )}
18+ {@const switchTab = async () => {
19+ console .log (' switchTab called' , tab .id )
20+ activeTab = tab .id
21+ await doSomething ()
22+ }}
23+
24+ <button onclick ={switchTab }>
25+ {tab .label }
26+ </button >
27+ {/each }
28+ </ul >
29+ </nav >
30+
31+ {#if activeTab == ' tab1' }
32+ <h1 >Tab 1</h1 >
33+ {:else if activeTab == ' tab2' }
34+ <h1 >Tab 2</h1 >
35+ {:else if activeTab == ' tab3' }
36+ <h1 >Tab 3</h1 >
37+ {/if }
You can’t perform that action at this time.
0 commit comments