填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

RouterTestingModule

设置要用于测试的路由器。

Sets up the router to be used for testing.

查看"说明"...

      
      class RouterTestingModule {
  static withRoutes(routes: Route[], config?: ExtraOptions): ModuleWithProviders<RouterTestingModule>
}
    

说明

这些模块会设置用于测试的路由器。它提供 LocationLocationStrategyNgModuleFactoryLoader的间谍实现。

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

Further information available in the Usage Notes...

静态方法

      
      static withRoutes(routes: Route[], config?: ExtraOptions): ModuleWithProviders<RouterTestingModule>
    
参数
routes Route[]
config ExtraOptions
可选. 默认值是 `undefined`.
返回值

ModuleWithProviders<RouterTestingModule>

提供商

提供商
      
      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([])
    

使用说明

例子

Example

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