@@ -13,14 +13,20 @@ import { provideEffects } from './provide-effects';
13
13
14
14
const spy = jest . fn ( ) ;
15
15
const spy2 = jest . fn ( ) ;
16
+ const spy3 = jest . fn ( ) ;
16
17
const loadTodos = createAction ( '[Todos] Load Todos' ) ;
17
18
const loadTodos2 = createAction ( '[Todos] Load Todos 2' ) ;
19
+ const loadTodos3 = createAction ( '[Todos] Load Todos 3' ) ;
18
20
19
21
@Injectable ( )
20
22
class EffectsOne {
21
23
loadTodos$ = createEffect ( ( actions ) =>
22
24
actions . pipe ( ofType ( loadTodos ) , tap ( spy ) )
23
25
) ;
26
+
27
+ loadTodos3$ = createEffect ( ( actions ) =>
28
+ actions . pipe ( ofType ( loadTodos3 ) , tap ( spy3 ) )
29
+ ) ;
24
30
}
25
31
26
32
@Injectable ( )
@@ -54,6 +60,7 @@ describe('provideDirectiveEffects & EffectsDirective', () => {
54
60
beforeEach ( ( ) => {
55
61
spy . mockClear ( ) ;
56
62
spy2 . mockClear ( ) ;
63
+ spy3 . mockClear ( ) ;
57
64
} ) ;
58
65
59
66
it ( 'should provide effects' , ( ) => {
@@ -95,6 +102,8 @@ describe('provideDirectiveEffects & EffectsDirective', () => {
95
102
TestBed . createComponent ( componentType ) ;
96
103
97
104
expect ( spy ) . toHaveBeenCalled ( ) ;
105
+ expect ( spy2 ) . not . toHaveBeenCalled ( ) ;
106
+ expect ( spy3 ) . not . toHaveBeenCalled ( ) ;
98
107
} ) ;
99
108
100
109
it ( 'should subscribe on the same effects only once' , ( ) => {
@@ -116,6 +125,7 @@ describe('provideDirectiveEffects & EffectsDirective', () => {
116
125
117
126
expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
118
127
expect ( spy2 ) . toHaveBeenCalledTimes ( 1 ) ;
128
+ expect ( spy3 ) . not . toHaveBeenCalled ( ) ;
119
129
} ) ;
120
130
121
131
it ( 'should unsubscribe only from effects that was registered via provideDirectiveEffects when component is destroyed' , ( ) => {
@@ -148,25 +158,28 @@ describe('provideDirectiveEffects & EffectsDirective', () => {
148
158
const fixture3 = TestBed . createComponent ( TestComponent ) ;
149
159
const actions = TestBed . inject ( Actions ) ;
150
160
151
- actions . dispatch ( loadTodos2 ( ) ) ;
161
+ actions . dispatch ( loadTodos2 ( ) , loadTodos3 ( ) ) ;
152
162
153
163
expect ( spy ) . toHaveBeenCalledTimes ( 3 ) ;
154
164
expect ( spy2 ) . toHaveBeenCalledTimes ( 1 ) ;
165
+ expect ( spy2 ) . toHaveBeenCalledTimes ( 1 ) ;
155
166
156
167
fixture . destroy ( ) ;
157
168
fixture2 . destroy ( ) ;
158
169
159
- actions . dispatch ( loadTodos ( ) , loadTodos2 ( ) ) ;
170
+ actions . dispatch ( loadTodos ( ) , loadTodos2 ( ) , loadTodos3 ( ) ) ;
160
171
161
172
expect ( spy ) . toHaveBeenCalledTimes ( 4 ) ;
162
173
expect ( spy2 ) . toHaveBeenCalledTimes ( 2 ) ;
174
+ expect ( spy3 ) . toHaveBeenCalledTimes ( 2 ) ;
163
175
164
176
fixture3 . destroy ( ) ;
165
177
166
- actions . dispatch ( loadTodos ( ) , loadTodos2 ( ) ) ;
178
+ actions . dispatch ( loadTodos ( ) , loadTodos2 ( ) , loadTodos3 ( ) ) ;
167
179
168
180
expect ( spy ) . toHaveBeenCalledTimes ( 4 ) ;
169
181
expect ( spy2 ) . toHaveBeenCalledTimes ( 3 ) ;
182
+ expect ( spy3 ) . toHaveBeenCalledTimes ( 2 ) ;
170
183
} ) ;
171
184
172
185
it ( 'should properly determine source instances and manage their effects' , ( ) => {
0 commit comments