Multiple befores/afters in a single describe should be executed in order (as declared for befores, in reverse for afters).

This commit is contained in:
Christian Williams 2010-06-04 14:41:16 -04:00
parent ed49104fad
commit a2041e90a6
3 changed files with 62 additions and 5 deletions

View File

@ -861,7 +861,7 @@ describe("jasmine spec running", function () {
expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass");
});
it("testNestedDescribes", function() {
it("should permit nested describes", function() {
var actions = [];
env.beforeEach(function () {
@ -953,6 +953,63 @@ describe("jasmine spec running", function () {
expect(actions).toEqual(expected);
});
it("should run multiple befores and afters in the order they are declared", function() {
var actions = [];
env.beforeEach(function () {
actions.push('runner beforeEach1');
});
env.afterEach(function () {
actions.push('runner afterEach1');
});
env.beforeEach(function () {
actions.push('runner beforeEach2');
});
env.afterEach(function () {
actions.push('runner afterEach2');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('beforeEach1');
});
env.afterEach(function() {
actions.push('afterEach1');
});
env.beforeEach(function() {
actions.push('beforeEach2');
});
env.afterEach(function() {
actions.push('afterEach2');
});
env.it('does it 1', function() {
actions.push('outer it 1');
});
});
env.execute();
var expected = [
"runner beforeEach1",
"runner beforeEach2",
"beforeEach1",
"beforeEach2",
"outer it 1",
"afterEach2",
"afterEach1",
"runner afterEach2",
"runner afterEach1"
];
expect(actions).toEqual(expected);
});
it("builds up nested names", function() {
var nestedSpec;
env.describe('Test Subject', function() {

View File

@ -25,12 +25,12 @@ jasmine.Runner.prototype.execute = function() {
jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
beforeEachFunction.typeName = 'beforeEach';
this.before_.push(beforeEachFunction);
this.before_.unshift(beforeEachFunction);
};
jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
afterEachFunction.typeName = 'afterEach';
this.after_.push(afterEachFunction);
this.after_.unshift(afterEachFunction);
};

View File

@ -37,12 +37,12 @@ jasmine.Suite.prototype.finish = function(onComplete) {
jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
beforeEachFunction.typeName = 'beforeEach';
this.before_.push(beforeEachFunction);
this.before_.unshift(beforeEachFunction);
};
jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
afterEachFunction.typeName = 'afterEach';
this.after_.push(afterEachFunction);
this.after_.unshift(afterEachFunction);
};
jasmine.Suite.prototype.results = function() {