1
- import { ChangeDetectorRef , Component } from '@angular/core' ;
1
+ import { ChangeDetectorRef , Component , computed , signal } from '@angular/core' ;
2
2
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
3
3
import {
4
4
RX_RENDER_STRATEGIES_CONFIG ,
@@ -29,12 +29,14 @@ let pushPipeTestComponent: {
29
29
} ;
30
30
let componentNativeElement : HTMLElement ;
31
31
let strategyProvider : RxStrategyProvider ;
32
+ let pushPipe : RxPush ;
32
33
33
34
const setupPushPipeComponent = ( ) => {
34
35
TestBed . configureTestingModule ( {
35
36
declarations : [ PushPipeTestComponent ] ,
36
37
imports : [ RxPush ] ,
37
38
providers : [
39
+ RxPush ,
38
40
ChangeDetectorRef ,
39
41
{
40
42
provide : RX_RENDER_STRATEGIES_CONFIG ,
@@ -61,8 +63,43 @@ const setupPushPipeComponent = () => {
61
63
pushPipeTestComponent = fixturePushPipeTestComponent . componentInstance ;
62
64
componentNativeElement = fixturePushPipeTestComponent . nativeElement ;
63
65
strategyProvider = TestBed . inject ( RxStrategyProvider ) ;
66
+ pushPipe = TestBed . inject ( RxPush ) ;
64
67
} ;
65
68
69
+ describe ( 'RxPush' , ( ) => {
70
+ beforeAll ( ( ) => mockConsole ( ) ) ;
71
+ beforeEach ( setupPushPipeComponent ) ;
72
+
73
+ it ( 'should be instantiable' , ( ) => {
74
+ expect ( pushPipe ) . toBeDefined ( ) ;
75
+ } ) ;
76
+
77
+ describe ( 'transform function' , ( ) => {
78
+ it ( 'should not track signal reads in subscriptions' , ( ) => {
79
+ const trigger = signal ( false ) ;
80
+
81
+ const obs = new Observable ( ( ) => {
82
+ // Whenever `obs` is subscribed, synchronously read `trigger`.
83
+ trigger ( ) ;
84
+ } ) ;
85
+
86
+ let trackCount = 0 ;
87
+ const tracker = computed ( ( ) => {
88
+ // Subscribe to `obs` within this `computed`. If the subscription side effect runs
89
+ // within the computed, then changes to `trigger` will invalidate this computed.
90
+ pushPipe . transform ( obs ) ;
91
+
92
+ // The computed returns how many times it's run.
93
+ return ++ trackCount ;
94
+ } ) ;
95
+
96
+ expect ( tracker ( ) ) . toBe ( 1 ) ;
97
+ trigger . set ( true ) ;
98
+ expect ( tracker ( ) ) . toBe ( 1 ) ;
99
+ } ) ;
100
+ } ) ;
101
+ } ) ;
102
+
66
103
describe ( 'RxPush used as pipe in the template' , ( ) => {
67
104
beforeAll ( ( ) => mockConsole ( ) ) ;
68
105
0 commit comments