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

177
Vistas
Can I have Jest Mocks in a different file and import it into my test file?

I have a custom Hook in a file and I have to mock it quite often for multiple tests. Can I have the mock in a separate file and then just import it into the test?

Hook file

export default function myHook(key) {
    const { state, app } = StateFromSomePlace();

    const setParameter = useCallback(
        newValue => {
            // do something
        },
        [app, key, state.something]
    );

    if (key) {
       // do something
        const parameter = // something;
        return [parameter, setParameter];
    }
}

i want to mock the above using jest to return something (which i can), but i want to do so in an helper/setup file so i can use it in multiple test by just importing the mock.

Thanks for the help in advance. :)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

https://jestjs.io/docs/manual-mocks

You can as per the documentation Follow the instruction

about 4 years ago · Juan Pablo Isaza Denunciar
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