From 2750d17c67a15dd26c3f29f19e5e1a956ce1e726 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Mon, 13 Aug 2018 10:18:45 +0200 Subject: [PATCH] Reuse helper --- lib/rules/no-nested-tests.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/rules/no-nested-tests.js b/lib/rules/no-nested-tests.js index 22d64dc..7595a59 100644 --- a/lib/rules/no-nested-tests.js +++ b/lib/rules/no-nested-tests.js @@ -17,32 +17,25 @@ module.exports = function noNestedTests(context) { }); } - function isNestedTest(isTestCase, isDescribe) { - const isNested = testNestingLevel > 0; + function isNestedTest(isTestCase, isDescribe, nestingLevel) { + const isNested = nestingLevel > 0; const isTest = isTestCase || isDescribe; return isNested && isTest; } - function isTestInHookCall(isTestCase, isHookCall) { - const isNested = hookCallNestingLevel > 0; - const isTest = isTestCase || isHookCall; - - return isNested && isTest; - } - return { CallExpression(node) { const isTestCase = astUtils.isTestCase(node); const isHookCall = astUtils.isHookCall(node); const isDescribe = astUtils.isDescribe(node, additionalSuiteNames(settings)); - if (isNestedTest(isTestCase, isDescribe)) { + if (isNestedTest(isTestCase, isDescribe, testNestingLevel)) { const message = isDescribe ? 'Unexpected suite nested within a test.' : 'Unexpected test nested within another test.'; report(node, message); - } else if (isTestInHookCall(isTestCase, isHookCall)) { + } else if (isNestedTest(isTestCase, isHookCall, hookCallNestingLevel)) { report(node, 'Unexpected test nested within a test hook.'); }