mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
assert: fix the string length check for printing the simple diff
PR-URL: https://github.com/nodejs/node/pull/55474 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
@@ -134,7 +134,14 @@ function getStackedDiff(actual, expected) {
|
||||
}
|
||||
|
||||
function getSimpleDiff(originalActual, actual, originalExpected, expected) {
|
||||
const stringsLen = actual.length + expected.length;
|
||||
let stringsLen = actual.length + expected.length;
|
||||
// Accounting for the quotes wrapping strings
|
||||
if (typeof originalActual === 'string') {
|
||||
stringsLen -= 2;
|
||||
}
|
||||
if (typeof originalExpected === 'string') {
|
||||
stringsLen -= 2;
|
||||
}
|
||||
if (stringsLen <= kMaxShortStringLength && (originalActual !== 0 || originalExpected !== 0)) {
|
||||
return { message: `${actual} !== ${expected}`, header: '' };
|
||||
}
|
||||
|
||||
@@ -846,6 +846,26 @@ test('Additional tests', () => {
|
||||
}
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => assert.strictEqual('apple', 'pear'),
|
||||
{
|
||||
name: 'AssertionError',
|
||||
message: 'Expected values to be strictly equal:\n\n\'apple\' !== \'pear\'\n'
|
||||
}
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => assert.strictEqual('ABABABABABAB', 'BABABABABABA'),
|
||||
{
|
||||
name: 'AssertionError',
|
||||
message: 'Expected values to be strictly equal:\n' +
|
||||
'+ actual - expected\n' +
|
||||
'\n' +
|
||||
"+ 'ABABABABABAB'\n" +
|
||||
"- 'BABABABABABA'\n"
|
||||
}
|
||||
);
|
||||
|
||||
assert.notDeepStrictEqual(new Date(), new Date(2000, 3, 14));
|
||||
|
||||
assert.throws(
|
||||
|
||||
@@ -919,11 +919,7 @@ test('Additional asserts', () => {
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
constructor: assert.AssertionError,
|
||||
message: 'Expected values to be strictly equal:\n' +
|
||||
'+ actual - expected\n' +
|
||||
'\n' +
|
||||
"+ 'string'\n" +
|
||||
'- false\n'
|
||||
message: 'Expected values to be strictly equal:\n\n\'string\' !== false\n'
|
||||
}
|
||||
);
|
||||
|
||||
@@ -935,11 +931,7 @@ test('Additional asserts', () => {
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
constructor: assert.AssertionError,
|
||||
message: 'Expected values to be strictly equal:\n' +
|
||||
'+ actual - expected\n' +
|
||||
'\n' +
|
||||
"+ 'string'\n" +
|
||||
'- false\n'
|
||||
message: 'Expected values to be strictly equal:\n\n\'string\' !== false\n'
|
||||
}
|
||||
);
|
||||
|
||||
@@ -951,11 +943,7 @@ test('Additional asserts', () => {
|
||||
}, {
|
||||
code: 'ERR_ASSERTION',
|
||||
constructor: assert.AssertionError,
|
||||
message: 'Expected values to be strictly equal:\n' +
|
||||
'+ actual - expected\n' +
|
||||
'\n' +
|
||||
"+ 'string'\n" +
|
||||
'- false\n'
|
||||
message: 'Expected values to be strictly equal:\n\n\'string\' !== false\n'
|
||||
}
|
||||
);
|
||||
/* eslint-enable @stylistic/js/indent */
|
||||
|
||||
Reference in New Issue
Block a user