diff --git a/scripts/jest/matchers/toWarnDev.js b/scripts/jest/matchers/toWarnDev.js index fcffae5a80c9..b4a52d1905f2 100644 --- a/scripts/jest/matchers/toWarnDev.js +++ b/scripts/jest/matchers/toWarnDev.js @@ -70,6 +70,12 @@ const createMatcherFor = consoleMethod => // Restore the unspied method so that unexpected errors fail tests. console[consoleMethod] = originalMethod; + // Any unexpected Errors thrown by the callback should fail the test. + // This should take precedence since unexpected errors could block warnings. + if (caughtError) { + throw caughtError; + } + // Any unexpected warnings should be treated as a failure. if (unexpectedWarnings.length > 0) { return { @@ -89,11 +95,6 @@ const createMatcherFor = consoleMethod => }; } - // Any unexpected Errors thrown by the callback should fail the test. - if (caughtError) { - throw caughtError; - } - return {pass: true}; } } else {