Skip to content

Commit 254f888

Browse files
committed
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: nodejs#18611 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent ca8a591 commit 254f888

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/internal/errors.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ function createErrDiff(actual, expected, operator) {
9090
var skipped = false;
9191
const util = lazyUtil();
9292
const actualLines = util
93-
.inspect(actual, { compact: false }).split('\n');
93+
.inspect(actual, { compact: false, customInspect: false }).split('\n');
9494
const expectedLines = util
95-
.inspect(expected, { compact: false }).split('\n');
95+
.inspect(expected, { compact: false, customInspect: false }).split('\n');
9696
const msg = `Input A expected to ${operator} input B:\n` +
9797
`${green}+ expected${white} ${red}- actual${white}`;
9898
const skippedMsg = ' ... Lines skipped';
@@ -235,8 +235,10 @@ class AssertionError extends Error {
235235
} else if (errorDiff === 1) {
236236
// In case the objects are equal but the operator requires unequal, show
237237
// the first object and say A equals B
238-
const res = util
239-
.inspect(actual, { compact: false }).split('\n');
238+
const res = util.inspect(
239+
actual,
240+
{ compact: false, customInspect: false }
241+
).split('\n');
240242

241243
if (res.length > 20) {
242244
res[19] = '...';

test/parallel/test-assert.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,11 @@ common.expectsError(
899899
message: `${start}\n` +
900900
`${actExp}\n` +
901901
'\n' +
902-
' {}'
902+
`${minus} {}\n` +
903+
`${plus} {\n` +
904+
`${plus} loop: 'forever',\n` +
905+
`${plus} [Symbol(util.inspect.custom)]: [Function]\n` +
906+
`${plus} }`
903907
});
904908

905909
// notDeepEqual tests

0 commit comments

Comments
 (0)