Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda