diff --git a/lib/rules/no-setup-in-describe.js b/lib/rules/no-setup-in-describe.js index d6aa739..3e80b98 100644 --- a/lib/rules/no-setup-in-describe.js +++ b/lib/rules/no-setup-in-describe.js @@ -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)); @@ -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(); } } diff --git a/test/rules/no-setup-in-describe.js b/test/rules/no-setup-in-describe.js index 6fcb229..986b5af 100644 --- a/test/rules/no-setup-in-describe.js +++ b/test/rules/no-setup-in-describe.js @@ -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: {