Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/rules/__tests__/consistent-test-it.test.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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