尝试在测试规范中构建表单时出错。表单构建功能还可以构建子表单数组。寻找测试的最佳方法
component.ts
buildForm() {
return this.peopleForm = this.fb.group({
people: this.fb.array([this.buildSubFormGroup()]),effective_date: [this.firstOfNextMonth(),Validators.required]
});
}
buildSubFormGroup(type: string = 'primary') {
return this.fb.group({
type: [type],first_name: ['',Validators.required],last_name: ['',dob: ['',gender: ['',uses_tobacco: ['',affordable_care: ['',is_pregnant: [''],});
}
component.spec.ts
it('should be able to build the peopleForm',() => {
component.buildForm();
fixture.detectChanges();
expect(component.peopleForm.controls['type'].value).not.toBeNull();
});
错误: 错误:没有附加到名称为“有效日期”的表单控件元素的FormControl实例