Skip to content

Commit 430de17

Browse files
authored
fix: don't consider template tags in the middle of a possible jest function chain to be valid (#1133)
1 parent 44de2ad commit 430de17

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/rules/utils/__tests__/parseJestFnCall.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ ruleTester.run('nonexistent methods', rule, {
118118
'"something".describe()',
119119
'[].describe()',
120120
'new describe().only()',
121+
'``.test()',
122+
'test.only``()',
123+
'test``.only()',
121124
],
122125
invalid: [],
123126
});

src/rules/utils/parseJestFnCall.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,21 @@ export const parseJestFnCall = (
160160
return null;
161161
}
162162

163-
// ensure that the only call expression in the chain is at the end
163+
// check that every link in the chain except the last is a member expression
164164
if (
165165
chain
166166
.slice(0, chain.length - 1)
167-
.some(nod => nod.parent?.type === AST_NODE_TYPES.CallExpression)
167+
.some(nod => nod.parent?.type !== AST_NODE_TYPES.MemberExpression)
168168
) {
169169
return null;
170170
}
171171

172172
const [first, ...rest] = chain;
173173

174-
const lastNode = chain[chain.length - 1];
174+
const lastLink = getAccessorValue(chain[chain.length - 1]);
175175

176176
// if we're an `each()`, ensure we're the outer CallExpression (i.e `.each()()`)
177-
if (isSupportedAccessor(lastNode, 'each')) {
177+
if (lastLink === 'each') {
178178
if (
179179
node.callee.type !== AST_NODE_TYPES.CallExpression &&
180180
node.callee.type !== AST_NODE_TYPES.TaggedTemplateExpression
@@ -183,6 +183,13 @@ export const parseJestFnCall = (
183183
}
184184
}
185185

186+
if (
187+
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression &&
188+
lastLink !== 'each'
189+
) {
190+
return null;
191+
}
192+
186193
const resolved = resolveToJestFn(scope, getAccessorValue(first));
187194

188195
// we're not a jest function

0 commit comments

Comments
 (0)