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);