Конфигурация тестового стенда
TestBed.configureTestingModule({
declarations: [ EditPersorgaComponent, ArrayFromIntPipe, TeamFilterPipe ],
schemas: [ NO_ERRORS_SCHEMA ],
imports: [ HttpClientModule, NgbModule.forRoot(), TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})],
providers: [
{ provide: Renderer2, useValue: renderer2Stub },
{ provide: NavigationService, useValue: navigationServiceStub },
{ provide: DatepickerFormater, useValue: datepickerFormaterStub },
{ provide: NgbModal, useValue: ngbModalStub },
{ provide: PersorgaService, useValue: persorgaServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: ActionsSubject, useValue: actionsSubjectStub },
{ provide: ToasterService, useValue: toasterServiceStub },
{ provide: TranslateService, useValue: translateServiceStub },
{ provide: AppConfirmService, useValue: appConfirmServiceStub }
]
});
fixture = TestBed.createComponent(EditPersorgaComponent);
comp = fixture.componentInstance;
});
Я хочу проверить ngOninit в Angular 2 +
ngOnInit() {
this.navigationService.menuStore$.dispatch(new SetFromArray({
widgetName: 'elementPersonalOrg', data: NavigationService.getMenuElement('elementPersonalOrg').sub
}));
this.selectedDate = this.dpFormatter.convertToNgbDateStruct(new Date());
}
Я попробовал юнит-тест
describe('ngOnInit', () => {
it('makes expected calls', async( () => {
const navigationServiceStub: NavigationService = fixture.debugElement.injector.get(NavigationService);
spyOn(navigationServiceStub, 'menuStore$');
comp.ngOnInit();
expect(navigationServiceStub.menuStore$).toHaveBeenCalled();
}));
});
Я получаюошибки типа
TypeError: Невозможно прочитать свойство 'id' из undefined Failed: Невозможно прочитать свойство 'debugElement' из undefined
Может кто-нибудь, пожалуйста, помогите мне с этим.Спасибо