CPSC270
Software Engineering and Project Design

Activity 26

Testing - Jest

Write Jest tests for the following function:

/**
 * Square a number.
 * @param {number} number - A number to square.
 * @return {number} The number squared.
 */
function square(number) {
    if (typeof number !== 'number') {
        throw new TypeError(`the type "${typeof number}" is not number`);
    }
    return number * number;
}

module.exports = square;