Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Angular应用程序中测试_Angular - Fatal编程技术网

在Angular应用程序中测试

在Angular应用程序中测试,angular,Angular,在终端中运行ng测试时出现问题。错误是 “类型'FormGroup'不可分配给类型'FormArray' 。 属性类型“控件”不兼容。 " 我如何解决这个问题? ------------------------------------------/这是一个为我提供问题的类----------------- 这是密码 import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { SharedM

在终端中运行
ng测试时出现问题。错误是

“类型'FormGroup'不可分配给类型'FormArray'

。 属性类型
“控件”
不兼容。 "

我如何解决这个问题? ------------------------------------------/这是一个为我提供问题的类-----------------

这是密码

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { SharedModule } from '../../../../shared/shared.module';

import { FormGroup, Validators, FormControl, FormArray } from '@angular/forms';
import { StepAvailabilityComponent } from './step-availability.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

describe('StepAvailabilityComponent', () => {
  let component: StepAvailabilityComponent;
  let fixture: ComponentFixture<StepAvailabilityComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
        declarations: [ StepAvailabilityComponent ],
        imports: [SharedModule, FormsModule, ReactiveFormsModule]
    })
    .compileComponents();
  }));enter code here

  beforeEach(() => {
    fixture = TestBed.createComponent(StepAvailabilityComponent);
    component = fixture.componentInstance;
      component.fg = new FormGroup({operatingDays: new FormArray(
          [
          new FormGroup({
              enabled: new FormControl(false),
              localName: new FormControl('mandag'),
          }),
          ]
      )});
    fixture.detectChanges();
  });
从'@angular/core/testing'导入{async,ComponentFixture,TestBed};
从“../../../../shared/shared.module”导入{SharedModule};
从'@angular/forms'导入{FormGroup,Validators,FormControl,FormArray};
从“/step availability.component”导入{step availability component};
从'@angular/forms'导入{FormsModule,ReactiveFormsModule};
描述('StepAvailabilityComponent',()=>{
let组件:StepAvailability组件;
let夹具:组件夹具;
beforeach(异步(()=>{
TestBed.configureTestingModule({
声明:[步骤可用性组件],
导入:[SharedModule,FormsModule,ReactiveFormsModule]
})
.compileComponents();
}));在此处输入代码
在每个之前(()=>{
fixture=TestBed.createComponent(StepAvailabilityComponent);
组件=fixture.componentInstance;
component.fg=新表单组({operatingDays:新表单阵列(
[
新表单组({
启用:新FormControl(错误),
localName:newformcontrol('mandag'),
}),
]
)});
fixture.detectChanges();
});

我们还需要您测试的组件的代码欢迎使用Stack Overflow!我编辑了问题的描述,以使其更清晰、可读性更高的注释和代码,以便更多了解该主题的人可以看到。请在您遇到的特定错误消息中进行编辑,以防识别specific问题,祝你好运!