2

So I was wondering - been using the aws-sdk-mock library for Node / Jasmine.

This particular library allows you to mock the service method invocations. However this appears to be a problem when attempting to mock a method called more than once, but fed different parameters (thus invoking a different lambda).

Aws.mock('lambda', 'invoke', function(params, callback){
callback(null, {})
}

This will mock every call to invoke, which really isn't flexible, what I think would be useful would be to see if the params passed to it contained a specific value.

Now I would not be tied to the AWS.mock framework I don't believe, so if anyone has any pointers how to handle this, it would be great. See the invocation flow below.

Custom function (called from test) -> custom function (calling the invoke)

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
aspiringCoder
  • 415
  • 1
  • 9
  • 24

1 Answers1

1

I found the solution to this to be checking the parameters of the lambda being mocked. For example if you have a lambda named lambdaOne and a lambda named lambdaTwo, your mock would look like this:

Aws.mock('lambda', 'invoke', function(params, callback){
    if (params.FunctioName === 'lambdaOne'){
        callback(null, lambdaOneResponse)
    }
    else if (params.FunctioName === 'lambdaTwo')
        callback(null, lambdaTwoResponse) 
}

I hope this helps!

rocketlobster
  • 690
  • 7
  • 18
  • I could only get this to work with capitalising the 'L' in lambda, e.g. `Aws.mock('Lambda', 'invoke', function(params, callback){...` – steswinbank Sep 03 '19 at 10:10