From 0253ee9a2e94d43e220a997eeedfcc6847c4542b Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 17 Dec 2019 13:31:47 +0000 Subject: [PATCH] Additional test infra changes for toErrorDev rename (#17632) --- .../no-to-warn-dev-within-to-throw.js | 7 +++++-- scripts/jest/setupTests.js | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/eslint-rules/no-to-warn-dev-within-to-throw.js b/scripts/eslint-rules/no-to-warn-dev-within-to-throw.js index 032a1b7c56..ff83f4e1bc 100644 --- a/scripts/eslint-rules/no-to-warn-dev-within-to-throw.js +++ b/scripts/eslint-rules/no-to-warn-dev-within-to-throw.js @@ -12,7 +12,7 @@ module.exports = function(context) { return { Identifier(node) { - if (node.name === 'toWarnDev') { + if (node.name === 'toWarnDev' || node.name === 'toErrorDev') { let current = node; while (current.parent) { if (current.type === 'CallExpression') { @@ -22,7 +22,10 @@ module.exports = function(context) { current.callee.property && current.callee.property.name === 'toThrow' ) { - context.report(node, 'toWarnDev() matcher should not be nested'); + context.report( + node, + node.name + '() matcher should not be nested' + ); } } current = current.parent; diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index 330cf65c0f..8a33db5af2 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -108,14 +108,24 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { .join('\n')}` ); + let expectedMatcher; + switch (methodName) { + case 'warn': + expectedMatcher = 'toWarnDev'; + break; + case 'error': + expectedMatcher = 'toErrorDev'; + break; + default: + throw new Error('No matcher for ' + methodName); + } const message = `Expected test not to call ${chalk.bold( `console.${methodName}()` )}.\n\n` + 'If the warning is expected, test for it explicitly by:\n' + - `1. Using the ${chalk.bold('.toWarnDev()')} / ${chalk.bold( - '.toLowPriorityWarnDev()' - )} matchers, or...\n` + + `1. Using the ${chalk.bold('.' + expectedMatcher + '()')} ` + + `matcher, or...\n` + `2. Mock it out using ${chalk.bold( 'spyOnDev' )}(console, '${methodName}') or ${chalk.bold(