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

183
Vistas
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 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