Skip to content Skip to sidebar Skip to footer

Mocking In AWS Lambda

I have a simple AWS Node.js Lambda, which I would like to test using mocks: //SimpleLambda.js var AWS = require('aws-sdk'); exports.handler = function(event, context) { var nam

Solution 1:

You need to export your getName function so that it's accessible from test.js (and can be wrapped by your mocking library).

Something like this:

//SimpleLambda.js

var AWS = require('aws-sdk');

exports.handler = function(event, context) {
 var name = exports.getName();
 context.succeed(name);
};

exports.getName = function (){
  return 'David';
}

Solution 2:

Try to put simple.mock(lambda, 'getName').returnWith('Tim'); to beforeEach and delete this lambda.getName.returnWith('Tim');.


Post a Comment for "Mocking In AWS Lambda"