Additional test infra changes for toErrorDev rename (#17632)

This commit is contained in:
Dan Abramov 2019-12-17 13:31:47 +00:00 committed by GitHub
parent 36a6e29bb3
commit 0253ee9a2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -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;

View File

@ -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(