From 9afb0e88fea7a3ddcbe6fd85d8dbae8d09f10844 Mon Sep 17 00:00:00 2001 From: Idan Attias Date: Sun, 7 Mar 2021 11:23:02 +0200 Subject: [PATCH] fix(consistent-test-it): false positives inside describe.each --- .../__tests__/consistent-test-it.test.ts | 28 +++++++++++++++++++ src/rules/utils.ts | 8 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/rules/__tests__/consistent-test-it.test.ts b/src/rules/__tests__/consistent-test-it.test.ts index 75afdeef6..fc228aef6 100644 --- a/src/rules/__tests__/consistent-test-it.test.ts +++ b/src/rules/__tests__/consistent-test-it.test.ts @@ -158,6 +158,20 @@ ruleTester.run('consistent-test-it with fn=test', rule, { }, ], }, + { + code: 'describe.each``("foo", () => { it.each``("bar") })', + output: 'describe.each``("foo", () => { test.each``("bar") })', + options: [{ fn: TestCaseName.test }], + errors: [ + { + messageId: 'consistentMethodWithinDescribe', + data: { + testKeywordWithinDescribe: TestCaseName.test, + oppositeTestKeyword: TestCaseName.it, + }, + }, + ], + }, { code: 'describe("suite", () => { it("foo") })', output: 'describe("suite", () => { test("foo") })', @@ -299,6 +313,20 @@ ruleTester.run('consistent-test-it with fn=it', 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: 'test.each``("foo")', output: 'it.each``("foo")', diff --git a/src/rules/utils.ts b/src/rules/utils.ts index 7d3f77ba2..77c4f0e93 100644 --- a/src/rules/utils.ts +++ b/src/rules/utils.ts @@ -663,6 +663,8 @@ export const isTestCase = ( // e.g. it.each``() (node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression && node.callee.tag.type === AST_NODE_TYPES.MemberExpression && + node.callee.tag.object.type === AST_NODE_TYPES.Identifier && + TestCaseName.hasOwnProperty(node.callee.tag.object.name) && isSupportedAccessor(node.callee.tag.property, TestCaseProperty.each)) || // e.g. it.concurrent.{skip,only} (node.callee.type === AST_NODE_TYPES.MemberExpression && @@ -683,7 +685,11 @@ export const isDescribe = ( node.callee.object.type === AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.object.name) && node.callee.property.type === AST_NODE_TYPES.Identifier && - DescribeProperty.hasOwnProperty(node.callee.property.name)); + DescribeProperty.hasOwnProperty(node.callee.property.name)) || + (node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression && + node.callee.tag.type === AST_NODE_TYPES.MemberExpression && + node.callee.tag.object.type === AST_NODE_TYPES.Identifier && + DescribeAlias.hasOwnProperty(node.callee.tag.object.name)); /** * Checks if the given node` is a call to `.each(...)`.