Skip to content

Commit

Permalink
assert: minor error message improvements
Browse files Browse the repository at this point in the history
Adjust indentations and fix a typo.

PR-URL: #20315
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed May 4, 2018
1 parent ec2037d commit f5054d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
15 changes: 6 additions & 9 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,10 @@ function createErrDiff(actual, expected, operator) {

// Strict equal with identical objects that are not identical by reference.
if (identical === maxLines) {
let base = 'Input object identical but not reference equal:';

if (operator !== 'strictEqual') {
// This code path should not be possible to reach.
// The output is identical but it is not clear why.
base = 'Input objects not identical:';
}
// E.g., assert.deepStrictEqual(Symbol(), Symbol())
const base = operator === 'strictEqual' ?
'Input objects identical but not reference equal:' :
'Input objects not identical:';

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

return `${base}\n\n ${actualLines.join('\n ')}\n`;
return `${base}\n\n${actualLines.join('\n')}\n`;
}
return `${msg}${skipped ? skippedMsg : ''}\n${res}${other}${end}`;
}
Expand Down Expand Up @@ -448,7 +445,7 @@ class AssertionError extends Error {
if (res.length === 1) {
super(`${base} ${res[0]}`);
} else {
super(`${base}\n\n ${res.join('\n ')}\n`);
super(`${base}\n\n${res.join('\n')}\n`);
}
} else {
let res = util.inspect(actual);
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,13 @@ assert.throws(
});

// notDeepEqual tests
message = 'Identical input passed to notDeepStrictEqual:\n\n' +
' [\n 1\n ]\n';
message = 'Identical input passed to notDeepStrictEqual:\n\n[\n 1\n]\n';
assert.throws(
() => assert.notDeepEqual([1], [1]),
{ message });

message = 'Identical input passed to notDeepStrictEqual:' +
`\n\n [${'\n 1,'.repeat(25)}\n ...\n`;
`\n\n[${'\n 1,'.repeat(25)}\n...\n`;
const data = Array(31).fill(1);
assert.throws(
() => assert.notDeepEqual(data, data),
Expand Down Expand Up @@ -901,7 +900,7 @@ assert.throws(() => { throw null; }, 'foo');
assert.throws(
() => assert.strictEqual([], []),
{
message: 'Input object identical but not reference equal:\n\n []\n'
message: 'Input objects identical but not reference equal:\n\n[]\n'
}
);

Expand Down

0 comments on commit f5054d3

Please sign in to comment.