Major refactoring of Spec. Moved QueuedFunction to Block, WaitsBlock and WaitsForBlock. Waits and WaitsFor blocks now sequentially stackable
This commit is contained in:
38
src/WaitsForBlock.js
Normal file
38
src/WaitsForBlock.js
Normal file
@@ -0,0 +1,38 @@
|
||||
jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
|
||||
this.timeout = timeout;
|
||||
this.latchFunction = latchFunction;
|
||||
this.message = message;
|
||||
this.totalTimeSpentWaitingForLatch = 0;
|
||||
jasmine.Block.call(this, env, null, spec);
|
||||
};
|
||||
|
||||
jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
|
||||
|
||||
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
|
||||
|
||||
jasmine.WaitsForBlock.prototype.execute = function () {
|
||||
var self = this;
|
||||
self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
|
||||
var latchFunctionResult;
|
||||
try {
|
||||
latchFunctionResult = self.latchFunction.apply(self.spec);
|
||||
} catch (e) {
|
||||
self.fail(e);
|
||||
self.next();
|
||||
return;
|
||||
}
|
||||
|
||||
if (latchFunctionResult) {
|
||||
self.next();
|
||||
} else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
|
||||
var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
|
||||
self.fail({
|
||||
name: 'timeout',
|
||||
message: message
|
||||
});
|
||||
self.spec.next();
|
||||
} else {
|
||||
self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
|
||||
self.env.setTimeout(function () { self.execute(); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user