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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.