Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

288
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda