Created
March 5, 2019 10:08
-
-
Save wiemKh/e72e3d17bf8d1c6afc81516fff8416d9 to your computer and use it in GitHub Desktop.
Lazy loading testing
This file contains hidden or 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
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; | |
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | |
import { Router, RouterModule } from '@angular/router'; | |
import { NgModuleFactoryLoader, Component, NgModule } from '@angular/core'; | |
import { RouterTestingModule } from '@angular/router/testing'; | |
import { routes } from './app-routing.module' | |
import { Location } from '@angular/common'; | |
describe('PageNotfoundComponent', () => { | |
let component: AppComponent; | |
let fixture: ComponentFixture<AppComponent>; | |
let router: Router; | |
let location: Location; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [AppComponent], | |
imports: [RouterTestingModule.withRoutes(routes), BrowserAnimationsModule, PageNotfoundModule, LoginModule] | |
}).compileComponents(); | |
})); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(AppComponent); | |
component = fixture.componentInstance; | |
fixture.detectChanges(); | |
let router = TestBed.get(Router); | |
}); | |
@Component({ template: '' }) | |
class LazyLoadedComponent { } | |
@NgModule({ declarations: [LazyLoadedComponent] }) | |
class LazyModule { } | |
it('should navigate to 404 child path', fakeAsync(() => { | |
let router = TestBed.get(Router); | |
router.initialNavigation(); | |
//Used to load ng module factories. | |
let loader = TestBed.get(NgModuleFactoryLoader); | |
let location = TestBed.get(Location); | |
// sets up stubbedModules | |
loader.stubbedModules = { | |
'./page-notfound/page-notfound.module#PageNotfoundModule': LazyModule, | |
}; | |
router.resetConfig([ | |
{ path: '404', loadChildren: './page-notfound/page-notfound.module#PageNotfoundModule' }, | |
]); | |
router.navigateByUrl('/404'); | |
tick(); | |
fixture.detectChanges(); | |
expect(location.path()).toBe('/404'); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment