我是单元测试的新手,如何使用组件外部的函数createFormGroup将单元测试写入cellClickHandler() ,如下所示。
const createFormGroup = (dataItem) => {
const group: any = {};
group['colorName'] = new FormControl(dataItem.colorName);
group['itemNo'] = new FormControl(dataItem.itemNo);
dataItem.availableSizes.forEach((element) => {
group[element.sizeName] = new FormControl(element.value);
});
return new FormGroup(group);
};
@Component({
selector: 'co-line-entry-singles',
templateUrl: './line-entry-singles.component.html',
})
export class LineEntrySinglesComponent {
public gridData: any[];
@ViewChild(GridComponent)
private grid: GridComponent;
public formGroup: FormGroup;
private editedRowIndex: number;
constructor() {}
public cellClickHandler({ isEdited, dataItem, rowIndex }): void {
this.formGroup = createFormGroup(dataItem);
this.editedRowIndex = rowIndex;
this.grid.editRow(rowIndex, this.formGroup);
}
}