Skip to content

Commit

Permalink
fix: don't consider method calls on literals or new to be jest func…
Browse files Browse the repository at this point in the history
…tions (#1132)
  • Loading branch information
G-Rath authored May 29, 2022
1 parent 0b2d64d commit 379ceb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/rules/utils/__tests__/parseJestFnCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ ruleTester.run('nonexistent methods', rule, {
'describe.concurrent()()',
'describe.concurrent``()',
'describe.every``()',
'/regex/.test()',
'"something".describe()',
'[].describe()',
'new describe().only()',
],
invalid: [],
});
Expand Down
14 changes: 9 additions & 5 deletions src/rules/utils/parseJestFnCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export const isTypeOfJestFnCall = (
return jestFnCall !== null && types.includes(jestFnCall.type);
};

export function getNodeChain(node: TSESTree.Node): AccessorNode[] {
const joinChains = (
a: AccessorNode[] | null,
b: AccessorNode[] | null,
): AccessorNode[] | null => (a && b ? [...a, ...b] : null);

export function getNodeChain(node: TSESTree.Node): AccessorNode[] | null {
if (isSupportedAccessor(node)) {
return [node];
}
Expand All @@ -30,13 +35,12 @@ export function getNodeChain(node: TSESTree.Node): AccessorNode[] {
case AST_NODE_TYPES.TaggedTemplateExpression:
return getNodeChain(node.tag);
case AST_NODE_TYPES.MemberExpression:
return [...getNodeChain(node.object), ...getNodeChain(node.property)];
case AST_NODE_TYPES.NewExpression:
return joinChains(getNodeChain(node.object), getNodeChain(node.property));
case AST_NODE_TYPES.CallExpression:
return getNodeChain(node.callee);
}

return [];
return null;
}

export interface ResolvedJestFnWithNode extends ResolvedJestFn {
Expand Down Expand Up @@ -152,7 +156,7 @@ export const parseJestFnCall = (

const chain = getNodeChain(node);

if (chain.length === 0) {
if (!chain?.length) {
return null;
}

Expand Down

0 comments on commit 379ceb3

Please sign in to comment.