feat(router): add syntax sugar for confuguring RouterTestingModule (#10906)
This commit is contained in:
parent
c56f3f2246
commit
53c99cfc95
|
@ -22,9 +22,11 @@ import {RouterTestingModule, SpyNgModuleFactoryLoader} from '../testing';
|
|||
describe('Integration', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [RouterTestingModule, TestModule],
|
||||
providers: [provideRoutes(
|
||||
[{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])]
|
||||
imports: [
|
||||
RouterTestingModule.withRoutes(
|
||||
[{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]),
|
||||
TestModule
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
|
||||
import {Location, LocationStrategy} from '@angular/common';
|
||||
import {MockLocationStrategy, SpyLocation} from '@angular/common/testing';
|
||||
import {Compiler, Injectable, Injector, NgModule, NgModuleFactory, NgModuleFactoryLoader} from '@angular/core';
|
||||
import {Compiler, Injectable, Injector, ModuleWithProviders, NgModule, NgModuleFactory, NgModuleFactoryLoader} from '@angular/core';
|
||||
|
||||
import {Route, Router, RouterOutletMap, UrlSerializer} from '../index';
|
||||
import {Routes} from '../src/config';
|
||||
import {ROUTES} from '../src/router_config_loader';
|
||||
import {ROUTER_PROVIDERS, RouterModule} from '../src/router_module';
|
||||
import {ROUTER_PROVIDERS, RouterModule, provideRoutes} from '../src/router_module';
|
||||
import {flatten} from '../src/utils/collection';
|
||||
|
||||
|
||||
|
@ -53,10 +54,12 @@ function setupTestingRouter(
|
|||
*
|
||||
* ```
|
||||
* beforeEach(() => {
|
||||
* configureModule({
|
||||
* modules: [RouterTestingModule],
|
||||
* providers: [provideRoutes(
|
||||
* TestBed.configureTestModule({
|
||||
* modules: [
|
||||
* RouterTestingModule.withRoutes(
|
||||
* [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])]
|
||||
* )
|
||||
* ]
|
||||
* });
|
||||
* });
|
||||
* ```
|
||||
|
@ -74,8 +77,12 @@ function setupTestingRouter(
|
|||
deps: [
|
||||
UrlSerializer, RouterOutletMap, Location, NgModuleFactoryLoader, Compiler, Injector, ROUTES
|
||||
]
|
||||
}
|
||||
},
|
||||
provideRoutes([])
|
||||
]
|
||||
})
|
||||
export class RouterTestingModule {
|
||||
static withRoutes(routes: Routes): ModuleWithProviders {
|
||||
return {ngModule: RouterTestingModule, providers: [provideRoutes(routes)]};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue