January 2018
Beginner
658 pages
13h 10m
English
Now, we'll create a new function that squares a number and returns the result. We'll define that in the utils.js file using module.exports.square. We'll set that equal to an arrow function (=>) that takes in one number, x, and we'll return x times x, x * x, just like this:
module.exports.add = (a, b) => a + b;module.exports.square = (x) => x * x;
Now we have this brand new function square and we'll create a new test case that makes sure square works as expected. In utils.test.js, next to the if condition for add function, we'll call the it function again:
const utils = require('./utils');it('should add two numbers', () => { var res = utils.add(33, 11); if (res != 44){ throw new Error(`Expected 44, but ...Read now
Unlock full access