Testing functions with Mocha and Chai

The first step to creating a continuously deployable Lambda function is to write unit tests. One of the easiest and simplest ways to do so is by using a combination of two frameworks called Mocha and Chai.

First, a little bit about the two frameworks without going into too much information:

  • Mocha: Mocha is a simple test framework for Node.js created to be easily extensible and fast for testing. It is used for unit and integration testing. You can read more about it at https://mochajs.org/. Mocha provides a unique ability to describe the features that we are implementing in our code by giving us a describe function that encapsulates our expectations:
 describe('myLambda',function(){ //assertions about ...

Get Mastering AWS Lambda now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.