Skip to content

Commit

Permalink
Reuse helper
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Aug 13, 2018
1 parent 262764a commit 2750d17
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/rules/no-nested-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down

0 comments on commit 2750d17

Please sign in to comment.