RouterTestingModule

class

npm Package @angular/router
Module import { RouterTestingModule } from '@angular/router/testing';
Source router/testing/src/router_testing_module.ts

Sets up the router to be used for testing.

Overview

class RouterTestingModule {
  static withRoutes(routes: Routes): ModuleWithProviders
}

How To Use

beforeEach(() => {
  TestBed.configureTestModule({
    imports: [
      RouterTestingModule.withRoutes(
        [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])]
      )
    ]
  });
});

Description

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

Static Members

static withRoutes(routes: Routes): ModuleWithProviders

Annotations

@NgModule({ exports: [RouterModule], providers: [ 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, [UrlHandlingStrategy, new Optional()] ] }, { provide: PreloadingStrategy, useExisting: NoPreloading }, provideRoutes([]) ] })

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v4.angular.io/api/router/testing/RouterTestingModule