Skip to content

Commit

Permalink
chore(utils): create isDescribeEach guard
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Oct 31, 2019
1 parent d620388 commit 2224c95
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/rules/utils.ts
Expand Up @@ -550,22 +550,32 @@ export enum TestCaseProperty {
}

export type JestFunctionName = DescribeAlias | TestCaseName | HookName;
export type JestPropertyName = DescribeProperty | TestCaseProperty;

export interface JestFunctionIdentifier<FunctionName extends JestFunctionName>
extends TSESTree.Identifier {
name: FunctionName;
}

export interface JestFunctionMemberExpression<
FunctionName extends JestFunctionName
> extends TSESTree.MemberExpression {
FunctionName extends JestFunctionName,
PropertyName extends JestPropertyName = JestPropertyName
> extends KnownMemberExpression<PropertyName> {
object: JestFunctionIdentifier<FunctionName>;
}

export interface JestFunctionMemberExpression<
FunctionName extends JestFunctionName,
PropertyName extends JestPropertyName = JestPropertyName
> extends KnownMemberExpression<PropertyName> {
object: JestFunctionIdentifier<FunctionName>;
}

export interface JestFunctionCallExpressionWithMemberExpressionCallee<
FunctionName extends JestFunctionName
FunctionName extends JestFunctionName,
PropertyName extends JestPropertyName = JestPropertyName
> extends TSESTree.CallExpression {
callee: JestFunctionMemberExpression<FunctionName>;
callee: JestFunctionMemberExpression<FunctionName, PropertyName>;
}

export interface JestFunctionCallExpressionWithIdentifierCallee<
Expand Down Expand Up @@ -651,6 +661,21 @@ export const isDescribe = (
);
};

/**
* Checks if the given `describe` is a call to `describe.each`.
*
* @param {JestFunctionCallExpression<DescribeAlias>} node
* @return {node is JestFunctionCallExpression<DescribeAlias, DescribeProperty.each>}
*/
export const isDescribeEach = (
node: JestFunctionCallExpression<DescribeAlias>,
): node is JestFunctionCallExpressionWithMemberExpressionCallee<
DescribeAlias,
DescribeProperty.each
> =>
node.callee.type === AST_NODE_TYPES.MemberExpression &&
isSupportedAccessor(node.callee.property, DescribeProperty.each);

/**
* Gets the arguments of the given `JestFunctionCallExpression`.
*
Expand Down

0 comments on commit 2224c95

Please sign in to comment.