chore: output both received value and diff for string expected results (#1287)

This commit is contained in:
Andrey Lushnikov 2020-03-07 17:29:41 -08:00 committed by GitHub
parent c881248062
commit 3dc48f96c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,11 +83,12 @@ function stringFormatter(received, expected) {
}).join('');
const output = [
`Expected: ${expected}`,
`Received: ${highlighted}`,
`Received: ${received}`,
` Diff: ${highlighted}`,
];
for (let i = 0; i < Math.min(expected.length, received.length); ++i) {
if (expected[i] !== received[i]) {
const padding = ' '.repeat('Expected: '.length);
const padding = ' '.repeat(' Diff: '.length);
const firstDiffCharacter = '~'.repeat(i) + '^';
output.push(colors.red(padding + firstDiffCharacter));
break;