/
router.effect.spec.ts
95 lines (76 loc) · 2.33 KB
/
router.effect.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Injectable } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Actions } from '@ngrx/effects';
import { hot } from 'jasmine-marbles';
import { Observable } from 'rxjs/Observable';
import { empty } from 'rxjs/observable/empty';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import * as fromEffects from './router.effect';
import * as fromActions from '../actions/router.action';
@Injectable()
export class TestActions extends Actions {
constructor() {
super(empty());
}
set stream(source: Observable<any>) {
this.source = source;
}
}
export function getActions() {
return new TestActions();
}
describe('Router Effects', () => {
let actions$: TestActions;
let effects: fromEffects.RouterEffects;
let router: Router;
let location: Location;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
providers: [
fromEffects.RouterEffects,
{ provide: Actions, useFactory: getActions }
]
});
actions$ = TestBed.get(Actions);
effects = TestBed.get(fromEffects.RouterEffects);
router = TestBed.get(Router);
location = TestBed.get(Location);
});
describe('navigate$', () => {
it('should navigate to path', () => {
const action = new fromActions.Go({
path: ['/test']
});
actions$.stream = hot('-a', { a: action });
spyOn(router, 'navigate');
effects.navigate$.subscribe(value => {
expect(router.navigate).toHaveBeenCalledWith(['/test'], {
queryParams: undefined
});
});
});
});
describe('navigateBack$', () => {
it('should navigate back', () => {
const action = new fromActions.Back();
actions$.stream = hot('-a', { a: action });
spyOn(location, 'back');
effects.navigate$.subscribe(value => {
expect(location.back).toHaveBeenCalled();
});
});
});
describe('navigateForward$', () => {
it('should navigate forward', () => {
const action = new fromActions.Back();
actions$.stream = hot('-a', { a: action });
spyOn(location, 'forward');
effects.navigate$.subscribe(value => {
expect(location.forward).toHaveBeenCalled();
});
});
});
});