Skip to content

Commit

Permalink
fix(require-top-level-describe): handle describe.each properly (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Feb 16, 2021
1 parent 3d847b2 commit 677be45
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
35 changes: 33 additions & 2 deletions src/rules/__tests__/require-top-level-describe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ ruleTester.run('require-top-level-describe', rule, {
'describe("test suite", () => { it("my test") });',
dedent`
describe("test suite", () => {
beforeEach("a", () => {});
describe("b", () => {});
beforeEach("a", () => {});
describe("b", () => {});
test("c", () => {})
});
`,
Expand All @@ -33,6 +33,33 @@ ruleTester.run('require-top-level-describe', rule, {
});
`,
'foo()',
'describe.each([1, true])("trues", value => { it("an it", () => expect(value).toBe(true) ); });',
dedent`
describe('%s', () => {
it('is fine', () => {
//
});
});
describe.each('world')('%s', () => {
it.each([1, 2, 3])('%n', () => {
//
});
});
`,
dedent`
describe.each('hello')('%s', () => {
it('is fine', () => {
//
});
});
describe.each('world')('%s', () => {
it.each([1, 2, 3])('%n', () => {
//
});
});
`,
],
invalid: [
{
Expand Down Expand Up @@ -62,5 +89,9 @@ ruleTester.run('require-top-level-describe', rule, {
`,
errors: [{ messageId: 'unexpectedHook' }],
},
{
code: "it.each([1, 2, 3])('%n', () => {});",
errors: [{ messageId: 'unexpectedTestCase' }],
},
],
});
10 changes: 8 additions & 2 deletions src/rules/require-top-level-describe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { createRule, isDescribe, isHook, isTestCase } from './utils';
import {
createRule,
isDescribe,
isDescribeEach,
isHook,
isTestCase,
} from './utils';

export default createRule({
name: __filename,
Expand Down Expand Up @@ -44,7 +50,7 @@ export default createRule({
}
},
'CallExpression:exit'(node: TSESTree.CallExpression) {
if (isDescribe(node)) {
if (isDescribe(node) && !isDescribeEach(node)) {
numberOfDescribeBlocks--;
}
},
Expand Down

0 comments on commit 677be45

Please sign in to comment.