Skip to content

Commit

Permalink
feat(router): add syntax sugar for confuguring RouterTestingModule (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin authored and kara committed Aug 19, 2016
1 parent c56f3f2 commit 53c99cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 5 additions & 3 deletions modules/@angular/router/test/integration.spec.ts
Expand Up @@ -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
]
});
});

Expand Down
19 changes: 13 additions & 6 deletions modules/@angular/router/testing/router_testing_module.ts
Expand Up @@ -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';


Expand Down Expand Up @@ -53,10 +54,12 @@ function setupTestingRouter(
*
* ```
* beforeEach(() => {
* configureModule({
* modules: [RouterTestingModule],
* providers: [provideRoutes(
* TestBed.configureTestModule({
* modules: [
* RouterTestingModule.withRoutes(
* [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])]
* )
* ]
* });
* });
* ```
Expand All @@ -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)]};
}
}

0 comments on commit 53c99cf

Please sign in to comment.