diff --git a/goldens/public-api/common/testing/index.md b/goldens/public-api/common/testing/index.md index d28b832f9b00c..60d95818039df 100644 --- a/goldens/public-api/common/testing/index.md +++ b/goldens/public-api/common/testing/index.md @@ -10,6 +10,7 @@ import { Location as Location_2 } from '@angular/common'; import { LocationChangeListener } from '@angular/common'; import { LocationStrategy } from '@angular/common'; import { PlatformLocation } from '@angular/common'; +import { Provider } from '@angular/core'; import { SubscriptionLike } from 'rxjs'; // @public @@ -105,6 +106,9 @@ export interface MockPlatformLocationConfig { startUrl?: string; } +// @public +export function provideLocationMocks(): Provider[]; + // @public export class SpyLocation implements Location_2 { // (undocumented) diff --git a/packages/common/test/location/provide_location_mocks_spec.ts b/packages/common/test/location/provide_location_mocks_spec.ts new file mode 100644 index 0000000000000..e275e5fc10573 --- /dev/null +++ b/packages/common/test/location/provide_location_mocks_spec.ts @@ -0,0 +1,23 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {Location, LocationStrategy} from '@angular/common'; +import {MockLocationStrategy, provideLocationMocks, SpyLocation} from '@angular/common/testing'; +import {TestBed} from '@angular/core/testing'; + + +describe('provideLocationMocks() function', () => { + it('should mock Location and LocationStrategy classes', () => { + TestBed.configureTestingModule({providers: [provideLocationMocks()]}); + const location = TestBed.inject(Location); + const locationStrategy = TestBed.inject(LocationStrategy); + + expect(location).toBeInstanceOf(SpyLocation); + expect(locationStrategy).toBeInstanceOf(MockLocationStrategy); + }); +}); diff --git a/packages/common/testing/src/provide_location_mocks.ts b/packages/common/testing/src/provide_location_mocks.ts new file mode 100644 index 0000000000000..9c6f4c63f1f01 --- /dev/null +++ b/packages/common/testing/src/provide_location_mocks.ts @@ -0,0 +1,27 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {Location, LocationStrategy} from '@angular/common'; +import {Provider} from '@angular/core'; + +import {SpyLocation} from './location_mock'; +import {MockLocationStrategy} from './mock_location_strategy'; + +/** + * Returns mock providers for the `Location` and `LocationStrategy` classes. + * The mocks are helpful in tests to fire simulated location events. + * + * @developerPreview + * @publicApi + */ +export function provideLocationMocks(): Provider[] { + return [ + {provide: Location, useClass: SpyLocation}, + {provide: LocationStrategy, useClass: MockLocationStrategy}, + ]; +} diff --git a/packages/common/testing/src/testing.ts b/packages/common/testing/src/testing.ts index a8a1ec38fc08d..7eb5601515ded 100644 --- a/packages/common/testing/src/testing.ts +++ b/packages/common/testing/src/testing.ts @@ -14,3 +14,4 @@ export {SpyLocation} from './location_mock'; export {MockLocationStrategy} from './mock_location_strategy'; export {MOCK_PLATFORM_LOCATION_CONFIG, MockPlatformLocation, MockPlatformLocationConfig} from './mock_platform_location'; +export {provideLocationMocks} from './provide_location_mocks'; diff --git a/packages/router/test/computed_state_restoration.spec.ts b/packages/router/test/computed_state_restoration.spec.ts index ce55e705c9587..e25d37ab29b28 100644 --- a/packages/router/test/computed_state_restoration.spec.ts +++ b/packages/router/test/computed_state_restoration.spec.ts @@ -7,15 +7,15 @@ */ import {CommonModule, Location} from '@angular/common'; -import {SpyLocation} from '@angular/common/testing'; +import {provideLocationMocks, SpyLocation} from '@angular/common/testing'; import {Component, Injectable, NgModule} from '@angular/core'; import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {CanActivate, CanDeactivate, Resolve, Router, RouterModule, RouterOutlet, UrlTree, withRouterConfig} from '@angular/router'; import {EMPTY, Observable, of} from 'rxjs'; +import {provideRouter} from '../src/provide_router'; import {isUrlTree} from '../src/url_tree'; -import {provideRouterForTesting} from '../testing/src/provide_router_for_testing'; describe('`restoredState#ɵrouterPageId`', () => { @Injectable({providedIn: 'root'}) @@ -490,7 +490,8 @@ function advance(fixture: ComponentFixture, millis?: number): void { CommonModule, ], providers: [ - provideRouterForTesting([], withRouterConfig({canceledNavigationResolution: 'computed'})), + provideLocationMocks(), + provideRouter([], withRouterConfig({canceledNavigationResolution: 'computed'})), ], exports: [SimpleCmp, RootCmp, ThrowingCmp], declarations: [SimpleCmp, RootCmp, ThrowingCmp] diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 2f5f582097ef1..16823d17dc134 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -7,20 +7,19 @@ */ import {CommonModule, HashLocationStrategy, Location, LocationStrategy} from '@angular/common'; -import {SpyLocation} from '@angular/common/testing'; +import {provideLocationMocks, SpyLocation} from '@angular/common/testing'; import {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'; import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing'; import {By} from '@angular/platform-browser/src/dom/debug/by'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {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'; -import {concat, defer, EMPTY, from, Observable, Observer, of, Subscription} from 'rxjs'; +import {concat, EMPTY, Observable, Observer, of, Subscription} from 'rxjs'; import {delay, filter, first, last, map, mapTo, takeWhile, tap} from 'rxjs/operators'; import {CanActivateChildFn, CanActivateFn, CanMatch, CanMatchFn, ResolveFn} from '../src/models'; -import {withRouterConfig} from '../src/provide_router'; +import {provideRouter, withRouterConfig} from '../src/provide_router'; import {forEach, wrapIntoObservable} from '../src/utils/collection'; import {getLoadedRoutes} from '../src/utils/config'; -import {provideRouterForTesting} from '../testing/src/provide_router_for_testing'; const ROUTER_DIRECTIVES = [RouterLink, RouterLinkActive, RouterOutlet]; @@ -32,7 +31,8 @@ describe('Integration', () => { imports: [...ROUTER_DIRECTIVES, TestModule], providers: [ {provide: Console, useValue: noopConsole}, - provideRouterForTesting([{path: 'simple', component: SimpleCmp}]) + provideLocationMocks(), + provideRouter([{path: 'simple', component: SimpleCmp}]), ] }); }); @@ -5451,7 +5451,8 @@ describe('Integration', () => { ...ROUTER_DIRECTIVES, ], providers: [ - provideRouterForTesting([{path: '', component: SimpleComponent}]), + provideLocationMocks(), + provideRouter([{path: '', component: SimpleComponent}]), ], declarations: [LinkComponent, SimpleComponent] }); @@ -6532,7 +6533,8 @@ describe('Integration', () => { TestBed.configureTestingModule({ providers: [ {provide: RouteReuseStrategy, useClass: AttachDetachReuseStrategy}, - provideRouterForTesting() + provideLocationMocks(), + provideRouter([]), ] }); @@ -6698,10 +6700,13 @@ describe('Integration', () => { @NgModule({ declarations: [RootCmpWithCondOutlet, Tool1Component, Tool2Component], imports: [CommonModule, ...ROUTER_DIRECTIVES], - providers: [provideRouterForTesting([ - {path: 'a', outlet: 'toolpanel', component: Tool1Component}, - {path: 'b', outlet: 'toolpanel', component: Tool2Component}, - ])] + providers: [ + provideLocationMocks(), + provideRouter([ + {path: 'a', outlet: 'toolpanel', component: Tool1Component}, + {path: 'b', outlet: 'toolpanel', component: Tool2Component}, + ]), + ] }) class TestModule { } @@ -6756,7 +6761,8 @@ describe('Integration', () => { ], providers: [ {provide: RouteReuseStrategy, useClass: AttachDetachReuseStrategy}, - provideRouterForTesting([ + provideLocationMocks(), + provideRouter([ {path: 'a', component: SimpleCmp}, {path: 'b', component: BlankCmp}, ]), @@ -6825,7 +6831,8 @@ describe('Integration', () => { providers: [ {provide: RouteReuseStrategy, useClass: AttachDetachReuseStrategy}, {provide: CREATED_COMPS, useValue: []}, - provideRouterForTesting([ + provideLocationMocks(), + provideRouter([ {path: 'a', component: Parent, children: [{path: 'b', component: Child}]}, {path: 'c', component: SimpleCmp} ]), @@ -6882,9 +6889,10 @@ describe('Integration', () => { imports: [ROUTER_DIRECTIVES], providers: [ {provide: RouteReuseStrategy, useClass: AttachDetachReuseStrategy}, - provideRouterForTesting([ + provideLocationMocks(), + provideRouter([ {path: 'a', loadChildren: () => LoadedModule}, {path: 'b', component: ComponentB} - ]) + ]), ] }) class TestModule { @@ -6914,7 +6922,10 @@ describe('Testing router options', () => { describe('should configure the router', () => { it('assigns onSameUrlNavigation', () => { TestBed.configureTestingModule({ - providers: [provideRouterForTesting([], withRouterConfig({onSameUrlNavigation: 'reload'}))] + providers: [ + provideLocationMocks(), + provideRouter([], withRouterConfig({onSameUrlNavigation: 'reload'})), + ] }); const router: Router = TestBed.inject(Router); expect(router.onSameUrlNavigation).toBe('reload'); @@ -6922,8 +6933,10 @@ describe('Testing router options', () => { it('assigns paramsInheritanceStrategy', () => { TestBed.configureTestingModule({ - providers: - [provideRouterForTesting([], withRouterConfig({paramsInheritanceStrategy: 'always'}))] + providers: [ + provideLocationMocks(), + provideRouter([], withRouterConfig({paramsInheritanceStrategy: 'always'})), + ] }); const router: Router = TestBed.inject(Router); expect(router.paramsInheritanceStrategy).toBe('always'); @@ -6931,7 +6944,10 @@ describe('Testing router options', () => { it('assigns urlUpdateStrategy', () => { TestBed.configureTestingModule({ - providers: [provideRouterForTesting([], withRouterConfig({urlUpdateStrategy: 'eager'}))] + providers: [ + provideLocationMocks(), + provideRouter([], withRouterConfig({urlUpdateStrategy: 'eager'})), + ] }); const router: Router = TestBed.inject(Router); expect(router.urlUpdateStrategy).toBe('eager'); diff --git a/packages/router/test/page_title_strategy_spec.ts b/packages/router/test/page_title_strategy_spec.ts index b0e4e086caeb6..6ed02131d3bac 100644 --- a/packages/router/test/page_title_strategy_spec.ts +++ b/packages/router/test/page_title_strategy_spec.ts @@ -7,11 +7,12 @@ */ import {DOCUMENT} from '@angular/common'; +import {provideLocationMocks} from '@angular/common/testing'; import {Component, Inject, Injectable, NgModule} from '@angular/core'; import {fakeAsync, TestBed, tick} from '@angular/core/testing'; -import {NavigationEnd, Router, RouterModule, RouterStateSnapshot, TitleStrategy} from '@angular/router'; +import {Router, RouterModule, RouterStateSnapshot, TitleStrategy} from '@angular/router'; -import {provideRouterForTesting} from '../testing/src/provide_router_for_testing'; +import {provideRouter} from '../src/provide_router'; describe('title strategy', () => { describe('DefaultTitleStrategy', () => { @@ -23,7 +24,10 @@ describe('title strategy', () => { imports: [ TestModule, ], - providers: [provideRouterForTesting()] + providers: [ + provideLocationMocks(), + provideRouter([]), + ] }); router = TestBed.inject(Router); document = TestBed.inject(DOCUMENT); @@ -133,8 +137,9 @@ describe('title strategy', () => { TestModule, ], providers: [ - provideRouterForTesting(), - {provide: TitleStrategy, useClass: TemplatePageTitleStrategy} + provideLocationMocks(), + provideRouter([]), + {provide: TitleStrategy, useClass: TemplatePageTitleStrategy}, ] }); const router = TestBed.inject(Router); diff --git a/packages/router/test/regression_integration.spec.ts b/packages/router/test/regression_integration.spec.ts index c2014f918840d..3d70bb7d24820 100644 --- a/packages/router/test/regression_integration.spec.ts +++ b/packages/router/test/regression_integration.spec.ts @@ -7,7 +7,7 @@ */ import {CommonModule, HashLocationStrategy, Location, LocationStrategy} from '@angular/common'; -import {SpyLocation} from '@angular/common/testing'; +import {provideLocationMocks, SpyLocation} from '@angular/common/testing'; import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Injectable, NgModule, TemplateRef, Type, ViewChild, ViewContainerRef} from '@angular/core'; import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; import {ChildrenOutletContexts, Resolve, Router, RouterOutlet} from '@angular/router'; @@ -15,7 +15,7 @@ import {RouterTestingModule} from '@angular/router/testing'; import {of} from 'rxjs'; import {delay, mapTo} from 'rxjs/operators'; -import {provideRouterForTesting} from '../testing/src/provide_router_for_testing'; +import {provideRouter} from '../src/provide_router'; describe('Integration', () => { describe('routerLinkActive', () => { @@ -304,7 +304,8 @@ describe('Integration', () => { imports: [RouterOutlet], providers: [ DelayedResolve, - provideRouterForTesting( + provideLocationMocks(), + provideRouter( [ {path: '', component: SimpleCmp}, {path: 'one', component: OneCmp, resolve: {x: DelayedResolve}} diff --git a/packages/router/test/router_preloader.spec.ts b/packages/router/test/router_preloader.spec.ts index fb5d102a8ae0a..fc4d299b26602 100644 --- a/packages/router/test/router_preloader.spec.ts +++ b/packages/router/test/router_preloader.spec.ts @@ -6,15 +6,16 @@ * found in the LICENSE file at https://angular.io/license */ -import {Compiler, Component, Inject, Injectable, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, Optional, Type} from '@angular/core'; +import {provideLocationMocks} from '@angular/common/testing'; +import {Compiler, Component, Injectable, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, Type} from '@angular/core'; import {fakeAsync, inject, TestBed, tick} from '@angular/core/testing'; import {PreloadAllModules, PreloadingStrategy, provideRoutes, RouterPreloader, withPreloading} from '@angular/router'; import {BehaviorSubject, Observable, of, throwError} from 'rxjs'; import {catchError, delay, filter, switchMap, take} from 'rxjs/operators'; import {Route, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouterModule} from '../index'; +import {provideRouter} from '../src/provide_router'; import {getLoadedComponent, getLoadedInjector, getLoadedRoutes, getProvidersInjector} from '../src/utils/config'; -import {provideRouterForTesting} from '../testing/src/provide_router_for_testing'; describe('RouterPreloader', () => { @@ -26,7 +27,8 @@ describe('RouterPreloader', () => { beforeEach(() => { TestBed.configureTestingModule({ providers: [ - provideRouterForTesting( + provideLocationMocks(), + provideRouter( [{path: 'lazy', loadChildren: jasmine.createSpy('expected'), canLoad: ['someGuard']}], withPreloading(PreloadAllModules)), ] @@ -51,9 +53,12 @@ describe('RouterPreloader', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [provideRouterForTesting( - [{path: 'lazy', loadChildren: () => LoadedModule, canLoad: ['someGuard']}], - withPreloading(PreloadAllModules))], + providers: [ + provideLocationMocks(), + provideRouter( + [{path: 'lazy', loadChildren: () => LoadedModule, canLoad: ['someGuard']}], + withPreloading(PreloadAllModules)), + ], }); }); @@ -85,8 +90,10 @@ describe('RouterPreloader', () => { beforeEach(() => { lazySpy = jasmine.createSpy('expected'); TestBed.configureTestingModule({ - providers: [provideRouterForTesting( - [{path: 'lazy', loadChildren: lazySpy}], withPreloading(PreloadAllModules))], + providers: [ + provideLocationMocks(), + provideRouter([{path: 'lazy', loadChildren: lazySpy}], withPreloading(PreloadAllModules)), + ], }); }); @@ -152,13 +159,16 @@ describe('RouterPreloader', () => { } TestBed.configureTestingModule({ - providers: [provideRouterForTesting( - [{ - path: 'parent', - providers: [{provide: TOKEN, useValue: 'parent'}], - loadChildren: () => Child, - }], - withPreloading(PreloadAllModules))], + providers: [ + provideLocationMocks(), + provideRouter( + [{ + path: 'parent', + providers: [{provide: TOKEN, useValue: 'parent'}], + loadChildren: () => Child, + }], + withPreloading(PreloadAllModules)), + ], }); TestBed.inject(RouterPreloader).preload().subscribe(() => {}); @@ -184,8 +194,8 @@ describe('RouterPreloader', () => { lazySpy = jasmine.createSpy('expected'); TestBed.configureTestingModule({ providers: [ - provideRouterForTesting( - [{path: 'lazy', loadChildren: lazySpy}], withPreloading(PreloadAllModules)), + provideLocationMocks(), + provideRouter([{path: 'lazy', loadChildren: lazySpy}], withPreloading(PreloadAllModules)), ], }); }); @@ -291,8 +301,9 @@ describe('RouterPreloader', () => { lazyLoadChildrenSpy.calls.reset(); TestBed.configureTestingModule({ providers: [ - provideRouterForTesting([{path: 'lazy', loadChildren: lazyLoadChildrenSpy}]), - {provide: PreloadingStrategy, useFactory: mockPreloaderFactory} + provideLocationMocks(), + provideRouter([{path: 'lazy', loadChildren: lazyLoadChildrenSpy}]), + {provide: PreloadingStrategy, useFactory: mockPreloaderFactory}, ] }); events = []; @@ -582,10 +593,12 @@ describe('RouterPreloader', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [provideRouterForTesting( - [{path: 'lazy1', loadChildren: () => LoadedModule}], - withPreloading(PreloadAllModules), - )], + providers: [ + provideLocationMocks(), + provideRouter( + [{path: 'lazy1', loadChildren: () => LoadedModule}], + withPreloading(PreloadAllModules)), + ], }); }); @@ -620,10 +633,10 @@ describe('RouterPreloader', () => { beforeEach(() => { TestBed.configureTestingModule({ providers: [ - provideRouterForTesting( + provideLocationMocks(), + provideRouter( [{path: 'lazyEmptyModule', loadChildren: () => EmptyModule}], - withPreloading(PreloadAllModules), - ), + withPreloading(PreloadAllModules)), ] }); }); @@ -639,10 +652,9 @@ describe('RouterPreloader', () => { lazyComponentSpy = jasmine.createSpy('expected'); TestBed.configureTestingModule({ providers: [ - provideRouterForTesting( - [{path: 'lazy', loadComponent: lazyComponentSpy}], - withPreloading(PreloadAllModules), - ), + provideLocationMocks(), + provideRouter( + [{path: 'lazy', loadComponent: lazyComponentSpy}], withPreloading(PreloadAllModules)), ] }); }); @@ -717,7 +729,10 @@ describe('RouterPreloader', () => { } @NgModule({ - providers: [provideRouterForTesting([{path: 'child', component: LoadedComponent}])], + providers: [ + provideLocationMocks(), + provideRouter([{path: 'child', component: LoadedComponent}]), + ], }) class LoadedModule { } @@ -747,12 +762,15 @@ describe('RouterPreloader', () => { lazyComponentSpy.and.returnValue(of(LoadedComponent).pipe(delay(5))); @NgModule({ - providers: [provideRouterForTesting([{ - path: 'child', - loadChildren: () => of([ - {path: 'grandchild', children: []}, - ]).pipe(delay(1)), - }])] + providers: [ + provideLocationMocks(), + provideRouter([{ + path: 'child', + loadChildren: () => of([ + {path: 'grandchild', children: []}, + ]).pipe(delay(1)), + }]), + ] }) class LoadedModule { } diff --git a/packages/router/testing/src/provide_router_for_testing.ts b/packages/router/testing/src/provide_router_for_testing.ts deleted file mode 100644 index 5f9bf67f972e9..0000000000000 --- a/packages/router/testing/src/provide_router_for_testing.ts +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {Location, LocationStrategy} from '@angular/common'; -import {MockLocationStrategy, SpyLocation} from '@angular/common/testing'; -import {EnvironmentProviders, Provider} from '@angular/core'; -import {provideRouter, RouterFeatures, Routes} from '@angular/router'; - - -/** - * Sets up providers necessary to enable `Router` functionality for tests. - * - * Allows to configure a set of routes as well as extra features that should be enabled. - * Provides spy implementations of `Location` and `LocationStrategy` interfaces. - * - * @usageNotes - * ### Example - * - * ``` - * const testRoutes: Routes = [ - * {path: '', component: BlankCmp}, - * {path: 'simple', component: SimpleCmp} - * ]; - * - * beforeEach(() => { - * TestBed.configureTestingModule({ - * providers: [ - * provideRouterForTesting(testRoutes, - * withDebugTracing(), - * withRouterConfig({paramsInheritanceStrategy: 'always'}), - * ) - * ] - * }); - * }); - * ``` - * - * @see `provideRouter` - * - * @param routes A set of `Route`s to use during the test. - * @param features Optional features to configure additional router behaviors. - * @returns A set of providers to setup Router for testing. - */ -export function provideRouterForTesting( - routes: Routes = [], ...features: RouterFeatures[]): (Provider|EnvironmentProviders)[] { - return [ - provideRouter(routes, ...features), - {provide: Location, useClass: SpyLocation}, - {provide: LocationStrategy, useClass: MockLocationStrategy}, - ]; -} diff --git a/packages/router/testing/src/router_testing_module.ts b/packages/router/testing/src/router_testing_module.ts index 995f21c87f479..69b51218be0fb 100644 --- a/packages/router/testing/src/router_testing_module.ts +++ b/packages/router/testing/src/router_testing_module.ts @@ -6,8 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {Location, LocationStrategy} from '@angular/common'; -import {MockLocationStrategy, SpyLocation} from '@angular/common/testing'; +import {Location} from '@angular/common'; +import {provideLocationMocks} from '@angular/common/testing'; import {Compiler, Injector, ModuleWithProviders, NgModule, Optional} from '@angular/core'; import {ChildrenOutletContexts, ExtraOptions, NoPreloading, provideRoutes, Route, Router, ROUTER_CONFIGURATION, RouteReuseStrategy, RouterModule, ROUTES, Routes, TitleStrategy, UrlHandlingStrategy, UrlSerializer, ɵassignExtraOptionsToRouter as assignExtraOptionsToRouter, ɵflatten as flatten, ɵROUTER_PROVIDERS as ROUTER_PROVIDERS, ɵwithPreloading as withPreloading} from '@angular/router'; @@ -106,8 +106,7 @@ export function setupTestingRouter( providers: [ ROUTER_PROVIDERS, EXTRA_ROUTER_TESTING_PROVIDERS, - {provide: Location, useClass: SpyLocation}, - {provide: LocationStrategy, useClass: MockLocationStrategy}, + provideLocationMocks(), { provide: Router, useFactory: setupTestingRouterInternal,