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

176
Visualizações
Setting somethig equal to the value of a known method with known contents results in undefined

I have a piece of code that generates objects that deliver functions, but the function variable pulled from the first variable only comes up as undefined.

Early in the code, an object is defined to return an object containing functions, the function in this case being something like:

/* Pulls in and sets up libraries like hapi, axios, lodash, joi, await-to-js */
/* CODE */
module.exports = {
 routes: () => {  // This is in a set location used by a well established library
  
     return [
       {
          'handler': function (a, b) { return ((a - b)/12) }
       }
     ]
  }
}

An object is created by a function in my testing scripts:

/* Pulls in and libraries like chai, chai expect, chance, to, sinon, proxyquire, and sinonChai */
/* CODE */
describe ('function fetcher', () => {
  it('should return a function', async () => {
    let testModule = proxyquire('../path-to-file/', {})
    let myObject =  await testModule.routes() // The library function that grabs the routes
    console.debug(typeof(myObject))
    console.debug(myObject)
    let result = myObject.handler
    console.debug(typeof(result))
    console.debug(result)
    result(chance.Number, chance.Number)
    /* More processing */
  })
})

And it returns

/* OUTPUT */
object
{
   handler: [Function: handler]
}
undefined
undefined

My goal is to get this line to work:

/* CODE */
return result(a, b)
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