Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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