@@ -7,15 +7,15 @@ import type { ComputationSignal } from '../../src/internal/client/types';
7
7
* @param fn A function that returns a function because we first need to setup all the signals
8
8
* and then execute the test in order to simulate a real component
9
9
*/
10
- function run_test ( runes : boolean , fn : ( ) => ( ) => void ) {
10
+ function run_test ( runes : boolean , fn : ( runes : boolean ) => ( ) => void ) {
11
11
return ( ) => {
12
12
// Create a component context to test runes vs legacy mode
13
13
$ . push ( { } , runes ) ;
14
14
// Create a render context so that effect validations etc don't fail
15
15
let execute : any ;
16
16
const signal = $ . render_effect (
17
17
( ) => {
18
- execute = fn ( ) ;
18
+ execute = fn ( runes ) ;
19
19
} ,
20
20
null ,
21
21
true ,
@@ -27,7 +27,7 @@ function run_test(runes: boolean, fn: () => () => void) {
27
27
} ;
28
28
}
29
29
30
- function test ( text : string , fn : ( ) => any ) {
30
+ function test ( text : string , fn : ( runes : boolean ) => any ) {
31
31
it ( `${ text } (legacy mode)` , run_test ( false , fn ) ) ;
32
32
it ( `${ text } (runes mode)` , run_test ( true , fn ) ) ;
33
33
}
@@ -262,4 +262,25 @@ describe('signals', () => {
262
262
assert . deepEqual ( count . c , null ) ;
263
263
} ;
264
264
} ) ;
265
+
266
+ test ( 'schedules rerun when writing to signal before reading it' , ( runes ) => {
267
+ if ( ! runes ) return ( ) => { } ;
268
+
269
+ const value = $ . source ( { count : 0 } ) ;
270
+ $ . user_effect ( ( ) => {
271
+ $ . set ( value , { count : 0 } ) ;
272
+ $ . get ( value ) ;
273
+ } ) ;
274
+
275
+ return ( ) => {
276
+ let errored = false ;
277
+ try {
278
+ $ . flushSync ( ) ;
279
+ } catch ( e : any ) {
280
+ assert . include ( e . message , 'ERR_SVELTE_TOO_MANY_UPDATES' ) ;
281
+ errored = true ;
282
+ }
283
+ assert . equal ( errored , true ) ;
284
+ } ;
285
+ } ) ;
265
286
} ) ;
0 commit comments