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', () => {
|
describe('Integration', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [RouterTestingModule, TestModule],
|
imports: [
|
||||||
providers: [provideRoutes(
|
RouterTestingModule.withRoutes(
|
||||||
[{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])]
|
[{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]),
|
||||||
|
TestModule
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,12 @@
|
||||||
|
|
||||||
import {Location, LocationStrategy} from '@angular/common';
|
import {Location, LocationStrategy} from '@angular/common';
|
||||||
import {MockLocationStrategy, SpyLocation} from '@angular/common/testing';
|
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 {Route, Router, RouterOutletMap, UrlSerializer} from '../index';
|
||||||
|
import {Routes} from '../src/config';
|
||||||
import {ROUTES} from '../src/router_config_loader';
|
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';
|
import {flatten} from '../src/utils/collection';
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,10 +54,12 @@ function setupTestingRouter(
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* beforeEach(() => {
|
* beforeEach(() => {
|
||||||
* configureModule({
|
* TestBed.configureTestModule({
|
||||||
* modules: [RouterTestingModule],
|
* modules: [
|
||||||
* providers: [provideRoutes(
|
* RouterTestingModule.withRoutes(
|
||||||
* [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])]
|
* [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])]
|
||||||
|
* )
|
||||||
|
* ]
|
||||||
* });
|
* });
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
|
@ -74,8 +77,12 @@ function setupTestingRouter(
|
||||||
deps: [
|
deps: [
|
||||||
UrlSerializer, RouterOutletMap, Location, NgModuleFactoryLoader, Compiler, Injector, ROUTES
|
UrlSerializer, RouterOutletMap, Location, NgModuleFactoryLoader, Compiler, Injector, ROUTES
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
provideRoutes([])
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class RouterTestingModule {
|
export class RouterTestingModule {
|
||||||
|
static withRoutes(routes: Routes): ModuleWithProviders {
|
||||||
|
return {ngModule: RouterTestingModule, providers: [provideRoutes(routes)]};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue