Skip to content

Commit

Permalink
Merge pull request #196 from lo1tuma/gh-172
Browse files Browse the repository at this point in the history
Fix no-setup-in-describe to correctly detect describe calls
  • Loading branch information
lo1tuma authored Jul 8, 2019
2 parents dd43791 + 88a3598 commit 8ad04fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ module.exports = function noSetupInDescribe(context) {
}
}

function isDescribe(node) {
return astUtils.isDescribe(node, additionalSuiteNames(settings));
}

function isParentDescribe(node) {
return astUtils.isDescribe(node.parent, additionalSuiteNames(settings));
return isDescribe(node.parent);
}

return {
CallExpression(node) {
const isDescribe = astUtils.isDescribe(node, additionalSuiteNames(settings));
if (isDescribe) {
if (isDescribe(node)) {
nesting.push(DESCRIBE);
return;
}
Expand All @@ -68,7 +71,7 @@ module.exports = function noSetupInDescribe(context) {
},

'CallExpression:exit'(node) {
if (astUtils.isDescribe(node) || nesting.length && isPureNode(node)) {
if (isDescribe(node) || nesting.length && isPureNode(node)) {
nesting.pop();
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getNodeName(node) {
return node.name;
}

function isDescribe(node, additionalSuiteNames) {
function isDescribe(node, additionalSuiteNames = []) {
return isCallExpression(node) &&
describeAliases.concat(additionalSuiteNames).indexOf(getNodeName(node.callee)) > -1;
}
Expand Down
10 changes: 10 additions & 0 deletions test/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ ruleTester.run('no-setup-in-describe', rule, {
additionalSuiteNames: [ 'foo' ]
}
}
},
{
code: `describe('', () => {
it('', () =>{
foo()();
foo()();
bar();
});
});`,
parserOptions: { ecmaVersion: 2015 }
}
],

Expand Down

0 comments on commit 8ad04fc

Please sign in to comment.