8000 fix(template): added tests for untracked push pipe · rx-angular/rx-angular@5978a15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5978a15

Browse files
committed
fix(template): added tests for untracked push pipe
1 parent fbdbf5b commit 5978a15

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

libs/template/push/src/lib/tests/push.pipe.spec.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Component } from '@angular/core';
1+
import { ChangeDetectorRef, Component, computed, signal } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import {
44
RX_RENDER_STRATEGIES_CONFIG,
@@ -29,12 +29,14 @@ let pushPipeTestComponent: {
2929
};
3030
let componentNativeElement: HTMLElement;
3131
let strategyProvider: RxStrategyProvider;
32+
let pushPipe: RxPush;
3233

3334
const setupPushPipeComponent = () => {
3435
TestBed.configureTestingModule({
3536
declarations: [PushPipeTestComponent],
3637
imports: [RxPush],
3738
providers: [
39+
RxPush,
3840
ChangeDetectorRef,
3941
{
4042
provide: RX_RENDER_STRATEGIES_CONFIG,
@@ -61,8 +63,43 @@ const setupPushPipeComponent = () => {
6163
pushPipeTestComponent = fixturePushPipeTestComponent.componentInstance;
6264
componentNativeElement = fixturePushPipeTestComponent.nativeElement;
6365
strategyProvider = TestBed.inject(RxStrategyProvider);
66+
pushPipe = TestBed.inject(RxPush);
6467
};
6568

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+
66103
describe('RxPush used as pipe in the template', () => {
67104
beforeAll(() => mockConsole());
68105

0 commit comments

Comments
 (0)
0