How to Unit Test with NodeJS?

We will use Mocha and Chai to do unit tests and talk about the importance of testing.

Serverless Guru
Serverless Guru

--

In this article, we are going to dive into unit testing and learn about how to use Mocha and Chai to write our tests. We will also take a look at how to do granular testing, an important concept when you have hundreds or thousands of unit tests. We will also talk about why testing is important.

Overview

  • What is unit testing?
  • Mocha — what, how, run, result
  • Chai — what, how, run, result
  • Testing a real NodeJS function — code, test, run, result
  • Granular testing with the Mocha CLI — test a single file, test a group of tests or a single test
  • Testing Opinion — granular testing, testing & code quality
  • Testing Asynchronous functions
  • Review

What is unit testing?

“UNIT TESTING is a level of software testing where individual units/ components of a software are tested. The purpose is to validate that each unit of the software performs as designed. A unit is the smallest testable part of any software. It usually has one or a few inputs and usually a single output. In…

--

--

Serverless Guru
Serverless Guru

We can help you migrate to serverless, build serverless applications, and train your team on serverless best practices. https://www.serverlessguru.com