Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(util): identify only valid global properties (#341)
Fixes #340
  • Loading branch information
ranyitz authored and SimenB committed Jul 22, 2019
1 parent b27c80d commit 8e67740
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/rules/__tests__/no-identical-title.test.js
Expand Up @@ -113,6 +113,26 @@ ruleTester.run('no-identical-title', rule, {
es6: true,
},
},
{
code: [
'const test = { content: () => "foo" }',
'test.content(`testing backticks with the same title`);',
'test.content(`testing backticks with the same title`);',
].join('\n'),
env: {
es6: true,
},
},
{
code: [
'const describe = { content: () => "foo" }',
'describe.content(`testing backticks with the same title`);',
'describe.content(`testing backticks with the same title`);',
].join('\n'),
env: {
es6: true,
},
},
],

invalid: [
Expand Down
10 changes: 8 additions & 2 deletions src/rules/util.js
Expand Up @@ -101,13 +101,18 @@ const describeAliases = new Set(['describe', 'fdescribe', 'xdescribe']);

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

const describeProperties = new Set(['each', 'only', 'skip']);

const testCaseProperties = new Set(['each', 'only', 'skip', 'todo']);

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

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

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

0 comments on commit 8e67740

Please sign in to comment.