assert: minor error message improvements
Adjust indentations and fix a typo. PR-URL: https://github.com/nodejs/node/pull/20315 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
parent
564048dc29
commit
f0a6cb0593
@ -360,13 +360,10 @@ function createErrDiff(actual, expected, operator) {
|
|||||||
|
|
||||||
// Strict equal with identical objects that are not identical by reference.
|
// Strict equal with identical objects that are not identical by reference.
|
||||||
if (identical === maxLines) {
|
if (identical === maxLines) {
|
||||||
let base = 'Input object identical but not reference equal:';
|
// E.g., assert.deepStrictEqual(Symbol(), Symbol())
|
||||||
|
const base = operator === 'strictEqual' ?
|
||||||
if (operator !== 'strictEqual') {
|
'Input objects identical but not reference equal:' :
|
||||||
// This code path should not be possible to reach.
|
'Input objects not identical:';
|
||||||
// The output is identical but it is not clear why.
|
|
||||||
base = 'Input objects not identical:';
|
|
||||||
}
|
|
||||||
|
|
||||||
// We have to get the result again. The lines were all removed before.
|
// We have to get the result again. The lines were all removed before.
|
||||||
const actualLines = inspectValue(actual);
|
const actualLines = inspectValue(actual);
|
||||||
@ -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}`;
|
return `${msg}${skipped ? skippedMsg : ''}\n${res}${other}${end}`;
|
||||||
}
|
}
|
||||||
@ -448,7 +445,7 @@ class AssertionError extends Error {
|
|||||||
if (res.length === 1) {
|
if (res.length === 1) {
|
||||||
super(`${base} ${res[0]}`);
|
super(`${base} ${res[0]}`);
|
||||||
} else {
|
} else {
|
||||||
super(`${base}\n\n ${res.join('\n ')}\n`);
|
super(`${base}\n\n${res.join('\n')}\n`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let res = util.inspect(actual);
|
let res = util.inspect(actual);
|
||||||
|
@ -599,14 +599,13 @@ assert.throws(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// notDeepEqual tests
|
// notDeepEqual tests
|
||||||
message = 'Identical input passed to notDeepStrictEqual:\n\n' +
|
message = 'Identical input passed to notDeepStrictEqual:\n\n[\n 1\n]\n';
|
||||||
' [\n 1\n ]\n';
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => assert.notDeepEqual([1], [1]),
|
() => assert.notDeepEqual([1], [1]),
|
||||||
{ message });
|
{ message });
|
||||||
|
|
||||||
message = 'Identical input passed to notDeepStrictEqual:' +
|
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);
|
const data = Array(31).fill(1);
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => assert.notDeepEqual(data, data),
|
() => assert.notDeepEqual(data, data),
|
||||||
@ -901,7 +900,7 @@ assert.throws(() => { throw null; }, 'foo');
|
|||||||
assert.throws(
|
assert.throws(
|
||||||
() => assert.strictEqual([], []),
|
() => assert.strictEqual([], []),
|
||||||
{
|
{
|
||||||
message: 'Input object identical but not reference equal:\n\n []\n'
|
message: 'Input objects identical but not reference equal:\n\n[]\n'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user