1
1
import { Component } from '@angular/core' ;
2
2
import { TestBed } from '@angular/core/testing' ;
3
- import { of , Subject , tap } from 'rxjs' ;
3
+ import { Observable , of , Subject , tap } from 'rxjs' ;
4
4
import { rxEffects , RxEffectsSetupFn } from './rx-effects' ;
5
5
6
6
describe ( rxEffects , ( ) => {
@@ -16,6 +16,20 @@ describe(rxEffects, () => {
16
16
expect ( spy ) . toHaveBeenCalledWith ( 'src' ) ;
17
17
} ) ;
18
18
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
+
19
33
it ( 'should register multiple observables' , ( ) => {
20
34
const spy = jest . fn ( ) ;
21
35
setupComponent ( ( { register } ) => {
@@ -43,6 +57,20 @@ describe(rxEffects, () => {
43
57
expect ( spyError ) . toHaveBeenCalledTimes ( 1 ) ;
44
58
} ) ;
45
59
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
+
46
74
it ( 'should call onDestroy' , ( ) => {
47
75
const spySideEffect = jest . fn ( ) ;
48
76
const spyInternalOnCleanup = jest . fn ( ) ;
0 commit comments