角度:如何为动态表单编写单元测试用例(SPEC FILE)?

时间:2019-02-05 15:08:33

标签: javascript angular

我已使用以下链接构建动态表格。现在,我需要编写测试用例,而我无法继续。请帮忙。

https://toddmotto.com/angular-dynamic-components-forms

下面是将为文本字段呈现的组件的代码 该组来自父组件,该父组件是FormGroup的类型

text.component.ts

export class TextComponent implements OnInit {
  config;
  group: FormGroup;
  flexiformParams;
  validationList: any[] = [];
  rowIndex;
  tableDefId;
  mode = '';
  modeConstants = ModeConstants;
  constructor(private _formValidateService: FormValidationService, private _formDataService: FormDataService) { }
  ngOnInit() {
    this.mode = this._formDataService.mode;
    if (this.config.required) {
      this.validationList.push(Validators.required); // required condition
    }
    const valConditions = this._formValidateService.textTypeValidation(this.config['fieldProperties']); //allowed characters and capital allow
    this.validationList = this.validationList.concat(valConditions);
    this.group.controls[this.config.fieldDefinitionId].setValidators(this.validationList);
  }

  get text() {
    return this.group.get(this.config.fieldDefinitionId);
  }

  get textValue() {
    return this.config.value != '' ? this.config.value : '-';
  }
}

0 个答案:

没有答案