Unit test example

We will look at a previous project called circleci-jobs-example (https://github.com/packtci/circleci-jobs-example) that has several unit tests that have been written to test individual functions. In the repository, we have a file called sort.js that has the following function in it:

/ Takes an array of objects and sorts by First Name
function sortListOfNames(names) {
    return names.sort((a, b) => {
        if (a.firstName < b.firstName) {
            return -1;
        }
        if (a.firstName > b.firstName) {
            return 1;
        }
        if (a.firstName === b.firstName) {
            return 0;
        }
    });
}

This function takes an array of objects and sorts the objects by the firstName attribute. For our unit test, we simply want to test that the sortListOfNames function will sort the first ...

Get Hands-On Continuous Integration and Delivery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.