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

182
Visualizações
Aws Lambda, NodeJS, Jest: TypeError: handler is not a function

Writing tests for a Lambda function.

In the code below, when the test calls handler, it throws an error saying: TypeError: handler is not a function.

index.js (Lambda)

const aws = require('aws-sdk')

exports.handler =  async function(event, context) { 
        //if incoming data is valid then proceed
        let message = parse_event(event);
        
        if(abc(message))
        {
            await doSomething(message);
        }   
};

function parse_event(message)
{
  return JSON.parse(message) 
}

function abc(message)
{
  conssole.log('xyz') 
  return true 
}

async function doSomething(message)
{
 console.log('doing something with: ' + JSON.stringify(message))
}


module.exports = {abc, doSomething, parse_event}

index.spec.js

const mod = require("./index");

describe('Tests',  () => 
{   
  test('does it do something', async ()=>
  {
    var ev = '{"xyz": 123}'

    ...
       
    //Here it throws --  TypeError: handler is not a function.
    await mod.handler(ev, "")
    expect(1=1)
        
  });
});

I've tried putting handler in the module.exports list, but no go.

When I break at the handler call, it shows as undefined. But when not in debug mode, if I dot the module where it resides, it is listed as a property/function.

Anyone have any advice here?

Thanks!

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