ngmodule
Sets up the router to be used for testing.
class RouterTestingModule { static withRoutes(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterTestingModule> }
The modules sets up the router to be used for testing. It provides spy implementations of Location
, LocationStrategy
, and NgModuleFactoryLoader
.
withRoutes() | ||||||
---|---|---|---|---|---|---|
|
routes | Routes | |
config | ExtraOptions | Optional. Default is |
Provider |
---|
ROUTER_PROVIDERS |
{ provide: Location, useClass: SpyLocation } |
{ provide: LocationStrategy, useClass: MockLocationStrategy } |
{ provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader } |
{ provide: Router, useFactory: setupTestingRouter, deps: [ UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector, ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()] ] } |
{ provide: PreloadingStrategy, useExisting: NoPreloading } |
provideRoutes([]) |
beforeEach(() => { TestBed.configureTestingModule({ imports: [ RouterTestingModule.withRoutes( [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}] ) ] }); });
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v10.angular.io/api/router/testing/RouterTestingModule