In my angular appliation, I have a config file where I defined some property. In my component I have a method which makes use of that property. I am writing a test case for that method, when I am trying to use spyOnProperty on that property, I get an error saying Error: : getRequestInfo is not declared configurable. Below is the component and spec file.
component.ts
getRequestInfoDetails(config: MyConfig): void {
if (config.update) {
const payload: Partial<IRequestInfoRequest> = getRequestInfo(
this.form.getRawValue(),
config.update
);
}
}
MyConfig.ts
export const getRequestInfo = (
form,
status: string
): Partial<IRequestInfoRequest> => {
// business logic
}
Spec.ts
it('getRequestInfoDetails to have called', () => {
const myFrmgrp = new FormGroup({
});
const config: MyConfig = {
form: myFrmgrp,
status: 'true'
};
const request: Partial<IRequestInfoRequest> = {};
const spyObj = spyOnProperty(config, 'getRequestInfo', 'get').and.returnValue(null);
component.getForm(config);
expect(spyObj).toHaveBeenCalled();
});