aws-lambda-mock-context
This library returns a mock context object that can be used to test lambda functions
Installation
npm install --save aws-lambda-mock-context
Usage
The library can be used in combination with SinonJS to test if the correct
methods are called.
var chai = require('chai'),
sinon = require('sinon'),
sinonChai = require('sinonChai'),
Q = require('q'),
ctx = require('aws-lambda-mock-context');;
chai.should();
chai.use(sinonChai);
describe('Lambda Test', function() {
var ctx = context();
beforeEach(function() {
sinon.spy(ctx, 'succeed');
});
afterEach(function() {
ctx.succeed.restore();
});
it('Should call the succeed method', function(done) {
Q.fcall(function() {
return index.handler({hello: 'world'}, this.ctx);
}).then(function() {
ctx.succeed.should.be.calledOnce;
done();
});
});
});
If the handler method is asynchronous, make sure it returns a promise. If you don't return
a promise, the test will fail. This is because the handler returns but at that moment, the
succeed
method is not yet called.
Contributors
License
MIT © Sam Verschueren