这是茉莉花测试中的错误:
TypeError: Cannot read property 'length' of undefined throw\nUncaught TypeError: Cannot read property 'length' of undefined throws *
代码:
getReports(form){
this.requestService.postRequest('DB', 'detailEvent', {'form': form, 'table': typeTemp.table, 'actionReport': tipoTemp.action}).subscribe(
data => {
this.events = data.events.length ? data.events : [];
},
error => {
console.log(error);
});
};
我的测试:
it('Should call requestService.postRequest', () => {
spyOn(component.requestService, 'postRequest').and.returnValue(of({events:[]));
let form = {};
component.getReports(form);
expect(component.requestService.postRequest).toHaveBeenCalled();
expect(component.requestService.postRequest).toHaveBeenCalledTimes(3);
});