Getting NgModuleFactoryLoader is deprecated: the string form of loadChildren is deprecated, and NgModuleFactoryLoader is
part of its implementation. See LoadChildren for more details. warning and not able to stub the module for testing the lazy loaded module
Below is the code
import { Location } from '@angular/common';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
import { AppComponent } from './app.component';
import { AppConfigService } from './services/appConfig.service';
import { TranslateModule } from '@ngx-translate/core';
import { NgModuleFactoryLoader } from '@angular/core';
import { VehicleModule} from './views/vehicle/vehicle.module';
import { DriverModule} from './views/driver/driver.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
const routes: Routes = [{
path: 'admin',
data: { preload: false },
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)
},
{ path: '', component: FrontpageComponent }];
describe('Router: App', () => {
let location: Location;
let router: Router;
let fixture: ComponentFixture<AppComponent>;
let loader: any;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
TranslateModule.forRoot(),
RouterTestingModule.withRoutes(routes),
],
declarations: [AppComponent],
providers: [AppConfigService]
});
router = TestBed.get(Router);
location = TestBed.get(Location);
loader = TestBed.get(NgModuleFactoryLoader);
loader.stubbedModules = {
'VehicleModule': VehicleModule,
'DriverModule': DriverModule
};
fixture = TestBed.createComponent(AppComponent);
router.resetConfig([
{
path: 'vehicle',
loadChildren: 'VehicleModule'
},
{
path: 'driver',
loadChildren: 'DriverModule'
},
{
path: '',
loadChildren: 'VehicleModule'
}
]);
fixture = TestBed.createComponent(AppComponent);
router.initialNavigation();
});
it('should create APP', () => {
expect(fixture.componentInstance).toBeDefined();
});
it('should navigate to /student lazy loaded ,pdule', fakeAsync(() => {
const loader = TestBed.get(NgModuleFactoryLoader);
loader.stubbedModules = {lazyModule: StudentModule};
router.resetConfig([
{path: 'student', loadChildren: 'lazyModule'},
]);
router.navigate(['student'])
tick();
expect(location.path()).toBe('/student');
}));
});