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