December 2018
Intermediate to advanced
642 pages
15h 5m
English
First, let's see a simple, basic set of functional tests, and for that, let's go back to the rounding library we wrote in the Working with modules section of Chapter 3, Developing with Node. When you test a module, you only test the exported functions to see if they perform according to their specs. The interesting part to test is, then, the following:
const addR = (x: number, y: number): number => roundToCents(x + y);const subR = (x: number, y: number): number => addR(x, changeSign(y));const multR = (x: number, y: number): number => roundToCents(x * y);const divR = (x: number, y: number): number => { if (y === 0) { throw new Error("Divisor must be nonzero"); } else { return roundToCents(x / y); }};
These four functions ...
Read now
Unlock full access