Navigation Menu

Skip to content

Commit

Permalink
fix(consistent-test-it): properly handle describe.each (#796)
Browse files Browse the repository at this point in the history
Fixes #795
  • Loading branch information
G-Rath committed Mar 16, 2021
1 parent a431d07 commit 035bd30
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/rules/__tests__/consistent-test-it.test.ts
@@ -1,4 +1,5 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';
import dedent from 'dedent';
import resolveFrom from 'resolve-from';
import rule from '../consistent-test-it';
import { TestCaseName } from '../utils';
Expand Down Expand Up @@ -172,6 +173,46 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
},
],
},
{
code: 'describe.each``("foo", () => { test.each``("bar") })',
output: 'describe.each``("foo", () => { it.each``("bar") })',
options: [{ fn: TestCaseName.it }],
errors: [
{
messageId: 'consistentMethodWithinDescribe',
data: {
testKeywordWithinDescribe: TestCaseName.it,
oppositeTestKeyword: TestCaseName.test,
},
},
],
},
{
code: dedent`
describe.each()("%s", () => {
test("is valid, but should not be", () => {});
it("is not valid, but should be", () => {});
});
`,
output: dedent`
describe.each()("%s", () => {
it("is valid, but should not be", () => {});
it("is not valid, but should be", () => {});
});
`,
options: [{ fn: TestCaseName.test, withinDescribe: TestCaseName.it }],
errors: [
{
messageId: 'consistentMethodWithinDescribe',
data: {
testKeywordWithinDescribe: TestCaseName.it,
oppositeTestKeyword: TestCaseName.test,
},
},
],
},
{
code: 'describe("suite", () => { it("foo") })',
output: 'describe("suite", () => { test("foo") })',
Expand Down
3 changes: 2 additions & 1 deletion src/rules/consistent-test-it.ts
Expand Up @@ -8,6 +8,7 @@ import {
createRule,
getNodeName,
isDescribe,
isEachCall,
isTestCase,
} from './utils';

Expand Down Expand Up @@ -120,7 +121,7 @@ export default createRule<
}
},
'CallExpression:exit'(node) {
if (isDescribe(node)) {
if (isDescribe(node) && !isEachCall(node)) {
describeNestingLevel--;
}
},
Expand Down

0 comments on commit 035bd30

Please sign in to comment.