Skip to content

Commit f5054d3

Browse files
BridgeARMylesBorins
authored andcommitted
assert: minor error message improvements
Adjust indentations and fix a typo. PR-URL: #20315 Reviewed-By: Daniel Bevenius <[email protected]>
1 parent ec2037d commit f5054d3

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

lib/internal/errors.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,10 @@ function createErrDiff(actual, expected, operator) {
360360

361361
// Strict equal with identical objects that are not identical by reference.
362362
if (identical === maxLines) {
363-
let base = 'Input object identical but not reference equal:';
364-
365-
if (operator !== 'strictEqual') {
366-
// This code path should not be possible to reach.
367-
// The output is identical but it is not clear why.
368-
base = 'Input objects not identical:';
369-
}
363+
// E.g., assert.deepStrictEqual(Symbol(), Symbol())
364+
const base = operator === 'strictEqual' ?
365+
'Input objects identical but not reference equal:' :
366+
'Input objects not identical:';
370367

371368
// We have to get the result again. The lines were all removed before.
372369
const actualLines = inspectValue(actual);
@@ -380,7 +377,7 @@ function createErrDiff(actual, expected, operator) {
380377
}
381378
}
382379

383-
return `${base}\n\n ${actualLines.join('\n ')}\n`;
380+
return `${base}\n\n${actualLines.join('\n')}\n`;
384381
}
385382
return `${msg}${skipped ? skippedMsg : ''}\n${res}${other}${end}`;
386383
}
@@ -448,7 +445,7 @@ class AssertionError extends Error {
448445
if (res.length === 1) {
449446
super(`${base} ${res[0]}`);
450447
} else {
451-
super(`${base}\n\n ${res.join('\n ')}\n`);
448+
super(`${base}\n\n${res.join('\n')}\n`);
452449
}
453450
} else {
454451
let res = util.inspect(actual);

test/parallel/test-assert.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,13 @@ assert.throws(
599599
});
600600

601601
// notDeepEqual tests
602-
message = 'Identical input passed to notDeepStrictEqual:\n\n' +
603-
' [\n 1\n ]\n';
602+
message = 'Identical input passed to notDeepStrictEqual:\n\n[\n 1\n]\n';
604603
assert.throws(
605604
() => assert.notDeepEqual([1], [1]),
606605
{ message });
607606

608607
message = 'Identical input passed to notDeepStrictEqual:' +
609-
`\n\n [${'\n 1,'.repeat(25)}\n ...\n`;
608+
`\n\n[${'\n 1,'.repeat(25)}\n...\n`;
610609
const data = Array(31).fill(1);
611610
assert.throws(
612611
() => assert.notDeepEqual(data, data),
@@ -901,7 +900,7 @@ assert.throws(() => { throw null; }, 'foo');
901900
assert.throws(
902901
() => assert.strictEqual([], []),
903902
{
904-
message: 'Input object identical but not reference equal:\n\n []\n'
903+
message: 'Input objects identical but not reference equal:\n\n[]\n'
905904
}
906905
);
907906

0 commit comments

Comments
 (0)