An addition to Node's assertion library provides a paranoid (and enhanced) variant of deepEqual.
assertmodule with special Report object as the message. That object provides information about where the given objects are not equal and why.
Install it via Node Package Manager:
npm install assert-paranoid-equal
Then it can be used like so:
var enhancedAssert = require('assert-paranoid-equal'); enhancedAssert.paranoidEqual(42, 42); enhancedAssert.paranoidEqual(NaN, NaN); enhancedAssert.notParanoidEqual(null, undefined);
Look at the tests if you want more examples.
When the given objects are not equal at some point, paranoidEqual throws
AssertionError from Node's
assert module. It assigns
expected properties to the given top-level objects and
newly constructed Report object.
Report objects contain the following properties:
reason— Machine-friendly reason identifier. See the source code for details.
expected— Expected top-level object.
actual— Actual top-level object.
context— Special Context object. It contains:
path— Position (array of keys) within the object where the discrepancy was detected.
expected— Expected check value at the given path.
actual— Actual check value at the given path.
Also Report objects have
.toString() method, which returns
human-friendly description of the error.
assert-paranoid-equal is released under the MIT License.