|
| 1 | +import { TestBed, fakeAsync, tick } from '@angular/core/testing'; |
| 2 | +import { LazyElementsModule } from './lazy-elements.module'; |
| 3 | +import { NgModule } from '@angular/core'; |
| 4 | +import { RouterTestingModule } from '@angular/router/testing'; |
| 5 | +import { Router } from '@angular/router'; |
| 6 | + |
| 7 | +const config = { |
| 8 | + elementConfigs: [ |
| 9 | + { tag: 'some-element', url: 'http://elements.com/some-url' }, |
| 10 | + { tag: 'some-element', url: 'http://elements.com/some-url' }, |
| 11 | + { |
| 12 | + tag: 'some-other-element', |
| 13 | + url: 'http://elements.com/some-other-url' |
| 14 | + }, |
| 15 | + { |
| 16 | + tag: 'some-module-element', |
| 17 | + url: 'http://elements.com/some-module-url', |
| 18 | + isModule: true |
| 19 | + } |
| 20 | + ] |
| 21 | +}; |
| 22 | + |
| 23 | +@NgModule({ |
| 24 | + imports: [LazyElementsModule.forFeature({})] |
| 25 | +}) |
| 26 | +class ForFeatureModule {} |
| 27 | + |
| 28 | +@NgModule({ |
| 29 | + imports: [LazyElementsModule.forRoot({})] |
| 30 | +}) |
| 31 | +class ForRootModule {} |
| 32 | + |
| 33 | +describe('LazyElementsModule', () => { |
| 34 | + let router: Router; |
| 35 | + |
| 36 | + beforeEach(() => { |
| 37 | + TestBed.configureTestingModule({ |
| 38 | + imports: [ |
| 39 | + LazyElementsModule.forRoot(config), |
| 40 | + RouterTestingModule.withRoutes([ |
| 41 | + { |
| 42 | + path: 'feature', |
| 43 | + loadChildren: () => ForFeatureModule |
| 44 | + }, |
| 45 | + { |
| 46 | + path: 'root', |
| 47 | + loadChildren: () => ForRootModule |
| 48 | + } |
| 49 | + ]) |
| 50 | + ] |
| 51 | + }); |
| 52 | + router = TestBed.get(Router); |
| 53 | + router.initialNavigation(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('For feature can be call twice', fakeAsync(() => { |
| 57 | + let error; |
| 58 | + try { |
| 59 | + router.navigate(['/feature']); |
| 60 | + tick(); |
| 61 | + } catch (err) { |
| 62 | + error = err; |
| 63 | + } |
| 64 | + expect(error).toBeUndefined(); |
| 65 | + })); |
| 66 | + |
| 67 | + it('For root can not be call twice', fakeAsync(() => { |
| 68 | + let error; |
| 69 | + try { |
| 70 | + router.navigate(['/root']); |
| 71 | + tick(); |
| 72 | + } catch (err) { |
| 73 | + error = err; |
| 74 | + } |
| 75 | + expect(error).toBeDefined(); |
| 76 | + })); |
| 77 | +}); |
0 commit comments