Skip to content

Commit

Permalink
fix(tsutils): identify only valid global properties (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranyitz authored and SimenB committed Jul 23, 2019
1 parent 8e67740 commit ae3e599
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/rules/tsUtils.ts
Expand Up @@ -96,6 +96,19 @@ export enum HookName {
'afterEach' = 'afterEach',
}

export enum DescribeProperty {
'each' = 'each',
'only' = 'only',
'skip' = 'skip',
}

export enum TestCaseProperty {
'each' = 'each',
'only' = 'only',
'skip' = 'skip',
'todo' = 'todo',
}

export type JestFunctionName = DescribeAlias | TestCaseName | HookName;

export interface JestFunctionIdentifier<FunctionName extends JestFunctionName>
Expand Down Expand Up @@ -178,7 +191,9 @@ export const isTestCase = (
TestCaseName.hasOwnProperty(node.callee.name)) ||
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
node.callee.object.type === AST_NODE_TYPES.Identifier &&
TestCaseName.hasOwnProperty(node.callee.object.name))
TestCaseName.hasOwnProperty(node.callee.object.name) &&
node.callee.property.type === AST_NODE_TYPES.Identifier &&
TestCaseProperty.hasOwnProperty(node.callee.property.name))
);
};

Expand All @@ -190,7 +205,9 @@ export const isDescribe = (
DescribeAlias.hasOwnProperty(node.callee.name)) ||
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
node.callee.object.type === AST_NODE_TYPES.Identifier &&
DescribeAlias.hasOwnProperty(node.callee.object.name))
DescribeAlias.hasOwnProperty(node.callee.object.name) &&
node.callee.property.type === AST_NODE_TYPES.Identifier &&
DescribeProperty.hasOwnProperty(node.callee.property.name))
);
};

Expand Down
2 changes: 2 additions & 0 deletions src/rules/util.js
Expand Up @@ -112,6 +112,7 @@ export const isTestCase = node =>
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
testCaseNames.has(node.callee.object.name) &&
node.callee.property.type === 'Identifier' &&
testCaseProperties.has(node.callee.property.name)));

export const isDescribe = node =>
Expand All @@ -122,6 +123,7 @@ export const isDescribe = node =>
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
describeAliases.has(node.callee.object.name) &&
node.callee.property.type === 'Identifier' &&
describeProperties.has(node.callee.property.name)));

export const isFunction = node =>
Expand Down

0 comments on commit ae3e599

Please sign in to comment.