February 2019
Intermediate to advanced
204 pages
4h 52m
English
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 and the hourly rate is provided.", () => { expect(calculateBill(10, 40)).toBe(400);});We can run the test by simply executing a yarn test command as:
yarn testyarn run v1.12.1$ jestPASS app/JS/__tests__/calculateBill-test.js calculate bills when the number of hours and hourly rate are provided. (4ms)Test Suites: ...
Read now
Unlock full access