title: Jasmine Testing ForEach and getting cannot read property ''forEach''
body: <p>I'm testing a method that pushes a property to my array... but having the error: Cannot read property 'forEach' of undefined.</p>
  
  <p>How can I fix this?</p>
  
  <p>Note: I'm testing basically a method to use a mat-autocomplete on mu HTML, so the forEach provides data to the autocomplete</p>
  
  <p><strong>Spec</strong></p>
  
  <pre><code>mockCustomer = [{
        'id': "45831a77-5fee-49f0-8c87-3de1e881fcd1",
        'name': "John Doe",
        'alias': "John",
        'isEnabled': true,
        'updatedOn': "12-12-2020",
        'updateBy': "Daniel"
      },
      {
        'id': "c5c90f2e-b712-43a0-bf8d-0fdfe9c07076",
        'name': "Jeff Doe",
        'alias': "Jeff",
        'isEnabled': true,
        'updatedOn': "10-12-2020",
        'updateBy': "Daniel"
      }]
  
  it('should push on Customer', () =&gt;{
      const spy = spyOn(component, 'pushOnCustomerNames').and.callThrough();
      component.pushOnCustomerNames();
  
      mockCustomer.forEach(element =&gt;  {
        mockCustomer.push(element.name)
      });
  
      expect(spy).toHaveBeenCalled();
  
    })
  </code></pre>
  
  <p><strong>Component</strong></p>
  
  <pre><code>pushOnCustomerNames() {
      this.customerNames = [];
      this.customer.forEach((customer: CustomersViewModel) =&gt; {
        this.customerNames.push(customer.name);
      });
    }
  
  getCustomers() {
      this._managService.getCustomers().then(customerResponse =&gt; {
        this.customer = customerResponse;
        this.pushOnCustomerNames();
        this.filterCustomers();
      }).catch((err) =&gt; {
        this.toastr.error(err);
      })
    }
  
  filterCustomers() {
      this.filteredCustomer = this.formFilter.get("customerName").valueChanges
        .pipe(
          startWith(''),
          map(value =&gt; this._filterCustomer(value))
        );
    }
  
  _filterCustomer(value: string): string[] {
      return this.customerNames.filter(customer =&gt; customer.includes(value));
    }
  
  </code></pre>