From 82e66396d849b51c9cdd1ab3ab12470209d4bdcf Mon Sep 17 00:00:00 2001 From: Rafael Calpena Rodrigues Date: Thu, 24 Aug 2017 09:17:24 -0300 Subject: [PATCH] Throw Error When Using Nested It Specs (#4039) * throw error when adding nested it specs * add comment * improve error message * Update Env.js --- packages/jest-jasmine2/src/jasmine/Env.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/jest-jasmine2/src/jasmine/Env.js b/packages/jest-jasmine2/src/jasmine/Env.js index 2a0ad062806e..abd2b3bdd30f 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.js +++ b/packages/jest-jasmine2/src/jasmine/Env.js @@ -388,6 +388,18 @@ module.exports = function(j$) { if (currentDeclarationSuite.markedPending) { spec.pend(); } + + // When a test is defined inside another, jasmine will not run it. + // This check throws an error to warn the user about the edge-case. + if (currentSpec !== null) { + throw new Error( + 'Tests cannot be nested. Test `' + + spec.description + + '` cannot run because it is nested within `' + + currentSpec.description + + '`.', + ); + } currentDeclarationSuite.addChild(spec); return spec; };