diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 3a221459a5..b3bc41553b 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -5647,6 +5647,17 @@ describe('Integration', () => { } } + it('should be injectable', () => { + TestBed.configureTestingModule({ + imports: [RouterTestingModule], + providers: [{provide: RouteReuseStrategy, useClass: AttachDetachReuseStrategy}] + }); + + const router = TestBed.inject(Router); + + expect(router.routeReuseStrategy).toBeInstanceOf(AttachDetachReuseStrategy); + }); + it('should support attaching & detaching fragments', fakeAsync(inject([Router, Location], (router: Router, location: Location) => { const fixture = createRoot(router, RootCmp); diff --git a/packages/router/testing/src/router_testing_module.ts b/packages/router/testing/src/router_testing_module.ts index e7dc95e23a..a1ee2b000d 100644 --- a/packages/router/testing/src/router_testing_module.ts +++ b/packages/router/testing/src/router_testing_module.ts @@ -9,7 +9,7 @@ import {Location, LocationStrategy} from '@angular/common'; import {MockLocationStrategy, SpyLocation} from '@angular/common/testing'; import {Compiler, Injectable, Injector, ModuleWithProviders, NgModule, NgModuleFactory, NgModuleFactoryLoader, Optional} from '@angular/core'; -import {ChildrenOutletContexts, ExtraOptions, NoPreloading, PreloadingStrategy, provideRoutes, Route, Router, ROUTER_CONFIGURATION, RouterModule, ROUTES, Routes, UrlHandlingStrategy, UrlSerializer, ɵassignExtraOptionsToRouter as assignExtraOptionsToRouter, ɵflatten as flatten, ɵROUTER_PROVIDERS as ROUTER_PROVIDERS} from '@angular/router'; +import {ChildrenOutletContexts, ExtraOptions, NoPreloading, PreloadingStrategy, provideRoutes, Route, Router, ROUTER_CONFIGURATION, RouteReuseStrategy, RouterModule, ROUTES, Routes, UrlHandlingStrategy, UrlSerializer, ɵassignExtraOptionsToRouter as assignExtraOptionsToRouter, ɵflatten as flatten, ɵROUTER_PROVIDERS as ROUTER_PROVIDERS} from '@angular/router'; @@ -115,7 +115,8 @@ export function setupTestingRouter( export function setupTestingRouter( urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location, loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][], - opts?: ExtraOptions|UrlHandlingStrategy, urlHandlingStrategy?: UrlHandlingStrategy) { + opts?: ExtraOptions|UrlHandlingStrategy, urlHandlingStrategy?: UrlHandlingStrategy, + routeReuseStrategy?: RouteReuseStrategy) { const router = new Router( null!, urlSerializer, contexts, location, injector, loader, compiler, flatten(routes)); if (opts) { @@ -131,6 +132,11 @@ export function setupTestingRouter( if (urlHandlingStrategy) { router.urlHandlingStrategy = urlHandlingStrategy; } + + if (routeReuseStrategy) { + router.routeReuseStrategy = routeReuseStrategy; + } + return router; } @@ -170,7 +176,8 @@ export function setupTestingRouter( useFactory: setupTestingRouter, deps: [ UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector, - ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()] + ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()], + [RouteReuseStrategy, new Optional()] ] }, {provide: PreloadingStrategy, useExisting: NoPreloading}, provideRoutes([])