This library returns a mock context object that can be used to test lambda functions
npm install --save aws-lambda-mock-contextThis library can be used with promises or callbacks.
// module dependencies
var context = require('aws-lambda-mock-context');
// Start the test
describe('Lambda Test', function() {
it('Should call the succeed method', function(done) {
index.handler({hello: 'world'}, context());
context.Promise
.then(function() {
// succeed() called
done();
})
.catch(function(err) {
// fail() called
done(err);
});
});
it('Should call the fail method', function(done) {
index.handler({hello: 'wrld'}, context(function(err, result) {
if(err) {
// If we have an error, it's fine
done();
}
else {
// If we don't have an error, it means the fail() method was not called
done(new Error('Fail not called');
}
));
});
});- Sam Verschueren [[email protected]]
MIT © Sam Verschueren