title: Writing unit test cases for lazy loaded module angular
body: <p>Getting <strong>NgModuleFactoryLoader is deprecated: the <code>string</code> form of <code>loadChildren</code> is deprecated, and <code>NgModuleFactoryLoader</code> is
  part of its implementation. See <code>LoadChildren</code> for more details.</strong> warning and not able to stub the module for testing the lazy loaded module</p>
  <p>Below is the code</p>
  <pre><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: () =&gt; import('./admin/admin.module').then(m =&gt; m.AdminModule)
    },
    { path: '', component: FrontpageComponent }];
  
      describe('Router: App', () =&gt; {
  
        let location: Location;
        let router: Router;
        let fixture: ComponentFixture&lt;AppComponent&gt;;
        let loader: any;
  
        beforeEach(() =&gt; {
          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', () =&gt; {
          expect(fixture.componentInstance).toBeDefined();
        });
  
       it('should navigate to /student lazy loaded ,pdule', fakeAsync(() =&gt; {
  
          const loader = TestBed.get(NgModuleFactoryLoader);
          loader.stubbedModules = {lazyModule: StudentModule};
  
          router.resetConfig([
            {path: 'student', loadChildren: 'lazyModule'},
          ]);
  
          router.navigate(['student'])
  
          tick();
  
          expect(location.path()).toBe('/student');
        }));
      });
  </code></pre>