-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move 'Workbench.forRoot guard' spec into spec directory and…
… simplify spec Closes #43
- Loading branch information
1 parent
d5ce02e
commit 68601bf
Showing
3 changed files
with
66 additions
and
111 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
projects/scion/workbench/src/lib/spec/workbench.module.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2018 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import { fakeAsync, inject, TestBed, tick } from '@angular/core/testing'; | ||
import { NgModule, NgModuleFactoryLoader } from '@angular/core'; | ||
import { RouterTestingModule, SpyNgModuleFactoryLoader } from '@angular/router/testing'; | ||
import { Router } from '@angular/router'; | ||
import { WorkbenchModule } from '../workbench.module'; | ||
|
||
fdescribe('WorkbenchModule', () => { | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
WorkbenchModule.forRoot(), | ||
RouterTestingModule.withRoutes([{path: 'lazy-module-forroot', loadChildren: './lazy-forroot.module#LazyForRootModule'}]), | ||
RouterTestingModule.withRoutes([{path: 'lazy-module-forchild', loadChildren: './lazy-forchild.module#LazyForChildModule'}]), | ||
] | ||
}); | ||
}); | ||
|
||
it('throws an error when forRoot() is used in a lazy context', fakeAsync(inject([Router, NgModuleFactoryLoader], async (router: Router, loader: SpyNgModuleFactoryLoader) => { | ||
// Use forRoot() in a lazy context | ||
@NgModule({ | ||
imports: [ | ||
WorkbenchModule.forRoot() | ||
] | ||
}) | ||
class LazyForRootModule { | ||
} | ||
|
||
// Use forChild() in a lazy context | ||
@NgModule({ | ||
imports: [ | ||
WorkbenchModule.forChild() | ||
] | ||
}) | ||
class LazyForChildModule { | ||
} | ||
|
||
loader.stubbedModules = { | ||
'./lazy-forroot.module#LazyForRootModule': LazyForRootModule, | ||
'./lazy-forchild.module#LazyForChildModule': LazyForChildModule, | ||
}; | ||
|
||
// Navigate to LazyForRootModule | ||
expect(() => { | ||
router.navigate(['lazy-module-forroot']).then(); | ||
tick(); | ||
}).toThrowError(/ModuleForRootError/); | ||
|
||
// Navigate to LazyForChildModule | ||
expect(() => { | ||
router.navigate(['lazy-module-forchild']).then(); | ||
tick(); | ||
}).not.toThrowError(/ModuleForRootError/); | ||
}))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.