0
votes

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);

      });
    });
Why have you repeated the line const nestedProperties: string[] = column.property.split('.'); in the implementation and the test? And why type everything as any? That's not actually what the thing you're trying to to test returns anyway, because it processes it further. Also note you're passing column to the row parameter and value to the column parameter, which doesn't seem consistent. And finally value is an array, which doesn't have a property property to .split.jonrsharpe