Throw an error on nested methods
This commit is contained in:
@@ -384,6 +384,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function ensureIsNotNested(method, currentSuite) {
|
||||||
|
if (currentSuite !== undefined) {
|
||||||
|
throw new Error('\'' + method + '\' should only be used in \'describe\' function');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var suiteFactory = function(description) {
|
var suiteFactory = function(description) {
|
||||||
var suite = new j$.Suite({
|
var suite = new j$.Suite({
|
||||||
env: self,
|
env: self,
|
||||||
@@ -399,6 +405,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.describe = function(description, specDefinitions) {
|
this.describe = function(description, specDefinitions) {
|
||||||
|
ensureIsNotNested('describe', currentSuite());
|
||||||
ensureIsFunction(specDefinitions, 'describe');
|
ensureIsFunction(specDefinitions, 'describe');
|
||||||
var suite = suiteFactory(description);
|
var suite = suiteFactory(description);
|
||||||
if (specDefinitions.length > 0) {
|
if (specDefinitions.length > 0) {
|
||||||
@@ -412,6 +419,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.xdescribe = function(description, specDefinitions) {
|
this.xdescribe = function(description, specDefinitions) {
|
||||||
|
ensureIsNotNested('xdescribe', currentSuite());
|
||||||
ensureIsFunction(specDefinitions, 'xdescribe');
|
ensureIsFunction(specDefinitions, 'xdescribe');
|
||||||
var suite = suiteFactory(description);
|
var suite = suiteFactory(description);
|
||||||
suite.pend();
|
suite.pend();
|
||||||
@@ -422,6 +430,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
var focusedRunnables = [];
|
var focusedRunnables = [];
|
||||||
|
|
||||||
this.fdescribe = function(description, specDefinitions) {
|
this.fdescribe = function(description, specDefinitions) {
|
||||||
|
ensureIsNotNested('fdescribe', currentSuite());
|
||||||
ensureIsFunction(specDefinitions, 'fdescribe');
|
ensureIsFunction(specDefinitions, 'fdescribe');
|
||||||
var suite = suiteFactory(description);
|
var suite = suiteFactory(description);
|
||||||
suite.isFocused = true;
|
suite.isFocused = true;
|
||||||
@@ -519,6 +528,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.it = function(description, fn, timeout) {
|
this.it = function(description, fn, timeout) {
|
||||||
|
ensureIsNotNested('it', currentSuite());
|
||||||
// it() sometimes doesn't have a fn argument, so only check the type if
|
// it() sometimes doesn't have a fn argument, so only check the type if
|
||||||
// it's given.
|
// it's given.
|
||||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||||
@@ -533,6 +543,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.xit = function(description, fn, timeout) {
|
this.xit = function(description, fn, timeout) {
|
||||||
|
ensureIsNotNested('xit', currentSuite());
|
||||||
// xit(), like it(), doesn't always have a fn argument, so only check the
|
// xit(), like it(), doesn't always have a fn argument, so only check the
|
||||||
// type when needed.
|
// type when needed.
|
||||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||||
@@ -544,6 +555,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.fit = function(description, fn, timeout){
|
this.fit = function(description, fn, timeout){
|
||||||
|
ensureIsNotNested('fit', currentSuite());
|
||||||
ensureIsFunctionOrAsync(fn, 'fit');
|
ensureIsFunctionOrAsync(fn, 'fit');
|
||||||
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||||
currentDeclarationSuite.addChild(spec);
|
currentDeclarationSuite.addChild(spec);
|
||||||
@@ -561,6 +573,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.beforeEach = function(beforeEachFunction, timeout) {
|
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||||
|
ensureIsNotNested('beforeEach', currentSuite());
|
||||||
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
||||||
currentDeclarationSuite.beforeEach({
|
currentDeclarationSuite.beforeEach({
|
||||||
fn: beforeEachFunction,
|
fn: beforeEachFunction,
|
||||||
@@ -569,6 +582,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.beforeAll = function(beforeAllFunction, timeout) {
|
this.beforeAll = function(beforeAllFunction, timeout) {
|
||||||
|
ensureIsNotNested('beforeAll', currentSuite());
|
||||||
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
||||||
currentDeclarationSuite.beforeAll({
|
currentDeclarationSuite.beforeAll({
|
||||||
fn: beforeAllFunction,
|
fn: beforeAllFunction,
|
||||||
@@ -577,6 +591,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.afterEach = function(afterEachFunction, timeout) {
|
this.afterEach = function(afterEachFunction, timeout) {
|
||||||
|
ensureIsNotNested('afterEach', currentSuite());
|
||||||
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
||||||
afterEachFunction.isCleanup = true;
|
afterEachFunction.isCleanup = true;
|
||||||
currentDeclarationSuite.afterEach({
|
currentDeclarationSuite.afterEach({
|
||||||
@@ -586,6 +601,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.afterAll = function(afterAllFunction, timeout) {
|
this.afterAll = function(afterAllFunction, timeout) {
|
||||||
|
ensureIsNotNested('afterAll', currentSuite());
|
||||||
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
||||||
currentDeclarationSuite.afterAll({
|
currentDeclarationSuite.afterAll({
|
||||||
fn: afterAllFunction,
|
fn: afterAllFunction,
|
||||||
|
|||||||
Reference in New Issue
Block a user