Angular 组件测试 TypeError: cannot read properties of undefined (reading 'value')

问题描述 投票:0回答:0

我是 Angular 的新手。并尝试编写一些单元测试。继续未定义(阅读“价值”) //这是我的组件类(提前谢谢你)

export class inputComponent implements ICellRendererAngularComp {
   public flag!: boolean;
   public params: any;

   agInit(params: ICellRendererParams): void {
     const fieldName = params.colDef?.field;
     let name: string = fieldName!
     this.flag = params.data[name];
     this.param = params;
   }

   refresh(params: ICellRendererParams) {
     this.params = params;
     return true;
   } 

这是我的测试

it('should agInit and refersh', () => {
 component.agInt(<ICellRendererParams>{ data: {"test": true}, colDef: {fiedl: "test"} })
 component.refresh(<ICellRendererParams>{ data: {"test": true}, colDef: {fiedl: "test"} })
 expect(component).toBeTruthy();
});

我得到:

TypeError:无法读取未定义的属性(读取“值”)

angular angularjs unit-testing components
© www.soinside.com 2019 - 2024. All rights reserved.