afterEach now allows for waits, runs blocks
This commit is contained in:
parent
b55399bd4b
commit
8b998749f3
|
@ -1689,7 +1689,6 @@ jasmine.Spec.prototype.finish = function(onComplete) {
|
|||
for (var i = 0; i < this.afterCallbacks.length; i++) {
|
||||
this.afterCallbacks[i]();
|
||||
}
|
||||
this.safeExecuteAfters();
|
||||
this.removeAllSpies();
|
||||
this.finishCallback();
|
||||
if (onComplete) {
|
||||
|
@ -1701,7 +1700,6 @@ jasmine.Spec.prototype.after = function(doAfter) {
|
|||
this.afterCallbacks.unshift(doAfter);
|
||||
};
|
||||
|
||||
|
||||
jasmine.Spec.prototype.execute = function(onComplete) {
|
||||
var spec = this;
|
||||
if (!spec.env.specFilter(spec)) {
|
||||
|
@ -1714,7 +1712,7 @@ jasmine.Spec.prototype.execute = function(onComplete) {
|
|||
spec.env.currentSpec = spec;
|
||||
spec.env.currentlyRunningTests = true;
|
||||
|
||||
spec.safeExecuteBefores();
|
||||
spec.addBeforesAndAftersToQueue();
|
||||
|
||||
spec.queue.start(function () {
|
||||
spec.finish(onComplete);
|
||||
|
@ -1722,34 +1720,17 @@ jasmine.Spec.prototype.execute = function(onComplete) {
|
|||
spec.env.currentlyRunningTests = false;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.safeExecuteBefores = function() {
|
||||
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
|
||||
for (var suite = this.suite; suite; suite = suite.parentSuite) {
|
||||
if (suite.beforeQueue) {
|
||||
for (var i = 0; i < suite.beforeQueue.length; i++)
|
||||
this.queue.addBefore(new jasmine.Block(this.env, suite.beforeQueue[i], this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.safeExecuteAfters = function() {
|
||||
var afters = [];
|
||||
for (var suite = this.suite; suite; suite = suite.parentSuite) {
|
||||
if (suite.afterQueue) {
|
||||
for (var i = 0; i < suite.afterQueue.length; i++)
|
||||
afters.unshift(suite.afterQueue[i]);
|
||||
for (var j = 0; j < suite.afterQueue.length; j++)
|
||||
this.queue.add(new jasmine.Block(this.env, suite.afterQueue[j], this));
|
||||
}
|
||||
}
|
||||
while (afters.length) {
|
||||
this.safeExecuteBeforeOrAfter(afters.pop());
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.safeExecuteBeforeOrAfter = function(func) {
|
||||
try {
|
||||
func.apply(this);
|
||||
} catch (e) {
|
||||
this.results.addResult(new jasmine.ExpectationResult(false, func.typeName + '() fail: ' + jasmine.util.formatException(e), null));
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.explodes = function() {
|
||||
|
|
|
@ -630,6 +630,51 @@ describe("jasmine spec running", function () {
|
|||
expect(foo).toEqual(3);
|
||||
});
|
||||
|
||||
it("#afterEach should be able to eval runs and waits blocks", function () {
|
||||
var foo = 0;
|
||||
var firstSpecHasRun = false;
|
||||
var secondSpecHasRun = false;
|
||||
var suiteWithAfter = env.describe('one suite with a before', function () {
|
||||
this.afterEach(function () {
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
this.waits(500);
|
||||
});
|
||||
|
||||
env.it('should be the first spec', function () {
|
||||
firstSpecHasRun = true;
|
||||
});
|
||||
|
||||
env.it('should be a spec', function () {
|
||||
secondSpecHasRun = true;
|
||||
foo++;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
expect(firstSpecHasRun).toEqual(false);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
|
||||
suiteWithAfter.execute();
|
||||
|
||||
expect(firstSpecHasRun).toEqual(true);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(foo).toEqual(1);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(foo).toEqual(2);
|
||||
expect(secondSpecHasRun).toEqual(true);
|
||||
|
||||
});
|
||||
|
||||
it("testBeforeExecutesSafely", function() {
|
||||
var report = "";
|
||||
var suite = env.describe('before fails on first test, passes on second', function() {
|
||||
|
|
27
src/Spec.js
27
src/Spec.js
|
@ -100,7 +100,6 @@ jasmine.Spec.prototype.finish = function(onComplete) {
|
|||
for (var i = 0; i < this.afterCallbacks.length; i++) {
|
||||
this.afterCallbacks[i]();
|
||||
}
|
||||
this.safeExecuteAfters();
|
||||
this.removeAllSpies();
|
||||
this.finishCallback();
|
||||
if (onComplete) {
|
||||
|
@ -112,7 +111,6 @@ jasmine.Spec.prototype.after = function(doAfter) {
|
|||
this.afterCallbacks.unshift(doAfter);
|
||||
};
|
||||
|
||||
|
||||
jasmine.Spec.prototype.execute = function(onComplete) {
|
||||
var spec = this;
|
||||
if (!spec.env.specFilter(spec)) {
|
||||
|
@ -125,7 +123,7 @@ jasmine.Spec.prototype.execute = function(onComplete) {
|
|||
spec.env.currentSpec = spec;
|
||||
spec.env.currentlyRunningTests = true;
|
||||
|
||||
spec.safeExecuteBefores();
|
||||
spec.addBeforesAndAftersToQueue();
|
||||
|
||||
spec.queue.start(function () {
|
||||
spec.finish(onComplete);
|
||||
|
@ -133,34 +131,17 @@ jasmine.Spec.prototype.execute = function(onComplete) {
|
|||
spec.env.currentlyRunningTests = false;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.safeExecuteBefores = function() {
|
||||
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
|
||||
for (var suite = this.suite; suite; suite = suite.parentSuite) {
|
||||
if (suite.beforeQueue) {
|
||||
for (var i = 0; i < suite.beforeQueue.length; i++)
|
||||
this.queue.addBefore(new jasmine.Block(this.env, suite.beforeQueue[i], this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.safeExecuteAfters = function() {
|
||||
var afters = [];
|
||||
for (var suite = this.suite; suite; suite = suite.parentSuite) {
|
||||
if (suite.afterQueue) {
|
||||
for (var i = 0; i < suite.afterQueue.length; i++)
|
||||
afters.unshift(suite.afterQueue[i]);
|
||||
for (var j = 0; j < suite.afterQueue.length; j++)
|
||||
this.queue.add(new jasmine.Block(this.env, suite.afterQueue[j], this));
|
||||
}
|
||||
}
|
||||
while (afters.length) {
|
||||
this.safeExecuteBeforeOrAfter(afters.pop());
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.safeExecuteBeforeOrAfter = function(func) {
|
||||
try {
|
||||
func.apply(this);
|
||||
} catch (e) {
|
||||
this.results.addResult(new jasmine.ExpectationResult(false, func.typeName + '() fail: ' + jasmine.util.formatException(e), null));
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.explodes = function() {
|
||||
|
|
Loading…
Reference in New Issue