Workaround jest-diff single line string limitation (#12456)
Brian Vaughn committed
Mar 26, 2018 at 10:48 UTC
e9ba8ec8663071ebe9467c13576b3c18ad4e1b58
1 file changed
+9
-2
scripts/jest/matchers/toWarnDev.js
+9
-2
@@ -2,6 +2,13 @@
2
3
const jestDiff = require('jest-diff');
4
5
+function diffString(a, b) {
6
+ // jest-diff does not currently handle single line strings correctly
7
+ // The easiest work around is to ensure that both strings are multiline
8
+ // https://github.com/facebook/jest/issues/5657
9
+ return jestDiff(a + '\n', b + '\n');
10
+}
11
+
12
function normalizeCodeLocInfo(str) {
13
return str && str.replace(/at .+?:\d+/g, 'at **');
14
}
@@ -49,11 +56,11 @@ const createMatcherFor = consoleMethod =>
56
} else if (expectedMessages.length === 1) {
57
errorMessage =
58
'Unexpected warning recorded: ' +
52
- jestDiff(normalizedMessage, expectedMessages[0]);
59
+ diffString(normalizedMessage, expectedMessages[0]);
60
} else {
61
errorMessage =
62
'Unexpected warning recorded: ' +
56
- jestDiff([normalizedMessage], expectedMessages);
63
+ diffString([normalizedMessage], expectedMessages);
64
}
65
66
// Record the call stack for unexpected warnings.