Skip to content

Instantly share code, notes, and snippets.

@richardhyatt
Last active May 5, 2017 19:01
Show Gist options
  • Select an option

  • Save richardhyatt/721bdffa65ad0eeb055915caf243116b to your computer and use it in GitHub Desktop.

Select an option

Save richardhyatt/721bdffa65ad0eeb055915caf243116b to your computer and use it in GitHub Desktop.
Unit Testing AWS Lambda Functions in Node.js #2
'use strict';
var expect = require( 'chai' ).expect;
var myLambda = require( '../index' );
describe( 'myLambda', function() {
[
"Richard",
"rhyatt"
].forEach( function( validName ) {
it( `successful invocation: name=${validName}`, function( done ) {
var context = {
succeed: function( result ) {
expect( result.valid ).to.be.true;
done();
},
fail: function() {
done( new Error( 'never context.fail' ) );
}
}
myLambda.handler( { name: validName }, { /* context */ }, (err, result) => {
try {
expect( err ).to.not.exist;
expect( result ).to.exist;
expect( result.valid ).to.be.true;
done();
}
catch( error ) {
done( error );
}
});
});
});
[
"Fred",
undefined
].forEach( function( invalidName ) {
it( `fail: when name is invalid: name=${invalidName}`, function( done ) {
myLambda.handler( { name: invalidName }, { /* context */ }, (err,result) => {
try {
expect( err ).to.exist;
expect( err.message ).to.equal( 'unknown name' );
expect( result ).to.not.exist;
done();
}
catch( error ) {
done( eror );
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment