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