Skip to content

Commit

Permalink
Throw Error When Using Nested It Specs (#4039)
Browse files Browse the repository at this point in the history
* throw error when adding nested it specs

* add comment

* improve error message

* Update Env.js
  • Loading branch information
rafaelcalpena authored and cpojer committed Aug 24, 2017
1 parent fcf64d7 commit 82e6639
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 82e6639

Please sign in to comment.