Skip to content

Instantly share code, notes, and snippets.

@richardhyatt
Last active June 11, 2019 18:09
Show Gist options
  • Save richardhyatt/2d1ce5845c1b5aec2f31a07d0a814077 to your computer and use it in GitHub Desktop.
Save richardhyatt/2d1ce5845c1b5aec2f31a07d0a814077 to your computer and use it in GitHub Desktop.
Unit Testing AWS Lambda Functions in Node.js #3
'use strict';
var expect = require( 'chai' ).expect;
var LambdaTester = require( 'lambda-tester' );
var myLambda = require( '../index' );
describe( 'myLambda', function() {
[
"Richard",
"rhyatt"
].forEach( function( validName ) {
it( `successful invocation: name=${validName}`, function() {
return LambdaTester( myLambda.handler )
.event( { name: validName } )
.expectResult( ( result ) => {
expect( result.valid ).to.be.true;
});
});
});
[
"Fred",
undefined
].forEach( function( invalidName ) {
it( `fail: when name is invalid: name=${invalidName}`, function() {
return LambdaTester( myLambda.handler )
.event( { name: invalidName } )
.expectError( ( err ) => {
expect( err.message ).to.equal( 'unknown name' );
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment