@@ -14,8 +14,9 @@ import {
14
14
EffectSources ,
15
15
Actions ,
16
16
} from '..' ;
17
- import { ofType , createEffect } from '../src' ;
18
- import { mapTo } from 'rxjs/operators' ;
17
+ import { ofType , createEffect , OnRunEffects , EffectNotification } from '../src' ;
18
+ import { mapTo , exhaustMap , tap } from 'rxjs/operators' ;
19
+ import { Observable } from 'rxjs' ;
19
20
20
21
describe ( 'NgRx Effects Integration spec' , ( ) => {
21
22
it ( 'throws if forRoot() is used more than once' , ( done : DoneFn ) => {
@@ -27,8 +28,10 @@ describe('NgRx Effects Integration spec', () => {
27
28
] ,
28
29
} ) ;
29
30
30
- let router : Router = TestBed . get ( Router ) ;
31
- const loader : SpyNgModuleFactoryLoader = TestBed . get ( NgModuleFactoryLoader ) ;
31
+ let router : Router = TestBed . inject ( Router ) ;
32
+ const loader : SpyNgModuleFactoryLoader = TestBed . inject (
33
+ NgModuleFactoryLoader
34
+ ) as SpyNgModuleFactoryLoader ;
32
35
33
36
loader . stubbedModules = { feature : FeatModuleWithForRoot } ;
34
37
router . resetConfig ( [ { path : 'feature-path' , loadChildren : 'feature' } ] ) ;
@@ -61,7 +64,7 @@ describe('NgRx Effects Integration spec', () => {
61
64
EffectsModule . forRoot ( [ EffectWithOnInitAndResponse ] ) ,
62
65
] ,
63
66
} ) ;
64
- TestBed . get ( EffectSources ) ;
67
+ TestBed . inject ( EffectSources ) ;
65
68
66
69
expect ( dispatchedActionsLog ) . toEqual ( [
67
70
INIT ,
@@ -91,7 +94,7 @@ describe('NgRx Effects Integration spec', () => {
91
94
] ) ,
92
95
] ,
93
96
} ) ;
94
- TestBed . get ( EffectSources ) ;
97
+ TestBed . inject ( EffectSources ) ;
95
98
96
99
expect ( dispatchedActionsLog ) . toEqual ( [
97
100
INIT ,
@@ -148,6 +151,7 @@ describe('NgRx Effects Integration spec', () => {
148
151
dispatched : createDispatchedReducer ( dispatchedActionsLog ) ,
149
152
} ) ,
150
153
EffectsModule . forRoot ( [
154
+ EffectLoggerWithOnRunEffects ,
151
155
RootEffectWithInitAction ,
152
156
EffectWithOnInitAndResponse ,
153
157
RootEffectWithoutLifecycle ,
@@ -158,7 +162,9 @@ describe('NgRx Effects Integration spec', () => {
158
162
] ,
159
163
} ) ;
160
164
161
- const effectSources = TestBed . get ( EffectSources ) as EffectSources ;
165
+ const logger = TestBed . inject ( EffectLoggerWithOnRunEffects ) ;
166
+
167
+ const effectSources = TestBed . inject ( EffectSources ) ;
162
168
effectSources . addEffects (
163
169
new FeatEffectWithIdentifierAndInitAction ( 'one' )
164
170
) ;
@@ -169,17 +175,17 @@ describe('NgRx Effects Integration spec', () => {
169
175
new FeatEffectWithIdentifierAndInitAction ( 'one' )
170
176
) ;
171
177
172
- let router : Router = TestBed . get ( Router ) ;
173
- const loader : SpyNgModuleFactoryLoader = TestBed . get (
178
+ let router : Router = TestBed . inject ( Router ) ;
179
+ const loader : SpyNgModuleFactoryLoader = TestBed . inject (
174
180
NgModuleFactoryLoader
175
- ) ;
181
+ ) as SpyNgModuleFactoryLoader ;
176
182
177
183
loader . stubbedModules = { feature : FeatModuleWithForFeature } ;
178
184
router . resetConfig ( [ { path : 'feature-path' , loadChildren : 'feature' } ] ) ;
179
185
180
186
await router . navigateByUrl ( '/feature-path' ) ;
181
187
182
- expect ( dispatchedActionsLog ) . toEqual ( [
188
+ const expectedLog = [
183
189
// first store init
184
190
INIT ,
185
191
@@ -201,10 +207,32 @@ describe('NgRx Effects Integration spec', () => {
201
207
202
208
// from lazy loaded module
203
209
'[FeatEffectFromLazyLoadedModuleWithInitAction]: INIT' ,
204
- ] ) ;
210
+ ] ;
211
+
212
+ // reducers should receive all actions
213
+ expect ( dispatchedActionsLog ) . toEqual ( expectedLog ) ;
214
+
215
+ // ngrxOnRunEffects should receive all actions except STORE_INIT
216
+ expect ( logger . actionsLog ) . toEqual ( expectedLog . slice ( 1 ) ) ;
205
217
} ) ;
206
218
} ) ;
207
219
220
+ @Injectable ( )
221
+ class EffectLoggerWithOnRunEffects implements OnRunEffects {
222
+ actionsLog : string [ ] = [ ] ;
223
+
224
+ constructor ( private actions$ : Actions ) { }
225
+
226
+ ngrxOnRunEffects (
227
+ resolvedEffects$ : Observable < EffectNotification >
228
+ ) : Observable < EffectNotification > {
229
+ return this . actions$ . pipe (
230
+ tap ( action => this . actionsLog . push ( action . type ) ) ,
231
+ exhaustMap ( ( ) => resolvedEffects$ )
232
+ ) ;
233
+ }
234
+ }
235
+
208
236
@Injectable ( )
209
237
class EffectWithOnInitAndResponse implements OnInitEffects {
210
238
ngrxOnInitEffects ( ) : Action {
0 commit comments