liveBook · Manning

_.isEqual

As explained in Data-Oriented Programming: Reduce software complexity

_.isEqual is a Lodash function that recursively compares JavaScript values for deep structural equality.

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

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Explains recursive value comparison and demonstrates equal and non-equal collections, without covering test runners or framework mechanics.
Examples
Uses author records, ISBN arrays, Catalog.authorNames outputs, empty inputs, and missing author identifiers.
What it assumes
Assumes JavaScript data collections and functions, while teaching recursive comparison without requiring handwritten recursion.
What you can do after
Apply it via Lodash to write concise unit tests for functions that transform nested data.
How it connects
Connects deep structural equality with Lodash, JavaScript arrays, maps, data-oriented programming, and unit testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.