I have this error in unit testing with jasmine:
Uncaught TypeError: Cannot read property 'filter' of undefined thrown
My function:
info() {
this.requestService.postRequest('Reports', 'getInfo', {})
.subscribe(
data => {
this.places = data.places;
this.types = data.types.filter(obj => obj.id != 20);
this.loading = false;
},
error => {
console.log(error);
this.loading = false;
});
};
The test:
it('When call requestService.postRequest', () => {
spyOn(component.requestService, 'postRequest').and.returnValue(of({}));
component.info();
expect(component.requestService.postRequest).toHaveBeenCalled();
expect(component.requestService.postRequest).toHaveBeenCalledTimes(1);
});