@samitouri / QOS-React-2 / commits / 0253ee9a2e

Additional test infra changes for toErrorDev rename (#17632)

Dan Abramov committed Dec 17, 2019 at 13:31 UTC 0253ee9a2e94d43e220a997eeedfcc6847c4542b
2 files changed +18 -5
scripts/eslint-rules/no-to-warn-dev-within-to-throw.js
+5 -2
@@ -12,7 +12,7 @@
12 module.exports = function(context) {
13 return {
14 Identifier(node) {
15 - if (node.name === 'toWarnDev') {
15 + if (node.name === 'toWarnDev' || node.name === 'toErrorDev') {
16 let current = node;
17 while (current.parent) {
18 if (current.type === 'CallExpression') {
@@ -22,7 +22,10 @@ module.exports = function(context) {
22 current.callee.property &&
23 current.callee.property.name === 'toThrow'
24 ) {
25 - context.report(node, 'toWarnDev() matcher should not be nested');
25 + context.report(
26 + node,
27 + node.name + '() matcher should not be nested'
28 + );
29 }
30 }
31 current = current.parent;
scripts/jest/setupTests.js
+13 -3
@@ -108,14 +108,24 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
108 .join('\n')}`
109 );
110
111 + let expectedMatcher;
112 + switch (methodName) {
113 + case 'warn':
114 + expectedMatcher = 'toWarnDev';
115 + break;
116 + case 'error':
117 + expectedMatcher = 'toErrorDev';
118 + break;
119 + default:
120 + throw new Error('No matcher for ' + methodName);
121 + }
122 const message =
123 `Expected test not to call ${chalk.bold(
124 `console.${methodName}()`
125 )}.\n\n` +
126 'If the warning is expected, test for it explicitly by:\n' +
116 - `1. Using the ${chalk.bold('.toWarnDev()')} / ${chalk.bold(
117 - '.toLowPriorityWarnDev()'
118 - )} matchers, or...\n` +
127 + `1. Using the ${chalk.bold('.' + expectedMatcher + '()')} ` +
128 + `matcher, or...\n` +
129 `2. Mock it out using ${chalk.bold(
130 'spyOnDev'
131 )}(console, '${methodName}') or ${chalk.bold(