DEV Community

Discussion on: Unit Testing AWS Lambda Functions in Node.js

Collapse
 
harkinj profile image
harkinj

Thanks for the info. In the example given will running the unit tests still result in connecting to the dynamodb database via 'const documentClient = new AWS.DynamoDB.DocumentClient()'

Thread Thread
 
jarroo profile image
Alex Manarpies

I double-checked by setting a breakpoint and it's not being triggered. Notice that the deps property is actually a function:

exports.deps = () => { // notice the closure syntax
  const AWS = require('aws-sdk')
  const documentClient = new AWS.DynamoDB.DocumentClient()

  return Promise.resolve({
    dynamoBatchWrite: params => documentClient.batchWrite(params).promise()
  })
}

.. its body contents should only be run when deps is invoked as a function (in this case async).

Thread Thread
 
harkinj profile image
harkinj

Perfect, thanks for your time and this great article.