I have a helper file, which contains only one function, which uses transloco translate method.
translate.utils.ts
import { translate } from "@ngneat/transloco";
import { SelectItem } from "primeng/api";
export function someFunction(param: any[]): any[] {
return param.map((obj:any) => {
const newLabel= translate(obj.label as any);
obj.label = newLabel;
return obj;
}) as any;
}
I have imported this function in my angular component
Like this
import { someFunction } from '../utils/translate.utils';
..
//somewher in the component used as
data = someFunction(SOME_OPTIONS)
while running the test, i'm getting this error
TypeError: Cannot read properties of undefined (reading 'translate')
how to mock someFunction
? or fix this translate?
Test were coded in jasmine
Tried mocking like
spyOn(window, "translate").and.callFake((label: string) =>
Translated ${label}
);import * as translate from '../utils/translate.utils' spyOn(translate, "translate").and.callFake((label: string) =>
Translated ${label}
);
nothing works, any leads would be appreciated. Thanks