Skip to content

Commit

Permalink
fix(no-focused-tests): support .each template strings (#420)
Browse files Browse the repository at this point in the history
* fix(no-focused-tests)-support-template-strings

* chore(lint): apply linter

---------

Co-authored-by: Verite Mugabo <[email protected]>
  • Loading branch information
hjoelh and veritem authored Apr 9, 2024
1 parent 318d4ec commit 36e5b9a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/rules/no-focused-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ export default createEslintRule<Options, MessageIds>({
messageId: 'noFocusedTests'
})
}

if (callee.type === 'TaggedTemplateExpression') {
const tagCall = callee.tag.type === 'MemberExpression' ? callee.tag.object : null
if (!tagCall) return

if (
tagCall.type === 'MemberExpression'
&& isTestOrDescribe(tagCall.object)
&& isOnly(tagCall.property)
) {
context.report({
node: tagCall.property,
messageId: 'noFocusedTests'
})
}
}
}
},
CallExpression(node) {
Expand Down
26 changes: 26 additions & 0 deletions tests/no-focused-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ ruleTester.run(RULE_NAME, rule, {
}
],
output: 'it.only.each([])("test", () => {});'
},
{
code: 'test.only.each``("test", () => {});',
errors: [
{
column: 6,
endColumn: 10,
endLine: 1,
line: 1,
messageId: 'noFocusedTests'
}
],
output: 'test.only.each``("test", () => {});'
},
{
code: 'it.only.each``("test", () => {});',
errors: [
{
column: 4,
endColumn: 8,
endLine: 1,
line: 1,
messageId: 'noFocusedTests'
}
],
output: 'it.only.each``("test", () => {});'
}
]
})

0 comments on commit 36e5b9a

Please sign in to comment.