Closed
Description
I think it would be better if the message of assert.deepEqual
was not limited to a depth of 3, and could display the first difference between the objects, like some testing libraries do
const assert = require('assert');
assert.deepEqual({
foo: {
bar: {
qux: {
lolcat: {
bip: {
yup: 56
}
}
}
}
}
}, {
foo: {
bar: {
qux: {
lolcat: {
bip: {
yup: 56.3
}
}
}
}
}
})
// outputs:
// AssertionError [ERR_ASSERTION]: { foo: { bar: { qux: [Object] } } } deepEqual { foo: { bar: { qux: [Object] } } }
A simple implementation example:
const deepEq = (o1, o2) => {
const keys1 = Object.keys(o1);
const keys2 = Object.keys(o2);
if (keys1.length !== keys2.length) {
assert.deepEqual(o1, o2);
}
for (let i=0; i<keys1.length; i++) {
const v1 = o1[keys1[i]], v2 = o2[keys1[i]];
if (v1 && typeof v1 === 'object') {
deepEq(v1, v2);
} else {
assert.equal(v1, v2);
}
}
};
The current implementation passes the entire objects in the Error, and .toString is limited in 3 in depth I guess