In the previous sections, we made two test cases to verify that utils.add and our utils.square method work as expected. We did that using an if condition, that is, if the value was not 44 that means something went wrong and we threw an error. In this section, we'll learn how to use an assertion library, which will take care of all of the if condition in utils.test.js code for us:
if (res !== 44)
throw new Error(`Expected 44, but got ${res}.`)
}
Because when we add more and more tests, the code will end up looking pretty similar and there's no reason to keep rewriting it. Assertion libraries let us make assertions about values, whether it's about their type, the value itself, whether an array contains an element, all sorts of things like that. They really are fantastic.
The one we'll be using is called expect. You can find it by going to Google and googling mjackson expect. And this is the result we're looking for:

It's mjackson's repository, expect. It is a fantastic and super popular assertion library. This library will let us pass in a value and make some assertions about it. On this page, we scroll down past the introduction and the installation we can get down to an example:

As shown in the preceding screenshot, we have our Assertions header and we have our first assertion, toExist. This will verify that a value exists. In the next line, we have an example, we pass in a string to expect:
This is the value we want to make some assertions about. In the context of our application, that would be the response variable in the utils.test.js, shown here:
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}.`)
}
});
We want to assert that it is equal to 44. After we call expect, we can start chaining on some assertion calls. In the assertion example, next we check if it does exist:
expect('something truthy').toExist()
This would not throw an error because a string is indeed truthy inside JavaScript. If we passed in something like undefined, which is not truthy, toExist would fail. It would throw an error and the test case would not pass. Using these assertions, we can make it really, really easy to check the values in our tests without having to write all of that code ourselves.