Exercise 22: Writing Basic Tests with Lab

In this exercise, we will introduce the concept of writing unit tests for the Hapi.js web API, mainly using the third-party lab module and the built-in assert module. Ideally, we should have a separate database for our tests, but for the sake of simplicity here, we will share our development database for tests too:

  1. Let's first start by installing the necessary packages. Notice that we are using --save-dev since tests are not needed for production, therefore, they are development dependencies:
npm install lab --save-dev
Use the Code/Lesson-3/exercise-c for your reference.
  1. Create a test folder at the root of the project—that is where we will have our tests. Since our API is a simple one, we will ...

Get Beginning API Development with Node.js 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.