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

140
Vistas
How to set path property in order to return a value?

I'm using Jest in order to test a js function. In my function I have a flag variable. If flag is true I require another js file (which is into the same folder of function to test) otherwise I get the path of the file to include. For this in my function I have:

var utility;
if(flag) {
    utility = require('./utility');
} else {
    utility = require(Runtime.giveFunctions()['utility'].path);
}
const variable = utility.getValue(someParameters);

It's enough cover 'else' branch and for this I want to return from path: './utility'. In my test I write:

const Runtime = {
    giveFunctions: jest.fn().mockReturnValue({
        utility: jest.fn().mockReturnValue({
            path: jest.fn().mockReturnValue('./utility')
        })
    })
};

window.Runtime = Runtime;

When I launch the test I receive the error: utility.getValue is not a function (getValue is the function defined in utility.js). More, if in my function i use console.log in order to print 'Runtime' I read: Runtime.giveFunctions()['utility'].path undefined. I think I didn't mock path property well. How can I solve this issue? Thank's to all.

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