Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90fdaf3

Browse files
committed
test(state): add more rx effects tests
1 parent d3ea0e3 commit 90fdaf3

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

libs/state/effects/src/lib/rx-effects.spec.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from '@angular/core';
22
import { TestBed } from '@angular/core/testing';
3-
import { of, Subject, tap } from 'rxjs';
3+
import { Observable, of, Subject, tap } from 'rxjs';
44
import { rxEffects, RxEffectsSetupFn } from './rx-effects';
55

66
describe(rxEffects, () => {
@@ -16,6 +16,20 @@ describe(rxEffects, () => {
1616
expect(spy).toHaveBeenCalledWith('src');
1717
});
1818

19+
it('should continuously run sideEffect', () => {
20+
const spyNext = jest.fn();
21+
const trigger = new Subject();
22+
setupComponent(({ register }) => {
23+
register(trigger, spyNext);
24+
});
25+
26+
trigger.next(1);
27+
expect(spyNext).toHaveBeenCalledWith(1);
28+
trigger.next(2);
29+
expect(spyNext).toHaveBeenCalledWith(2);
30+
expect(spyNext).toHaveBeenCalledTimes(2);
31+
});
32+
1933
it('should register multiple observables', () => {
2034
const spy = jest.fn();
2135
setupComponent(({ register }) => {
@@ -43,6 +57,20 @@ describe(rxEffects, () => {
4357
expect(spyError).toHaveBeenCalledTimes(1);
4458
});
4559

60+
it('should unsubscribe onDestroy', () => {
61+
const spyInternalOnCleanup = jest.fn();
62+
63+
const { fixture } = setupComponent(({ register }) => {
64+
register(
65+
new Observable(() => {
66+
return spyInternalOnCleanup;
67+
})
68+
);
69+
});
70+
fixture.destroy();
71+
expect(spyInternalOnCleanup).toHaveBeenCalled();
72+
});
73+
4674
it('should call onDestroy', () => {
4775
const spySideEffect = jest.fn();
4876
const spyInternalOnCleanup = jest.fn();

0 commit comments

Comments
 (0)