RouterTestingModule

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.

Example

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

静态方法

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

参数

routes

Type: Routes.

config

Type: ExtraOptions.

可选. 默认值是 undefined.

返回值

ModuleWithProviders<RouterTestingModule>

注解

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