Testing ES6 functions is pretty straightforward. Let's consider a function that calculates the total bill for a person when the hourly rate and the number of hours are provided. Save the snippet in a file called something like calculateBill.js.
Testing ES6 functions
Testing a function
Let's consider the following function, calculateBill. It takes totalHours and ratePerHours as the arguments, and returns the total bill:
const calculateBill = (totalHours, ratePerHours) => totalHours * ratePerHours;
module.exports = calculateBill;
To test, it let us create a file and call it calculateBill-test.js:
const calculateBill = require("../calculateBill");
test("calculate bills when the number of hours...