Now we will extend our project by providing a unit test for the HTTP module, but before diving into that, let's have a look at how Node.js supports unit testing in general. At the beginning of this chapter, we installed the Nodeunit module. Well, it's about time we started playing around with it.
First, let's create another simple Node.js module that we will use to implement our first unit test. Then we will move to more advanced topics, such as mocking JavaScript objects and using them to create unit tests for our HTTP module.
I have chosen to develop a simple math module that exports functions for adding and subtracting integer numbers, as it is straightforward enough and the results of each operation are strictly defined.
Let's start with the module and create the following math.js file in our module directory:
exports.add = function...