Creating the if condition for the test

Now, we'll create an if statement for the test. If the response value is not equal to 44, that means we have a problem on our hands and we'll throw an error:

const utils = require('./utils');

it('should add two numbers', () => {
var res = utils.add(33, 11);

if (res != 44){

}
});

Inside the if condition, we can throw a new error and we'll use a template string as our message string because I do want to use the value that comes back in the error message. I'll say Expected 44, but got, then I'll inject the actual value, whatever happens to come back:

const utils = require('./utils');

it('should add two numbers', () => {
var res = utils.add(33, 11);

if (res != 44){
throw new Error(`Expected 44, but got ${res}.`);
}
});

Now in our case, everything will line up great. But what if the add method wasn't working correctly? Let's simulate this by simply tacking on another addition, adding on something like 22 in utils.js:

module.exports.add = (a, b) => a + b + 22;

I'll save the file, rerun the test suite:

Now we get an error message: Expected 44, but got 66. This error message is fantastic. It lets us know that something is going wrong with the test and it even tells us exactly what we got back and what we expected. This will let us go into the add function, look for errors, and hopefully fix them.

Creating test cases doesn't need to be something super complex. In this case, we have a simple test case that tests a simple function.