Skip to content

Commit

Permalink
fix(consistent-test-it): support it.each in describe.each (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
idan-at authored and G-Rath committed Mar 7, 2021
1 parent 8f81e47 commit 0014da0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/rules/__tests__/consistent-test-it.test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 0014da0

Please sign in to comment.