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 <daniel.bevenius@gmail.com>
1 parent ec2037d commit f5054d3

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎lib/internal/errors.js‎

Lines changed: 6 additions & 9 deletions
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-
letbase='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+
constbase=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
constactualLines=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
letres=util.inspect(actual);

‎test/parallel/test-assert.js‎

Lines changed: 3 additions & 4 deletions
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
constdata=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)