I wanted to pass use-translation as a parameter to util function I created, I'm not able get the desired result, how can I pass a function?
import { useTranslation } from "react-i18next";
import { submissionTypes } from "../../Submissions/Details/constants";
import { getFormName } from "./helpers";
// jest.mock("react-i18next", () => ({
// useTranslation: () => ({ t: key => key }),
// }));
// jest.mock('react-i18next', () => ({
// useTranslation: () => ({
// i18n: { changeLanguage: jest.fn() },
// t: key => key,
// }),
// }));
describe("utils/helpers", () => {
const { t } = useTranslation();
describe("getFormName()", () => {
it("should return withdrawal", () => {
const result = getFormName("withdrawal", true, t ); //last parameter is 't' which is a translation function
expect(result).toEqual("WITHDRAWAL");
});
});
});
Below if function definiton for getFormName:
export function getFormName(type, uppercase, t) {
switch (type) {
case "withdrawal":
return uppercase
? _.upperCase(t("mission.withdrawal"))
: t("mission.withdrawal");
default:
return uppercase ? _.upperCase(type) : toTitleCase(type);
}
}