Skip to content

Commit 0014da0

Browse files
idan-atG-Rath
authored andcommittedMar 7, 2021
fix(consistent-test-it): support it.each in describe.each (#782)
1 parent 8f81e47 commit 0014da0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
 

‎src/rules/__tests__/consistent-test-it.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
158158
},
159159
],
160160
},
161+
{
162+
code: 'describe.each``("foo", () => { it.each``("bar") })',
163+
output: 'describe.each``("foo", () => { test.each``("bar") })',
164+
options: [{ fn: TestCaseName.test }],
165+
errors: [
166+
{
167+
messageId: 'consistentMethodWithinDescribe',
168+
data: {
169+
testKeywordWithinDescribe: TestCaseName.test,
170+
oppositeTestKeyword: TestCaseName.it,
171+
},
172+
},
173+
],
174+
},
161175
{
162176
code: 'describe("suite", () => { it("foo") })',
163177
output: 'describe("suite", () => { test("foo") })',
@@ -299,6 +313,20 @@ ruleTester.run('consistent-test-it with fn=it', rule, {
299313
},
300314
],
301315
},
316+
{
317+
code: 'describe.each``("foo", () => { test.each``("bar") })',
318+
output: 'describe.each``("foo", () => { it.each``("bar") })',
319+
options: [{ fn: TestCaseName.it }],
320+
errors: [
321+
{
322+
messageId: 'consistentMethodWithinDescribe',
323+
data: {
324+
testKeywordWithinDescribe: TestCaseName.it,
325+
oppositeTestKeyword: TestCaseName.test,
326+
},
327+
},
328+
],
329+
},
302330
{
303331
code: 'test.each``("foo")',
304332
output: 'it.each``("foo")',

‎src/rules/utils.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,8 @@ export const isTestCase = (
663663
// e.g. it.each``()
664664
(node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression &&
665665
node.callee.tag.type === AST_NODE_TYPES.MemberExpression &&
666+
node.callee.tag.object.type === AST_NODE_TYPES.Identifier &&
667+
TestCaseName.hasOwnProperty(node.callee.tag.object.name) &&
666668
isSupportedAccessor(node.callee.tag.property, TestCaseProperty.each)) ||
667669
// e.g. it.concurrent.{skip,only}
668670
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
@@ -683,7 +685,11 @@ export const isDescribe = (
683685
node.callee.object.type === AST_NODE_TYPES.Identifier &&
684686
DescribeAlias.hasOwnProperty(node.callee.object.name) &&
685687
node.callee.property.type === AST_NODE_TYPES.Identifier &&
686-
DescribeProperty.hasOwnProperty(node.callee.property.name));
688+
DescribeProperty.hasOwnProperty(node.callee.property.name)) ||
689+
(node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression &&
690+
node.callee.tag.type === AST_NODE_TYPES.MemberExpression &&
691+
node.callee.tag.object.type === AST_NODE_TYPES.Identifier &&
692+
DescribeAlias.hasOwnProperty(node.callee.tag.object.name));
687693

688694
/**
689695
* Checks if the given node` is a call to `<describe|test|it>.each(...)`.

0 commit comments

Comments
 (0)
Please sign in to comment.