Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 如何在Jasmine中监视或模拟角度@输入?_Angular_Unit Testing_Jasmine - Fatal编程技术网

Angular 如何在Jasmine中监视或模拟角度@输入?

Angular 如何在Jasmine中监视或模拟角度@输入?,angular,unit-testing,jasmine,Angular,Unit Testing,Jasmine,我有一个有输入的组件和使用输入的函数 组成部分: @Input() form: FormGroup; .... showPreviousEmployer() { return parseInt(this.form.value.yearsWithEmployer, 10) < 5; } 但是,这会产生错误: 错误:表单属性不存在 显然,我可以直接设置值,而无需间谍或模拟: component.form = {value: {yearsWithEmployer: '6'}};

我有一个有输入的组件和使用输入的函数

组成部分:

@Input() form: FormGroup;
....

showPreviousEmployer() {
    return parseInt(this.form.value.yearsWithEmployer, 10) < 5;
}
但是,这会产生错误:

错误:表单属性不存在


显然,我可以直接设置值,而无需间谍或模拟:

   component.form = {value: {yearsWithEmployer: '6'}};
   expect(component.showPreviousEmployer()).toBe(false);
   component.form = {value: {yearsWithEmployer: '6'}};
   expect(component.showPreviousEmployer()).toBe(false);