Skip to Main Content
Beginning API Development with Node.js
book

Beginning API Development with Node.js

by Anthony Nandaa
July 2018
Beginner content levelBeginner
100 pages
2h 7m
English
Packt Publishing
Content preview from Beginning API Development with Node.js

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro REST API Development with Node.js

Pro REST API Development with Node.js

Fernando Doglio
Building APIs with Node.js

Building APIs with Node.js

Caio Ribeiro Pereira
Learning Node.js

Learning Node.js

Marc Wandschneider

Publisher Resources

ISBN: 9781789539660Supplemental Content