Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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 FormControl中的假阴性测试值_Angular_Jasmine_Karma Jasmine - Fatal编程技术网

Angular FormControl中的假阴性测试值

Angular FormControl中的假阴性测试值,angular,jasmine,karma-jasmine,Angular,Jasmine,Karma Jasmine,我有一个Angular组件,它编辑通过@Input()加载的对象中的数据: 组件的模板为: <div class="container-fluid"> <div class="row"> <form class="form-inline" [formGroup]="editForm"> <div class="col-xl-3"> <label for="editFieldInput

我有一个
Angular
组件,它编辑通过
@Input()
加载的对象中的数据:

组件的模板为:

<div class="container-fluid">
  <div class="row">
    <form class="form-inline"
          [formGroup]="editForm">
      <div class="col-xl-3">
        <label for="editFieldInput"
               class="sr-only">Field Value</label>
        <input id="editFieldInput"
               type="text"
               class="form-control-sm"
               placeholder="Field"
               formControlName="editFieldControl">
      </div>
    </form>
  </div>
</div>
我可以成功地测试(并失败)
onInit()
逻辑,因此表单控件的值被设置为
obj.field
的值。然后,我尝试生成
onClear()
方法的失败测试:

it('should reset FormControls to their original value', () => {
  fixture.whenStable().then(() => {
    component.editForm.controls.editFieldControl.setValue('test');
    component.onClear();
    fixture.detectChanges();
    fixture.whenStable().then(() => {
      expect(component.editForm.controls.editFieldControl.value).toBe(component.obj.field);
    })
  });
});
由于
onClear()
是一个空方法,我希望这个测试失败,但它通过了。我玩了一会儿,试图产生一个失败,但没有成功,最终尝试用以下内容取代最初的预期:

expect(component.editForm.controls.editPackControl.value).toBe('111');
expect(component.editForm.controls.editPackControl.value).toBe('000');

奇怪的是,这个不可能的期望也过去了。我尝试重新启动
karma
服务器,然后重新启动
节点
本身,但是错误的否定仍然存在。您是否尝试过使用类似于
it('should reset FormControls to the private value',async(()=>{
?我想知道在下面的代码
中,这个
指的是什么。toBe(this.obj.field)
@yurzui“this”输入错误,不是在实际代码中。可能是在我将实际组件代码简化为可读性更强的代码时发生的。我以前尝试过注入
async
函数,但没有成功。让我们尝试重新生成它。请看一分钟,下面是失败的测试
it('should reset FormControls to their original value', () => {
  fixture.whenStable().then(() => {
    component.editForm.controls.editFieldControl.setValue('test');
    component.onClear();
    fixture.detectChanges();
    fixture.whenStable().then(() => {
      expect(component.editForm.controls.editFieldControl.value).toBe(component.obj.field);
    })
  });
});
expect(component.editForm.controls.editPackControl.value).toBe('111');
expect(component.editForm.controls.editPackControl.value).toBe('000');