Skip to content

Commit

Permalink
fix(no-if): support each()()
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 11, 2021
1 parent 88f896b commit ac5872e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/rules/__tests__/no-if.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ ruleTester.run('conditional expressions', rule, {
};
});
`,
dedent`
it.each()('foo', function () {
const foo = function (bar) {
return foo ? bar : null;
};
});
`,
],
invalid: [
{
Expand Down Expand Up @@ -120,6 +127,11 @@ ruleTester.run('switch statements', rule, {
switch('bar') {}
})
`,
dedent`
describe.skip.each()('foo', () => {
switch('bar') {}
})
`,
dedent`
xdescribe('foo', () => {
switch('bar') {}
Expand Down Expand Up @@ -501,6 +513,13 @@ ruleTester.run('if statements', rule, {
});
})
`,
dedent`
describe.each\`\`('foo', () => {
afterEach(() => {
if('bar') {}
});
})
`,
dedent`
describe('foo', () => {
beforeEach(() => {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/rules/no-if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ac5872e

Please sign in to comment.