1
1
import { TestBed } from '@angular/core/testing' ;
2
- import { Router , RouterEvent } from '@angular/router' ;
2
+ import { Router , RouterEvent , NavigationEnd } from '@angular/router' ;
3
3
import {
4
4
routerReducer ,
5
5
RouterReducerState ,
@@ -11,7 +11,7 @@ import {
11
11
DefaultRouterStateSerializer ,
12
12
} from '@ngrx/router-store' ;
13
13
import { select , Store , ActionsSubject } from '@ngrx/store' ;
14
- import { withLatestFrom , filter } from 'rxjs/operators' ;
14
+ import { withLatestFrom , filter , skip } from 'rxjs/operators' ;
15
15
16
16
import { createTestModule } from './utils' ;
17
17
@@ -155,13 +155,12 @@ describe('Router Store Module', () => {
155
155
a . payload && a . payload . event ;
156
156
157
157
describe ( 'Full' , ( ) => {
158
- it ( 'should dispatch the full event' , async ( ) => {
158
+ it ( 'should dispatch the full event' , async ( done ) => {
159
159
const { actions, router } = setup ( RouterState . Full ) ;
160
- actions
161
- . pipe ( filter ( onlyRouterActions ) )
162
- . subscribe ( ( { payload } ) =>
163
- expect ( payload . event instanceof RouterEvent ) . toBe ( true )
164
- ) ;
160
+ actions . pipe ( filter ( onlyRouterActions ) ) . subscribe ( ( { payload } ) => {
161
+ expect ( payload . event instanceof RouterEvent ) . toBe ( true ) ;
162
+ done ( ) ;
163
+ } ) ;
165
164
166
165
await router . navigateByUrl ( '/' ) ;
167
166
} ) ;
@@ -191,18 +190,43 @@ describe('Router Store Module', () => {
191
190
} ) ;
192
191
193
192
describe ( 'Minimal' , ( ) => {
194
- it ( 'should dispatch the navigation id with url' , async ( ) => {
193
+ it ( 'should dispatch the navigation id with url' , async ( done ) => {
195
194
const { actions, router } = setup ( RouterState . Minimal ) ;
196
195
actions
197
196
. pipe ( filter ( onlyRouterActions ) )
198
197
. subscribe ( ( { payload } : any ) => {
199
198
expect ( payload . event instanceof RouterEvent ) . toBe ( false ) ;
200
199
expect ( payload . event ) . toEqual ( { id : 1 , url : '/' } ) ;
200
+ done ( ) ;
201
201
} ) ;
202
202
203
203
await router . navigateByUrl ( '/' ) ;
204
204
} ) ;
205
205
206
+ it ( 'should dispatch the navigation with urlAfterRedirects' , async ( done ) => {
207
+ const { actions, router } = setup ( RouterState . Minimal ) ;
208
+ actions
209
+ . pipe (
210
+ filter ( onlyRouterActions ) ,
211
+ // wait until NavigationEnd router event
212
+ filter (
213
+ ( { payload } ) =>
214
+ ! ! ( payload . event as NavigationEnd ) . urlAfterRedirects
215
+ )
216
+ )
217
+ . subscribe ( ( { payload } : any ) => {
218
+ expect ( payload . event instanceof RouterEvent ) . toBe ( false ) ;
219
+ expect ( payload . event ) . toEqual ( {
220
+ id : 1 ,
221
+ url : '/redirect' ,
222
+ urlAfterRedirects : '/next' ,
223
+ } ) ;
224
+ done ( ) ;
225
+ } ) ;
226
+
227
+ await router . navigateByUrl ( '/redirect' ) ;
228
+ } ) ;
229
+
206
230
it ( 'should use the minimal router serializer' , ( ) => {
207
231
const { serializer } = setup ( RouterState . Minimal ) ;
208
232
expect ( serializer ) . toEqual ( new MinimalRouterStateSerializer ( ) ) ;
0 commit comments