Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no-setup-in-describe to work with arrow functions #195

Merged
merged 1 commit into from
Jul 8, 2019
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
12 changes: 8 additions & 4 deletions lib/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ module.exports = function noSetupInDescribe(context) {
}
}

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

return {
CallExpression(node) {
const isDescribe = astUtils.isDescribe(node, additionalSuiteNames(settings));
Expand Down Expand Up @@ -86,13 +90,13 @@ module.exports = function noSetupInDescribe(context) {
}
},

ArrowFunctionExpression() {
if (nesting.length) {
ArrowFunctionExpression(node) {
if (nesting.length && !isParentDescribe(node)) {
nesting.push(FUNCTION);
}
},
'ArrowFunctionExpression:exit'() {
if (nesting.length) {
'ArrowFunctionExpression:exit'(node) {
if (nesting.length && !isParentDescribe(node)) {
nesting.pop();
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ ruleTester.run('no-setup-in-describe', rule, {
line: 1,
column: 28
} ]
}, {
code: 'describe("", () => { a(); });',
parserOptions: { ecmaVersion: 2015 },
errors: [ {
message: 'Unexpected function call in describe block.',
line: 1,
column: 22
} ]
}, {
code: 'foo("", function () { a(); });',
settings: {
Expand Down