assert: show proper differences
Right now it is possible to get an AssertionError from input that has the customInspect function set to always return the same value. That way the error message is actually misleading because the output is going to look the same. This fixes it by deactivating the custom inspect function. PR-URL: https://github.com/nodejs/node/pull/18611 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
656a5d042d
commit
0cdc87778e
@ -164,9 +164,9 @@ function createErrDiff(actual, expected, operator) {
|
|||||||
var skipped = false;
|
var skipped = false;
|
||||||
const util = lazyUtil();
|
const util = lazyUtil();
|
||||||
const actualLines = util
|
const actualLines = util
|
||||||
.inspect(actual, { compact: false }).split('\n');
|
.inspect(actual, { compact: false, customInspect: false }).split('\n');
|
||||||
const expectedLines = util
|
const expectedLines = util
|
||||||
.inspect(expected, { compact: false }).split('\n');
|
.inspect(expected, { compact: false, customInspect: false }).split('\n');
|
||||||
const msg = `Input A expected to ${operator} input B:\n` +
|
const msg = `Input A expected to ${operator} input B:\n` +
|
||||||
`${green}+ expected${white} ${red}- actual${white}`;
|
`${green}+ expected${white} ${red}- actual${white}`;
|
||||||
const skippedMsg = ' ... Lines skipped';
|
const skippedMsg = ' ... Lines skipped';
|
||||||
@ -310,8 +310,10 @@ class AssertionError extends Error {
|
|||||||
} else if (errorDiff === 1) {
|
} else if (errorDiff === 1) {
|
||||||
// In case the objects are equal but the operator requires unequal, show
|
// In case the objects are equal but the operator requires unequal, show
|
||||||
// the first object and say A equals B
|
// the first object and say A equals B
|
||||||
const res = util
|
const res = util.inspect(
|
||||||
.inspect(actual, { compact: false }).split('\n');
|
actual,
|
||||||
|
{ compact: false, customInspect: false }
|
||||||
|
).split('\n');
|
||||||
|
|
||||||
if (res.length > 20) {
|
if (res.length > 20) {
|
||||||
res[19] = '...';
|
res[19] = '...';
|
||||||
|
@ -574,7 +574,11 @@ common.expectsError(
|
|||||||
message: `${start}\n` +
|
message: `${start}\n` +
|
||||||
`${actExp}\n` +
|
`${actExp}\n` +
|
||||||
'\n' +
|
'\n' +
|
||||||
' {}'
|
`${minus} {}\n` +
|
||||||
|
`${plus} {\n` +
|
||||||
|
`${plus} loop: 'forever',\n` +
|
||||||
|
`${plus} [Symbol(util.inspect.custom)]: [Function]\n` +
|
||||||
|
`${plus} }`
|
||||||
});
|
});
|
||||||
|
|
||||||
// notDeepEqual tests
|
// notDeepEqual tests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user