Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
Passing usetranslation as a parameter to function from jest

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);
  }
}
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!