Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
Say hello to Angular's future home!Check out Angular.devHome
/

RouterTestingModule

Sets up the router to be used for testing.

See more...

      
      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

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

Optional. Default is undefined.

Returns

ModuleWithProviders<RouterTestingModule>

Providers

Provider
      
      ROUTER_PROVIDERS
    
      
      provideLocationMocks()
    
      
      withPreloading(NoPreloading).ɵproviders
    
      
      { provide: ROUTES, multi: true, useValue: [] }
    

Usage notes

Example

      
      beforeEach(() => {
  TestBed.configureTestingModule({
    imports: [
      RouterModule.forRoot(
        [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
      )
    ]
  });
});