Skip to content

Commit 035bd30

Browse files
authored
fix(consistent-test-it): properly handle describe.each (#796)
Fixes #795
1 parent a431d07 commit 035bd30

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/rules/__tests__/consistent-test-it.test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TSESLint } from '@typescript-eslint/experimental-utils';
2+
import dedent from 'dedent';
23
import resolveFrom from 'resolve-from';
34
import rule from '../consistent-test-it';
45
import { TestCaseName } from '../utils';
@@ -172,6 +173,46 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
172173
},
173174
],
174175
},
176+
{
177+
code: 'describe.each``("foo", () => { test.each``("bar") })',
178+
output: 'describe.each``("foo", () => { it.each``("bar") })',
179+
options: [{ fn: TestCaseName.it }],
180+
errors: [
181+
{
182+
messageId: 'consistentMethodWithinDescribe',
183+
data: {
184+
testKeywordWithinDescribe: TestCaseName.it,
185+
oppositeTestKeyword: TestCaseName.test,
186+
},
187+
},
188+
],
189+
},
190+
{
191+
code: dedent`
192+
describe.each()("%s", () => {
193+
test("is valid, but should not be", () => {});
194+
195+
it("is not valid, but should be", () => {});
196+
});
197+
`,
198+
output: dedent`
199+
describe.each()("%s", () => {
200+
it("is valid, but should not be", () => {});
201+
202+
it("is not valid, but should be", () => {});
203+
});
204+
`,
205+
options: [{ fn: TestCaseName.test, withinDescribe: TestCaseName.it }],
206+
errors: [
207+
{
208+
messageId: 'consistentMethodWithinDescribe',
209+
data: {
210+
testKeywordWithinDescribe: TestCaseName.it,
211+
oppositeTestKeyword: TestCaseName.test,
212+
},
213+
},
214+
],
215+
},
175216
{
176217
code: 'describe("suite", () => { it("foo") })',
177218
output: 'describe("suite", () => { test("foo") })',

src/rules/consistent-test-it.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createRule,
99
getNodeName,
1010
isDescribe,
11+
isEachCall,
1112
isTestCase,
1213
} from './utils';
1314

@@ -120,7 +121,7 @@ export default createRule<
120121
}
121122
},
122123
'CallExpression:exit'(node) {
123-
if (isDescribe(node)) {
124+
if (isDescribe(node) && !isEachCall(node)) {
124125
describeNestingLevel--;
125126
}
126127
},

0 commit comments

Comments
 (0)