Yes, everything beforeEachwill be executed in the order you specified.
If you drill in Jasmine, you will end up with this definition :
Suite.prototype.beforeEach = function(fn) {
this.beforeFns.unshift(fn);
};
describe s, Suite . Suite this.beforeFns = [], , . , unshift , , beforeEach. , , , beforeEach, , .
var beforeAndAfterFns = function(suite) {
return function() {
var befores = [],
afters = [];
while(suite) {
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
suite = suite.parentSuite;
}
return {
befores: befores.reverse(),
afters: afters
};
};
};
Dan , , beforeEach . Jasmine 2 beforeEach :
beforeEach(function(done) {
setTimeout(function() {
console.log('Async');
done();
}, 1000)
});
Jasmine done . (Function.length , ).
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var queueableFn = queueableFns[iterativeIndex];
if (queueableFn.fn.length > 0) {
attemptAsync(queueableFn);
return;
} else {
attemptSync(queueableFn);
}
}
attemptAsync , done(), QueueRunner beforeEach, ! .
describe('beforeEach', function() {
var data = null;
beforeEach(function() { data = []; });
beforeEach(function() { data.push(1); });
beforeEach(function(done) {
setTimeout(function() {
data.push('Async');
done();
}, 1000);
});
beforeEach(function() { data.push(2); });
beforeEach(function() { data.push(3); });
it('runs in order', function(){
expect(data).toEqual([1, 'Async', 2, 3]);
});
});