Testing the setName method

Now let's wrap up this section with some more testing. Over in utils.js, we can make a new function, one that we'll be testing, module.exports.setName. The setName function is will take two arguments. It'll take a user object, some fictitious user object with some generic properties, and it'll take fullName as a string:

module.exports.add = (a, b) => a + b;module.exports.square = (x) => x * x;module.exports.setName (user, fullName)

The job of setName will be to rip apart fullName into two parts—the first name and the last name—by splitting it on the space. We'll set the two properties, first name and last name, and return the user object. We'll fill out the function then we'll write the test case.

The first thing ...

Get Learning Node.js Development 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.