Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/rules/no-if.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { getDocsUrl, getNodeName, isTestCase, testCaseNames } from './util';
import { getDocsUrl, isTestCase } from './util';

const isTestArrowFunction = node =>
node !== undefined &&
node.type === 'ArrowFunctionExpression' &&
node.parent.type === 'CallExpression' &&
testCaseNames.has(getNodeName(node.parent.callee));
isTestCase(node.parent);

export default {
meta: {
Expand Down
34 changes: 13 additions & 21 deletions src/rules/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,9 @@ export const argument = node =>
export const argument2 = node =>
node.parent.parent.parent.arguments && node.parent.parent.parent.arguments[0];

const describeAliases = new Set([
'describe',
'describe.only',
'describe.skip',
'fdescribe',
'xdescribe',
]);
const describeAliases = new Set(['describe', 'fdescribe', 'xdescribe']);

export const testCaseNames = new Set([
'fit',
'it',
'it.only',
'it.skip',
'test',
'test.only',
'test.skip',
'xit',
'xtest',
]);
const testCaseNames = new Set(['fit', 'it', 'test', 'xit', 'xtest']);

const testHookNames = new Set([
'beforeAll',
Expand Down Expand Up @@ -127,17 +111,25 @@ export const getNodeName = node => {
export const isHook = node =>
node &&
node.type === 'CallExpression' &&
testHookNames.has(getNodeName(node.callee));
node.callee.type === 'Identifier' &&
testHookNames.has(node.callee.name);

export const isTestCase = node =>
node &&
node.type === 'CallExpression' &&
testCaseNames.has(getNodeName(node.callee));
((node.callee.type === 'Identifier' && testCaseNames.has(node.callee.name)) ||
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
testCaseNames.has(node.callee.object.name)));

export const isDescribe = node =>
node &&
node.type === 'CallExpression' &&
describeAliases.has(getNodeName(node.callee));
((node.callee.type === 'Identifier' &&
describeAliases.has(node.callee.name)) ||
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
describeAliases.has(node.callee.object.name)));

export const isFunction = node =>
node &&
Expand Down