how to perform "split" test with Angular ?
I'm trying to run a test on a method that has a "split" but I end up getting this error
follow below method , and test class spec.ts
getCellData(row: any, column: any): any {
const nestedProperties: string[] = column.property.split('.');
let value: any = row;
for (const prop of nestedProperties) {
value = value[prop];
}
return value;
}
fdescribe('getCellData:', () => {
const column: any = [{
property: 'address.street',
label: 'Rua',
type: 'boolean',
}];
const columnItem: any =[{
name: 'teste',
address:{
street: 'Rua dos Alfeneiros, nº 4'
}
}]
let value: any = columnItem;
it('teste A', () => {
const nestedProperties: string[] = column.property.split('.');
expect(component.getCellData(column, value)).toEqual(nestedProperties);
});
});
const nestedProperties: string[] = column.property.split('.');
in the implementation and the test? And why type everything asany
? That's not actually what the thing you're trying to to test returns anyway, because it processes it further. Also note you're passingcolumn
to therow
parameter andvalue
to thecolumn
parameter, which doesn't seem consistent. And finallyvalue
is an array, which doesn't have aproperty
property to.split
. – jonrsharpe