Reputation: 1117
I have a component which has an Input, and functions that use the inputs
Component:
@Input() form: FormGroup;
....
showPreviousEmployer() {
return parseInt(this.form.value.yearsWithEmployer, 10) < 5;
}
How Can I either Spy on or mock 'form' for jasmine tests?
I tried:
spy = spyOnProperty(component, 'form', 'get').and.returnValue({value: {yearsWithEmployer: '6'}});
expect(component.showPreviousEmployer).toBe(false);
However that gives the error:
Error: form property does not exist
Upvotes: 4
Views: 2967
Reputation: 1117
Apparently I can set the value directly without a spy or mock:
component.form = {value: {yearsWithEmployer: '6'}};
expect(component.showPreviousEmployer()).toBe(false);
Upvotes: 5