fix(env): Throw if nested describe has no children.

Users would like an error if it() is acciddently moved within a before/afterEach/All function.
The it() function calls ensureIsNotNested to report such an error. But if the user has no
other it() functions in the Suite, it() and thus ensureIsNotNested() is never called.

Here we check nested Suites for children; if none are found we throw.
This commit is contained in:
johnjbarton
2019-08-07 17:44:57 -07:00
parent 0449b35f5a
commit 2369c8dba7
4 changed files with 15 additions and 1 deletions

View File

@@ -133,6 +133,12 @@ describe('Env', function() {
'describe expects a function argument; received [object Function]'
);
});
it('throws an error when it has no children', function() {
expect(function() {
env.describe('done method', function() {});
}).toThrowError('describe with no children (describe() or it())');
});
});
describe('#it', function() {

View File

@@ -30,7 +30,9 @@ describe('Exceptions:', function() {
});
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
var secondDescribe = jasmine.createSpy('second describe');
var secondDescribe = jasmine.createSpy('second describe').and.callFake(function() {
env.it('is a test', function() {});
});
env.describe('a suite that throws an exception', function() {
env.it('is a test that should pass', function() {
this.expect(true).toEqual(true);

View File

@@ -1881,6 +1881,7 @@ describe("Env integration", function() {
} catch(e) {
exception = e;
}
env.it('has a test', () => {});
});
var assertions = function() {
@@ -1904,6 +1905,7 @@ describe("Env integration", function() {
} catch(e) {
exception = e;
}
env.it('has a test', () => {});
});
var assertions = function() {
@@ -1927,6 +1929,7 @@ describe("Env integration", function() {
} catch(e) {
exception = e;
}
env.it('has a test', () => {});
});
var assertions = function() {

View File

@@ -843,6 +843,9 @@ getJasmineRequireObj().Env = function(j$) {
suite.pend();
}
addSpecsToSuite(suite, specDefinitions);
if (suite.parentSuite && !suite.children.length) {
throw new Error('describe with no children (describe() or it())');
}
return suite;
};