@@ -6,15 +6,15 @@ import * as $ from '../../src/internal/client/runtime';
6
6
* @param fn A function that returns a function because we first need to setup all the signals
7
7
* and then execute the test in order to simulate a real component
8
8
*/
9
- function run_test ( runes : boolean , fn : ( ) => ( ) => void ) {
9
+ function run_test ( runes : boolean , fn : ( runes : boolean ) => ( ) => void ) {
10
10
return ( ) => {
11
11
// Create a component context to test runes vs legacy mode
12
12
$ . push ( { } , runes ) ;
13
13
// Create a render context so that effect validations etc don't fail
14
14
let execute : any ;
15
15
const signal = $ . render_effect (
16
16
( ) => {
17
- execute = fn ( ) ;
17
+ execute = fn ( runes ) ;
18
18
} ,
19
19
null ,
20
20
true ,
@@ -26,7 +26,7 @@ function run_test(runes: boolean, fn: () => () => void) {
26
26
} ;
27
27
}
28
28
29
- function test ( text : string , fn : ( ) => any ) {
29
+ function test ( text : string , fn : ( runes : boolean ) => any ) {
30
30
it ( `${ text } (legacy mode)` , run_test ( false , fn ) ) ;
31
31
it ( `${ text } (runes mode)` , run_test ( true , fn ) ) ;
32
32
}
@@ -228,4 +228,25 @@ describe('signals', () => {
228
228
assert . deepEqual ( count . c , null ) ;
229
229
} ;
230
230
} ) ;
231
+
232
+ test ( 'schedules rerun when writing to signal before reading it' , ( runes ) => {
233
+ if ( ! runes ) return ( ) => { } ;
234
+
235
+ const value = $ . source ( { count : 0 } ) ;
236
+ $ . user_effect ( ( ) => {
237
+ $ . set ( value , { count : 0 } ) ;
238
+ $ . get ( value ) ;
239
+ } ) ;
240
+
241
+ return ( ) => {
242
+ let errored = false ;
243
+ try {
244
+ $ . flushSync ( ) ;
245
+ } catch ( e : any ) {
246
+ assert . include ( e . message , 'ERR_SVELTE_TOO_MANY_UPDATES' ) ;
247
+ errored = true ;
248
+ }
249
+ assert . equal ( errored , true ) ;
250
+ } ;
251
+ } ) ;
231
252
} ) ;
0 commit comments