Skip to content

Commit

Permalink
Additional test infra changes for toErrorDev rename (#17632)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Dec 17, 2019
1 parent 36a6e29 commit 0253ee9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions scripts/eslint-rules/no-to-warn-dev-within-to-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions scripts/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0253ee9

Please sign in to comment.