Skip to content Skip to sidebar Skip to footer

Sinon.js Stub A Function That Resolves A Promise

I want to use Sinon to stub a function that uses callbacks which resolve a promise: const callback = (err, data) => { if (err) { reject(err); } else {

Solution 1:

This was due to a scope error. Per the docks for aws-sdk-mock, AWS service needs to be initialized in the function.

Does not work:

varAWS      = require('aws-sdk');
var sns      = AWS.SNS();
var dynamoDb = AWS.DynamoDB();

exports.handler = function(event, context) {
  // do something with the services e.g. sns.publish 
}

Works:

varAWS = require('aws-sdk');

exports.handler = function(event, context) {
  var sns      = AWS.SNS();
  var dynamoDb = AWS.DynamoDB();
  // do something with the services e.g. sns.publish 
}

Post a Comment for "Sinon.js Stub A Function That Resolves A Promise"