Skip to content

Commit

Permalink
Workaround jest-diff single line string limitation (facebook#12456)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn authored and rhagigi committed Apr 19, 2018
1 parent 96557bc commit f273ac4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/jest/matchers/toWarnDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 **');
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f273ac4

Please sign in to comment.