Я пытаюсь протестировать простое перенаправление с использованием TestBed, но постоянно вижу следующую ошибку:
Error: Uncaught (in promise): Error: Cannot find module ./pages/login/login.module#LoginPageModule
Мой тест выглядит следующим образом:
describe('AppComponent', () => {
let statusBarSpy, splashScreenSpy, platformReadySpy, platformSpy, platformIsSpy, storageSpy;
let router: Router;
let location: Location;
let fixture, loginFixture;
let comp: AppComponent;
beforeEach(async(() => {
statusBarSpy = jasmine.createSpyObj('StatusBar', ['styleDefault']);
splashScreenSpy = jasmine.createSpyObj('SplashScreen', ['hide']);
platformReadySpy = Promise.resolve();
platformIsSpy = Promise.resolve('ipad');
platformSpy = jasmine.createSpyObj('Platform', { ready: platformReadySpy, is: platformIsSpy })
storageSpy = jasmine.createSpyObj('Storage', ['get', 'set', 'clear', 'remove', 'ready']);
TestBed.configureTestingModule({
declarations: [AppComponent],
imports: [
IonicStorageModule.forRoot(),
HttpClientTestingModule,
LoginPageModule,
RouterTestingModule.withRoutes(routes),
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
{ provide: Storage, useClass: StorageMock },
{ provide: StatusBar, useValue: statusBarSpy },
{ provide: SplashScreen, useValue: splashScreenSpy },
{ provide: Platform, useValue: platformSpy },
],
}).compileComponents();
router = TestBed.get(Router);
location = TestBed.get(Location);
fixture = TestBed.createComponent(AppComponent);
loginFixture = TestBed.createComponent
comp = fixture.componentInstance;
router.initialNavigation();
}));
it('navigates to "" redirects you to /login', fakeAsync(() => {
router.navigate(['/login']);
tick();
expect(location.path()).toBe('/login')
}));
});
А мои маршруты в app-routing.module.ts
это:
export const routes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: 'login',
loadChildren: './pages/login/login.module#LoginPageModule'
// component: LoginPage
},
{
path: 'manager-dashboard',
canActivate: [AuthGuard],
loadChildren: './pages/manager-dashboard/manager-dashboard.module#ManagerDashboardPageModule'
},
];
А мой LoginPageModule
это:
const routes: Routes = [
{
path: '',
component: LoginPage
}
];
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [LoginPage]
})
export class LoginPageModule {}
Есть ли что-то, что мне нужно сделать, чтобы сделать эту работу?