{ "id": "api/router/testing/RouterTestingModule", "title": "RouterTestingModule", "contents": "\n\n
\n
\n
\n \n API > @angular/router > @angular/router/testing\n
\n \n
\n \n
\n

RouterTestingModulelink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

Sets up the router to be used for testing.

\n\n

See more...

\n
\n \n \n \n
\n\nclass RouterTestingModule {\n static withRoutes(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterTestingModule>\n}\n\n\n \n \n\n
\n\n\n \n\n \n \n \n
\n

Descriptionlink

\n

The modules sets up the router to be used for testing.\nIt provides spy implementations of Location, LocationStrategy, and NgModuleFactoryLoader.

\n\n

Further information available in the Usage Notes...

\n
\n\n \n\n \n\n
\n

Static methodslink

\n \n \n\n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n withRoutes()\n \n link

\n \n
\n
\n
\n \n\n static withRoutes(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterTestingModule>\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n routes\n Routes\n \n \n
\n \n config\n ExtraOptions\n

Optional. Default is undefined.

\n \n
\n\n \n
Returns
\n

ModuleWithProviders<RouterTestingModule>

\n\n \n\n\n \n\n \n
\n
\n\n \n
\n\n \n\n \n\n\n \n\n\n \n \n
\n

Providerslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Provider
\n \n ROUTER_PROVIDERS\n \n
\n \n { provide: Location, useClass: SpyLocation }\n \n
\n \n { provide: LocationStrategy, useClass: MockLocationStrategy }\n \n
\n \n { provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }\n \n
\n \n {\n provide: Router,\n useFactory: setupTestingRouter,\n deps: [\n UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector,\n ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()]\n ]\n}\n \n
\n \n { provide: PreloadingStrategy, useExisting: NoPreloading }\n \n
\n \n provideRoutes([])\n \n
\n
\n\n \n\n \n \n\n\n \n
\n

Usage noteslink

\n

Examplelink

\n\nbeforeEach(() => {\n TestBed.configureTestingModule({\n imports: [\n RouterTestingModule.withRoutes(\n [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]\n )\n ]\n });\n});\n\n\n
\n\n\n\n
\n
\n\n\n" }