diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index ee376899d04d35..dd56811647e5bf 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -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: '' }; } diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index aeacd21a21f029..93cc248160e6a1 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -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( diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 4a6420779a845e..e639e7f150a5df 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -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 */