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
Apparently I can set the value directly without a spy or mock:
component.form = {value: {yearsWithEmployer: '6'}};
expect(component.showPreviousEmployer()).toBe(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With