Skip to content

Commit b53917a

Browse files
committed
test(no-if): add cases for each()()
1 parent 88f896b commit b53917a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/rules/__tests__/no-if.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ ruleTester.run('conditional expressions', rule, {
2727
};
2828
});
2929
`,
30+
dedent`
31+
it.each()('foo', function () {
32+
const foo = function (bar) {
33+
return foo ? bar : null;
34+
};
35+
});
36+
`,
3037
],
3138
invalid: [
3239
{
@@ -120,6 +127,11 @@ ruleTester.run('switch statements', rule, {
120127
switch('bar') {}
121128
})
122129
`,
130+
dedent`
131+
describe.skip.each()('foo', () => {
132+
switch('bar') {}
133+
})
134+
`,
123135
dedent`
124136
xdescribe('foo', () => {
125137
switch('bar') {}
@@ -501,6 +513,13 @@ ruleTester.run('if statements', rule, {
501513
});
502514
})
503515
`,
516+
dedent`
517+
describe.each\`\`('foo', () => {
518+
afterEach(() => {
519+
if('bar') {}
520+
});
521+
})
522+
`,
504523
dedent`
505524
describe('foo', () => {
506525
beforeEach(() => {
@@ -826,6 +845,20 @@ ruleTester.run('if statements', rule, {
826845
},
827846
],
828847
},
848+
{
849+
code: dedent`
850+
it.each()('foo', () => {
851+
callExpression()
852+
if ('bar') {}
853+
})
854+
`,
855+
errors: [
856+
{
857+
data: { condition: 'if' },
858+
messageId: 'conditionalInTest',
859+
},
860+
],
861+
},
829862
{
830863
code: dedent`
831864
it.only.each\`\`('foo', () => {
@@ -840,6 +873,20 @@ ruleTester.run('if statements', rule, {
840873
},
841874
],
842875
},
876+
{
877+
code: dedent`
878+
it.only.each()('foo', () => {
879+
callExpression()
880+
if ('bar') {}
881+
})
882+
`,
883+
errors: [
884+
{
885+
data: { condition: 'if' },
886+
messageId: 'conditionalInTest',
887+
},
888+
],
889+
},
843890
{
844891
code: dedent`
845892
describe('valid', () => {

src/rules/no-if.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export default createRule({
7777
CallExpression(node) {
7878
if (isTestCaseCall(node)) {
7979
stack.push(true);
80+
81+
if (getNodeName(node).endsWith('each')) {
82+
stack.push(true);
83+
}
8084
}
8185
},
8286
FunctionExpression(node) {

0 commit comments

Comments
 (0)