Я тестирую метод, который помещает свойство в мой массив ... но выдает ошибку: Не удается прочитать свойство 'forEach' из неопределенного.
Как это исправить?
Примечание: я тестирую в основном метод использования автозаполнения матов на mu HTML, поэтому forEach предоставляет данные для автозаполнения
Spe c
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', () =>{
const spy = spyOn(component, 'pushOnCustomerNames').and.callThrough();
component.pushOnCustomerNames();
mockCustomer.forEach(element => {
mockCustomer.push(element.name)
});
expect(spy).toHaveBeenCalled();
})
Компонент
pushOnCustomerNames() {
this.customerNames = [];
this.customer.forEach((customer: CustomersViewModel) => {
this.customerNames.push(customer.name);
});
}
getCustomers() {
this._managService.getCustomers().then(customerResponse => {
this.customer = customerResponse;
this.pushOnCustomerNames();
this.filterCustomers();
}).catch((err) => {
this.toastr.error(err);
})
}
filterCustomers() {
this.filteredCustomer = this.formFilter.get("customerName").valueChanges
.pipe(
startWith(''),
map(value => this._filterCustomer(value))
);
}
_filterCustomer(value: string): string[] {
return this.customerNames.filter(customer => customer.includes(value));
}