Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(consistent-test-it): false positives inside describe.each #782

Merged
merged 1 commit into from Mar 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/rules/__tests__/consistent-test-it.test.ts
Expand Up @@ -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") })',
Expand Down Expand Up @@ -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")',
Expand Down
8 changes: 7 additions & 1 deletion src/rules/utils.ts
Expand Up @@ -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 &&
Expand All @@ -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 `<describe|test|it>.each(...)`.
Expand Down