diff --git a/src/rules/__tests__/no-if.test.ts b/src/rules/__tests__/no-if.test.ts index d6554638e..f890baac7 100644 --- a/src/rules/__tests__/no-if.test.ts +++ b/src/rules/__tests__/no-if.test.ts @@ -27,6 +27,13 @@ ruleTester.run('conditional expressions', rule, { }; }); `, + dedent` + it.each()('foo', function () { + const foo = function (bar) { + return foo ? bar : null; + }; + }); + `, ], invalid: [ { @@ -120,6 +127,11 @@ ruleTester.run('switch statements', rule, { switch('bar') {} }) `, + dedent` + describe.skip.each()('foo', () => { + switch('bar') {} + }) + `, dedent` xdescribe('foo', () => { switch('bar') {} @@ -501,6 +513,13 @@ ruleTester.run('if statements', rule, { }); }) `, + dedent` + describe.each\`\`('foo', () => { + afterEach(() => { + if('bar') {} + }); + }) + `, dedent` describe('foo', () => { beforeEach(() => { @@ -826,6 +845,20 @@ ruleTester.run('if statements', rule, { }, ], }, + { + code: dedent` + it.each()('foo', () => { + callExpression() + if ('bar') {} + }) + `, + errors: [ + { + data: { condition: 'if' }, + messageId: 'conditionalInTest', + }, + ], + }, { code: dedent` it.only.each\`\`('foo', () => { @@ -840,6 +873,20 @@ ruleTester.run('if statements', rule, { }, ], }, + { + code: dedent` + it.only.each()('foo', () => { + callExpression() + if ('bar') {} + }) + `, + errors: [ + { + data: { condition: 'if' }, + messageId: 'conditionalInTest', + }, + ], + }, { code: dedent` describe('valid', () => { diff --git a/src/rules/no-if.ts b/src/rules/no-if.ts index f8ba2f236..0203d4953 100644 --- a/src/rules/no-if.ts +++ b/src/rules/no-if.ts @@ -77,6 +77,10 @@ export default createRule({ CallExpression(node) { if (isTestCaseCall(node)) { stack.push(true); + + if (getNodeName(node).endsWith('each')) { + stack.push(true); + } } }, FunctionExpression(node) {