11// #docregion routestuff
2- import { ApplicationRef } from '@angular/core' ;
3- import { LocationStrategy } from '@angular/common' ;
2+ import { Directive } from '@angular/core' ;
43import { HTTP_PROVIDERS } from '@angular/http' ;
54import {
6- ROUTER_PROVIDERS ,
5+ Router ,
6+ RouterLink ,
7+ RootRouter ,
8+ RouteRegistry ,
79 ROUTER_PRIMARY_COMPONENT
810} from '@angular/router-deprecated' ;
911import { Observable } from 'rxjs/Rx' ;
1012import {
1113 describe ,
12- beforeEachProviders ,
14+ addProviders ,
1315 inject ,
1416 it ,
1517 expect ,
16- MockApplicationRef
18+ // MockApplicationRef
1719} from '@angular/core/testing' ;
18- import { MockLocationStrategy } from '@angular/common/testing' ;
20+ import { SpyLocation } from '@angular/common/testing' ;
1921import {
2022 TestComponentBuilder ,
2123 ComponentFixture
22- } from '@angular/compiler /testing' ;
24+ } from '@angular/core /testing' ;
2325
2426import { AppComponent } from '../app.component' ;
2527import { PhoneListComponent } from './phone-list.component' ;
2628import { Phone , PhoneData } from '../core/phone/phone.service' ;
2729
2830// #enddocregion routestuff
2931
32+ @Directive ( {
33+ selector : '[routerLink]' ,
34+ inputs : [ 'routeParams: routerLink' , 'target: target' ]
35+ } )
36+ class RouterLinkMock { }
3037
3138class MockPhone extends Phone {
3239 query ( ) : Observable < PhoneData [ ] > {
@@ -41,19 +48,22 @@ describe('PhoneList', () => {
4148
4249 // #docregion routestuff
4350
44- beforeEachProviders ( ( ) => [
45- { provide : Phone , useClass : MockPhone } ,
46- HTTP_PROVIDERS ,
47- ROUTER_PROVIDERS ,
48- { provide : ApplicationRef , useClass : MockApplicationRef } ,
51+ addProviders ( [
52+ RouteRegistry ,
53+ { provide : Router , useClass : RootRouter } ,
4954 { provide : ROUTER_PRIMARY_COMPONENT , useValue : AppComponent } ,
50- { provide : LocationStrategy , useClass : MockLocationStrategy } ,
55+ { provide : Location , useClass : SpyLocation } ,
56+ { provide : Phone , useClass : MockPhone } ,
57+ HTTP_PROVIDERS
5158 ] ) ;
5259 // #enddocregion routestuff
5360
5461 it ( 'should create "phones" model with 2 phones fetched from xhr' ,
5562 inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
56- return tcb . createAsync ( PhoneListComponent )
63+ return tcb
64+ . overrideDirective ( AppComponent , RouterLink , RouterLinkMock )
65+ . overrideDirective ( PhoneListComponent , RouterLink , RouterLinkMock )
66+ . createAsync ( PhoneListComponent )
5767 . then ( ( fixture : ComponentFixture < PhoneListComponent > ) => {
5868 fixture . detectChanges ( ) ;
5969 let compiled = fixture . debugElement . nativeElement ;
@@ -69,7 +79,10 @@ describe('PhoneList', () => {
6979
7080 it ( 'should set the default value of orderProp model' ,
7181 inject ( [ TestComponentBuilder ] , ( tcb : TestComponentBuilder ) => {
72- return tcb . createAsync ( PhoneListComponent )
82+ return tcb
83+ . overrideDirective ( AppComponent , RouterLink , RouterLinkMock )
84+ . overrideDirective ( PhoneListComponent , RouterLink , RouterLinkMock )
85+ . createAsync ( PhoneListComponent )
7386 . then ( ( fixture : ComponentFixture < PhoneListComponent > ) => {
7487 fixture . detectChanges ( ) ;
7588 let compiled = fixture . debugElement . nativeElement ;
0 commit comments