Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!