File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
packages/svelte/tests/signals Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as $ from '../../src/internal/client/runtime';
44import { push , pop } from '../../src/internal/client/context' ;
55import {
66 effect ,
7+ effect_active ,
78 effect_root ,
89 render_effect ,
910 user_effect ,
@@ -1390,4 +1391,41 @@ describe('signals', () => {
13901391 destroy ( ) ;
13911392 } ;
13921393 } ) ;
1394+
1395+ test ( '$effect.active()' , ( ) => {
1396+ const log : Array < string | boolean > = [ ] ;
1397+
1398+ return ( ) => {
1399+ log . push ( 'effect orphan' , effect_active ( ) ) ;
1400+ const destroy = effect_root ( ( ) => {
1401+ log . push ( 'effect root' , effect_active ( ) ) ;
1402+ effect ( ( ) => {
1403+ log . push ( 'effect' , effect_active ( ) ) ;
1404+ } ) ;
1405+ $ . get (
1406+ derived ( ( ) => {
1407+ log . push ( 'derived' , effect_active ( ) ) ;
1408+ return 1 ;
1409+ } )
1410+ ) ;
1411+ return ( ) => {
1412+ log . push ( 'effect teardown' , effect_active ( ) ) ;
1413+ } ;
1414+ } ) ;
1415+ flushSync ( ) ;
1416+ destroy ( ) ;
1417+ assert . deepEqual ( log , [
1418+ 'effect orphan' ,
1419+ false ,
1420+ 'effect root' ,
1421+ true ,
1422+ 'derived' ,
1423+ true ,
1424+ 'effect' ,
1425+ true ,
1426+ 'effect teardown' ,
1427+ false
1428+ ] ) ;
1429+ } ;
1430+ } ) ;
13931431} ) ;
You can’t perform that action at this time.
0 commit comments