File tree Expand file tree Collapse file tree 4 files changed +98
-0
lines changed
packages/svelte/tests/runtime-runes/samples
async-binding-update-while-focused
binding-update-while-focused-2 Expand file tree Collapse file tree 4 files changed +98
-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 [ input ] = target . querySelectorAll ( 'input' ) ;
9+
10+ input . focus ( ) ;
11+ input . value = '3' ;
12+ input . dispatchEvent ( new InputEvent ( 'input' , { bubbles : true } ) ) ;
13+ await tick ( ) ;
14+
15+ assert . equal ( input . value , '3' ) ;
16+ assert . htmlEqual ( target . innerHTML , `<p>3</p> <input type="number" />` ) ;
17+
18+ input . focus ( ) ;
19+ input . value = '1' ;
20+ input . dispatchEvent ( new InputEvent ( 'input' , { bubbles : true } ) ) ;
21+ await tick ( ) ;
22+
23+ assert . equal ( input . value , '2' ) ;
24+ assert . htmlEqual ( target . innerHTML , `<p>2</p> <input type="number" />` ) ;
25+ }
26+ } ) ;
Original file line number Diff line number Diff line change 1+ <script >
2+ let value = $state (0 )
3+ const min = 2
4+ const max = 5
5+
6+ $effect (() => {
7+ setValue ()
8+ })
9+
10+ function setValue () {
11+ if (value < min) {
12+ value = min
13+ }
14+ if (value > max) {
15+ value = max
16+ }
17+ }
18+ </script >
19+
20+ <svelte:boundary >
21+ <p >{await value }</p >
22+ <input type =" number" bind:value />
23+
24+ {#snippet pending ()}
25+ <p >loading...</p >
26+ {/ snippet }
27+ </svelte:boundary >
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 } ) {
6+ const [ input ] = target . querySelectorAll ( 'input' ) ;
7+
8+ input . focus ( ) ;
9+ input . value = '3' ;
10+ input . dispatchEvent ( new InputEvent ( 'input' , { bubbles : true } ) ) ;
11+ flushSync ( ) ;
12+
13+ assert . equal ( input . value , '3' ) ;
14+ assert . htmlEqual ( target . innerHTML , `<p>3</p> <input type="number" />` ) ;
15+
16+ input . focus ( ) ;
17+ input . value = '1' ;
18+ input . dispatchEvent ( new InputEvent ( 'input' , { bubbles : true } ) ) ;
19+ flushSync ( ) ;
20+
21+ assert . equal ( input . value , '2' ) ;
22+ assert . htmlEqual ( target . innerHTML , `<p>2</p> <input type="number" />` ) ;
23+ }
24+ } ) ;
Original file line number Diff line number Diff line change 1+ <script >
2+ let value = $state (0 )
3+ const min = 2
4+ const max = 5
5+
6+ $effect (() => {
7+ setValue ()
8+ })
9+
10+ function setValue () {
11+ if (value < min) {
12+ value = min
13+ }
14+ if (value > max) {
15+ value = max
16+ }
17+ }
18+ </script >
19+
20+ <p >{value }</p >
21+ <input type =" number" bind:value />
You can’t perform that action at this time.
0 commit comments