File tree Expand file tree Collapse file tree 2 files changed +24
-24
lines changed
packages/svelte/tests/runtime-runes/samples/async-attribute Expand file tree Collapse file tree 2 files changed +24
-24
lines changed Original file line number Diff line number Diff line change 11import { flushSync , tick } from 'svelte' ;
2- import { deferred } from '../../../../src/internal/shared/utils.js' ;
3- import { test } from '../../test' ;
4-
5- /** @type {ReturnType<typeof deferred> } */
6- let d ;
2+ import { ok , test } from '../../test' ;
73
84export default test ( {
9- html : `<p>pending</p>` ,
10-
11- get props ( ) {
12- d = deferred ( ) ;
13-
14- return {
15- promise : d . promise
16- } ;
17- } ,
5+ html : `
6+ <button>cool</button>
7+ <button>neat</button>
8+ <button>reset</button>
9+ <p>pending</p>
10+ ` ,
1811
1912 async test ( { assert, target, component } ) {
20- d . resolve ( 'cool' ) ;
13+ const [ cool , neat , reset ] = target . querySelectorAll ( 'button' ) ;
14+
15+ flushSync ( ( ) => cool . click ( ) ) ;
2116 await Promise . resolve ( ) ;
2217 await Promise . resolve ( ) ;
2318 await Promise . resolve ( ) ;
2419 await tick ( ) ;
2520 flushSync ( ) ;
26- assert . htmlEqual ( target . innerHTML , '<p class="cool">hello</p>' ) ;
2721
28- d = deferred ( ) ;
29- component . promise = d . promise ;
30- await tick ( ) ;
31- assert . htmlEqual ( target . innerHTML , '<p class="cool">hello</p>' ) ;
22+ const p = target . querySelector ( 'p' ) ;
23+ ok ( p ) ;
24+ assert . htmlEqual ( p . outerHTML , '<p class="cool">hello</p>' ) ;
25+
26+ flushSync ( ( ) => reset . click ( ) ) ;
27+ assert . htmlEqual ( p . outerHTML , '<p class="cool">hello</p>' ) ;
3228
33- d . resolve ( ' neat' ) ;
29+ flushSync ( ( ) => neat . click ( ) ) ;
3430 await tick ( ) ;
35- assert . htmlEqual ( target . innerHTML , '<p class="neat">hello</p>' ) ;
31+ assert . htmlEqual ( p . outerHTML , '<p class="neat">hello</p>' ) ;
3632 }
3733} ) ;
Original file line number Diff line number Diff line change 11<script >
2- let { promise } = $props ( );
2+ let deferred = $state ( Promise . withResolvers () );
33 </script >
44
5+ <button onclick ={() => deferred .resolve (' cool' )}>cool</button >
6+ <button onclick ={() => deferred .resolve (' neat' )}>neat</button >
7+ <button onclick ={() => deferred = Promise .withResolvers ()}>reset</button >
8+
59<svelte:boundary >
6- <p class ={await promise }>hello</p >
10+ <p class ={await deferred . promise }>hello</p >
711
812 {#snippet pending ()}
913 <p >pending</p >
You can’t perform that action at this time.
0 commit comments