Skip to content
Permalink
Browse files
fix(consistent-test-it): properly handle describe.each (#796)
Fixes #795
  • Loading branch information
G-Rath committed Mar 16, 2021
1 parent a431d07 commit 035bd30af43f1215e65bf1b26c2ef2e6d174d3c8
Showing with 43 additions and 1 deletion.
  1. +41 −0 src/rules/__tests__/consistent-test-it.test.ts
  2. +2 −1 src/rules/consistent-test-it.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';
@@ -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") })',
@@ -8,6 +8,7 @@ import {
createRule,
getNodeName,
isDescribe,
isEachCall,
isTestCase,
} from './utils';

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

0 comments on commit 035bd30

Please sign in to comment.