Refactor Spec block execution into Queue
This commit is contained in:
29
src/Queue.js
Normal file
29
src/Queue.js
Normal file
@@ -0,0 +1,29 @@
|
||||
jasmine.Queue = function() {
|
||||
this.blocks = [];
|
||||
};
|
||||
|
||||
jasmine.Queue.prototype.add = function(block) {
|
||||
this.setNextOnLastInQueue(block);
|
||||
this.blocks.push(block);
|
||||
};
|
||||
|
||||
jasmine.Queue.prototype.start = function(onComplete) {
|
||||
if (this.blocks[0]) {
|
||||
this.blocks[0].execute();
|
||||
} else {
|
||||
onComplete();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
jasmine.Queue.prototype.setNextOnLastInQueue = function (block) {
|
||||
if (this.blocks.length > 0) {
|
||||
var previousBlock = this.blocks[this.blocks.length - 1];
|
||||
previousBlock.next = function() {
|
||||
block.execute();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user