Workaround jest-diff single line string limitation (#12456)

This commit is contained in:
Brian Vaughn 2018-03-26 10:48:36 -07:00 committed by GitHub
parent dadafd6bd8
commit e9ba8ec866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -2,6 +2,13 @@
const jestDiff = require('jest-diff');
function diffString(a, b) {
// jest-diff does not currently handle single line strings correctly
// The easiest work around is to ensure that both strings are multiline
// https://github.com/facebook/jest/issues/5657
return jestDiff(a + '\n', b + '\n');
}
function normalizeCodeLocInfo(str) {
return str && str.replace(/at .+?:\d+/g, 'at **');
}
@ -49,11 +56,11 @@ const createMatcherFor = consoleMethod =>
} else if (expectedMessages.length === 1) {
errorMessage =
'Unexpected warning recorded: ' +
jestDiff(normalizedMessage, expectedMessages[0]);
diffString(normalizedMessage, expectedMessages[0]);
} else {
errorMessage =
'Unexpected warning recorded: ' +
jestDiff([normalizedMessage], expectedMessages);
diffString([normalizedMessage], expectedMessages);
}
// Record the call stack for unexpected warnings.