When a function returns nested maps or arrays, checking every field by hand turns a small test into busywork. Lodash’s _.isEqual recursively compares JavaScript data collections by value, making expected-output tests compact. section 6.1 section 6.2.2
Equal and non-equal collections
_.isEqual({ name: "Alan Moore", bookIsbns: ["978-1779501127"] }, { name: "Alan Moore", bookIsbns: ["978-1779501127"] }); // true Changing the ISBN to "bad-isbn" makes the comparison false. The same approach checks a function result against its expected array or map. section 6.1
Listing 6.3 The general pattern of a data-oriented test case
var dataIn = {
// input
};
var dataOut = {
// expected output
};
_.isEqual(f(dataIn), dataOut);
Use the general data-oriented test pattern: prepare input and expected output, run the function, then compare the two values recursively. section 6.1
