Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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