77 */
88
99import { CommonModule , HashLocationStrategy , Location , LocationStrategy } from '@angular/common' ;
10- import { SpyLocation } from '@angular/common/testing' ;
10+ import { provideLocationMocks , SpyLocation } from '@angular/common/testing' ;
1111import { ChangeDetectionStrategy , Component , EnvironmentInjector , inject as coreInject , Inject , Injectable , InjectionToken , NgModule , NgModuleRef , NgZone , OnDestroy , QueryList , ViewChild , ViewChildren , ɵConsole as Console , ɵNoopNgZone as NoopNgZone } from '@angular/core' ;
1212import { ComponentFixture , fakeAsync , inject , TestBed , tick } from '@angular/core/testing' ;
1313import { By } from '@angular/platform-browser/src/dom/debug/by' ;
1414import { expect } from '@angular/platform-browser/testing/src/matchers' ;
1515import { ActivatedRoute , ActivatedRouteSnapshot , ActivationEnd , ActivationStart , CanActivate , CanDeactivate , ChildActivationEnd , ChildActivationStart , DefaultUrlSerializer , DetachedRouteHandle , Event , GuardsCheckEnd , GuardsCheckStart , Navigation , NavigationCancel , NavigationCancellationCode , NavigationEnd , NavigationError , NavigationStart , ParamMap , Params , PreloadAllModules , PreloadingStrategy , PRIMARY_OUTLET , Resolve , ResolveEnd , ResolveStart , RouteConfigLoadEnd , RouteConfigLoadStart , Router , RouteReuseStrategy , RouterEvent , RouterLink , RouterLinkActive , RouterModule , RouterOutlet , RouterPreloader , RouterStateSnapshot , RoutesRecognized , RunGuardsAndResolvers , UrlHandlingStrategy , UrlSegmentGroup , UrlSerializer , UrlTree } from '@angular/router' ;
16- import { concat , defer , EMPTY , from , Observable , Observer , of , Subscription } from 'rxjs' ;
16+ import { concat , EMPTY , Observable , Observer , of , Subscription } from 'rxjs' ;
1717import { delay , filter , first , last , map , mapTo , takeWhile , tap } from 'rxjs/operators' ;
1818
1919import { CanActivateChildFn , CanActivateFn , CanMatch , CanMatchFn , ResolveFn } from '../src/models' ;
20- import { withRouterConfig } from '../src/provide_router' ;
20+ import { provideRouter , withRouterConfig } from '../src/provide_router' ;
2121import { forEach , wrapIntoObservable } from '../src/utils/collection' ;
2222import { getLoadedRoutes } from '../src/utils/config' ;
23- import { provideRouterForTesting } from '../testing/src/provide_router_for_testing' ;
2423
2524const ROUTER_DIRECTIVES = [ RouterLink , RouterLinkActive , RouterOutlet ] ;
2625
@@ -32,7 +31,8 @@ describe('Integration', () => {
3231 imports : [ ...ROUTER_DIRECTIVES , TestModule ] ,
3332 providers : [
3433 { provide : Console , useValue : noopConsole } ,
35- provideRouterForTesting ( [ { path : 'simple' , component : SimpleCmp } ] )
34+ provideLocationMocks ( ) ,
35+ provideRouter ( [ { path : 'simple' , component : SimpleCmp } ] ) ,
3636 ]
3737 } ) ;
3838 } ) ;
@@ -5451,7 +5451,8 @@ describe('Integration', () => {
54515451 ...ROUTER_DIRECTIVES ,
54525452 ] ,
54535453 providers : [
5454- provideRouterForTesting ( [ { path : '' , component : SimpleComponent } ] ) ,
5454+ provideLocationMocks ( ) ,
5455+ provideRouter ( [ { path : '' , component : SimpleComponent } ] ) ,
54555456 ] ,
54565457 declarations : [ LinkComponent , SimpleComponent ]
54575458 } ) ;
@@ -6532,7 +6533,8 @@ describe('Integration', () => {
65326533 TestBed . configureTestingModule ( {
65336534 providers : [
65346535 { provide : RouteReuseStrategy , useClass : AttachDetachReuseStrategy } ,
6535- provideRouterForTesting ( )
6536+ provideLocationMocks ( ) ,
6537+ provideRouter ( [ ] ) ,
65366538 ]
65376539 } ) ;
65386540
@@ -6698,10 +6700,13 @@ describe('Integration', () => {
66986700 @NgModule ( {
66996701 declarations : [ RootCmpWithCondOutlet , Tool1Component , Tool2Component ] ,
67006702 imports : [ CommonModule , ...ROUTER_DIRECTIVES ] ,
6701- providers : [ provideRouterForTesting ( [
6702- { path : 'a' , outlet : 'toolpanel' , component : Tool1Component } ,
6703- { path : 'b' , outlet : 'toolpanel' , component : Tool2Component } ,
6704- ] ) ]
6703+ providers : [
6704+ provideLocationMocks ( ) ,
6705+ provideRouter ( [
6706+ { path : 'a' , outlet : 'toolpanel' , component : Tool1Component } ,
6707+ { path : 'b' , outlet : 'toolpanel' , component : Tool2Component } ,
6708+ ] ) ,
6709+ ]
67056710 } )
67066711 class TestModule {
67076712 }
@@ -6756,7 +6761,8 @@ describe('Integration', () => {
67566761 ] ,
67576762 providers : [
67586763 { provide : RouteReuseStrategy , useClass : AttachDetachReuseStrategy } ,
6759- provideRouterForTesting ( [
6764+ provideLocationMocks ( ) ,
6765+ provideRouter ( [
67606766 { path : 'a' , component : SimpleCmp } ,
67616767 { path : 'b' , component : BlankCmp } ,
67626768 ] ) ,
@@ -6825,7 +6831,8 @@ describe('Integration', () => {
68256831 providers : [
68266832 { provide : RouteReuseStrategy , useClass : AttachDetachReuseStrategy } ,
68276833 { provide : CREATED_COMPS , useValue : [ ] } ,
6828- provideRouterForTesting ( [
6834+ provideLocationMocks ( ) ,
6835+ provideRouter ( [
68296836 { path : 'a' , component : Parent , children : [ { path : 'b' , component : Child } ] } ,
68306837 { path : 'c' , component : SimpleCmp }
68316838 ] ) ,
@@ -6882,9 +6889,10 @@ describe('Integration', () => {
68826889 imports : [ ROUTER_DIRECTIVES ] ,
68836890 providers : [
68846891 { provide : RouteReuseStrategy , useClass : AttachDetachReuseStrategy } ,
6885- provideRouterForTesting ( [
6892+ provideLocationMocks ( ) ,
6893+ provideRouter ( [
68866894 { path : 'a' , loadChildren : ( ) => LoadedModule } , { path : 'b' , component : ComponentB }
6887- ] )
6895+ ] ) ,
68886896 ]
68896897 } )
68906898 class TestModule {
@@ -6914,24 +6922,32 @@ describe('Testing router options', () => {
69146922 describe ( 'should configure the router' , ( ) => {
69156923 it ( 'assigns onSameUrlNavigation' , ( ) => {
69166924 TestBed . configureTestingModule ( {
6917- providers : [ provideRouterForTesting ( [ ] , withRouterConfig ( { onSameUrlNavigation : 'reload' } ) ) ]
6925+ providers : [
6926+ provideLocationMocks ( ) ,
6927+ provideRouter ( [ ] , withRouterConfig ( { onSameUrlNavigation : 'reload' } ) ) ,
6928+ ]
69186929 } ) ;
69196930 const router : Router = TestBed . inject ( Router ) ;
69206931 expect ( router . onSameUrlNavigation ) . toBe ( 'reload' ) ;
69216932 } ) ;
69226933
69236934 it ( 'assigns paramsInheritanceStrategy' , ( ) => {
69246935 TestBed . configureTestingModule ( {
6925- providers :
6926- [ provideRouterForTesting ( [ ] , withRouterConfig ( { paramsInheritanceStrategy : 'always' } ) ) ]
6936+ providers : [
6937+ provideLocationMocks ( ) ,
6938+ provideRouter ( [ ] , withRouterConfig ( { paramsInheritanceStrategy : 'always' } ) ) ,
6939+ ]
69276940 } ) ;
69286941 const router : Router = TestBed . inject ( Router ) ;
69296942 expect ( router . paramsInheritanceStrategy ) . toBe ( 'always' ) ;
69306943 } ) ;
69316944
69326945 it ( 'assigns urlUpdateStrategy' , ( ) => {
69336946 TestBed . configureTestingModule ( {
6934- providers : [ provideRouterForTesting ( [ ] , withRouterConfig ( { urlUpdateStrategy : 'eager' } ) ) ]
6947+ providers : [
6948+ provideLocationMocks ( ) ,
6949+ provideRouter ( [ ] , withRouterConfig ( { urlUpdateStrategy : 'eager' } ) ) ,
6950+ ]
69356951 } ) ;
69366952 const router : Router = TestBed . inject ( Router ) ;
69376953 expect ( router . urlUpdateStrategy ) . toBe ( 'eager' ) ;
0 commit comments