-
Book Overview & Buying
-
Table Of Contents
Node.js for Beginners
By :
In this section, we will build our first test suite. We will build a test suite for the utils module that we created and published in the previous chapter.
We will use the node:test and node:assert modules to build our test suite, and then we will build the same tests using the Jest framework, so we can compare both approaches and see the differences.
Let’s start by creating a new folder and then initialize a new Node.js project with npm init. Then we will create a utils.js file with the following code:
export const sum = (a, b) => a + b export const multiply = (a, b) => a * b
The code is very simple. The sum function will sum two numbers and the multiply function will multiply two numbers. Then the tests should be very simple as well.
Basically, we need to test that the sum function is summing two numbers and the multiply function is multiplying two numbers.
Recently, Node.js has introduced...