A data-manipulating function can be tested without mocks: prepare input, calculate the expected output, and compare both nested data structures field by field. Recursive comparison handles maps and arrays without requiring hand-written recursion. section 6.1
Use the recurring test pattern:
- Generate data input. section 6.6
- Generate expected data output. section 6.6
- Compare f(dataIn) with dataOut using a generic recursive comparator such as Lodash's _.isEqual. section 6.1 section 6.6
Equal and non-equal collections
Comparing two collections with the same name and ISBN array returns true; changing the ISBN to "bad-isbn" returns false. The same approach supports positive and negative test cases. section 6.1 section 6.6
Listing 6.1 Comparing an equal data collection recursively
_.isEqual({
"name": "Alan Moore",
"bookIsbns": ["978-1779501127"]
}, {
"name": "Alan Moore",
"bookIsbns": ["978-1779501127"]
});
// → true
Inspect a concrete _.isEqual call comparing nested map and array values. section 6.1
