Allow waitsFor() arguments to be specified in arbitrary order.
Default waitsFor() timeout is now specified in env.defaultTimeoutInterval; defaults to 5 seconds. Deprecate waits() block in favor of waitsFor().
This commit is contained in:
parent
55149310c3
commit
e7a57606a2
|
@ -259,6 +259,63 @@ describe("jasmine spec running", function () {
|
|||
});
|
||||
|
||||
describe("waitsFor", function() {
|
||||
var latchFunction = function() {
|
||||
return true;
|
||||
};
|
||||
var spec;
|
||||
|
||||
function makeWaitsForSpec() {
|
||||
var args = jasmine.util.argsToArray(arguments);
|
||||
env.describe('suite', function() {
|
||||
spec = env.it('spec', function() {
|
||||
this.waitsFor.apply(this, args);
|
||||
});
|
||||
});
|
||||
env.execute();
|
||||
}
|
||||
|
||||
it("should accept args (latchFunction, timeoutMessage, timeout)", function() {
|
||||
makeWaitsForSpec(latchFunction, "message", 123);
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(123);
|
||||
expect(block.message).toEqual('message');
|
||||
});
|
||||
|
||||
it("should accept args (latchFunction, timeout)", function() {
|
||||
makeWaitsForSpec(latchFunction, 123);
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(123);
|
||||
expect(block.message).toEqual(null);
|
||||
});
|
||||
|
||||
it("should accept args (latchFunction, timeoutMessage)", function() {
|
||||
env.defaultTimeoutInterval = 4321;
|
||||
makeWaitsForSpec(latchFunction, "message");
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(4321);
|
||||
expect(block.message).toEqual('message');
|
||||
});
|
||||
|
||||
it("should accept args (latchFunction)", function() {
|
||||
env.defaultTimeoutInterval = 4321;
|
||||
makeWaitsForSpec(latchFunction);
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(4321);
|
||||
expect(block.message).toEqual(null);
|
||||
});
|
||||
|
||||
it("should accept deprecated args order (timeout, latchFunction, timeoutMessage)", function() {
|
||||
makeWaitsForSpec(123, latchFunction, "message");
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(123);
|
||||
expect(block.message).toEqual('message');
|
||||
});
|
||||
|
||||
it("testWaitsFor", function() {
|
||||
var doneWaiting = false;
|
||||
var runsBlockExecuted = false;
|
||||
|
|
|
@ -11,6 +11,7 @@ jasmine.Env = function() {
|
|||
this.reporter = new jasmine.MultiReporter();
|
||||
|
||||
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
|
||||
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
this.lastUpdate = 0;
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
|
|
36
src/Spec.js
36
src/Spec.js
|
@ -73,14 +73,46 @@ jasmine.Spec.prototype.expect = function(actual) {
|
|||
return positive;
|
||||
};
|
||||
|
||||
/**
|
||||
* Waits a fixed time period before moving to the next block.
|
||||
*
|
||||
* @deprecated Use waitsFor() instead
|
||||
* @param {Number} timeout milliseconds to wait
|
||||
*/
|
||||
jasmine.Spec.prototype.waits = function(timeout) {
|
||||
var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
|
||||
this.addToQueue(waitsFunc);
|
||||
return this;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) {
|
||||
var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this);
|
||||
/**
|
||||
* Waits for the latchFunction to return true before proceeding to the next block.
|
||||
*
|
||||
* @param {Function} latchFunction
|
||||
* @param {String} optional_timeoutMessage
|
||||
* @param {Number} optional_timeout
|
||||
*/
|
||||
jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
||||
var latchFunction_ = null;
|
||||
var optional_timeoutMessage_ = null;
|
||||
var optional_timeout_ = null;
|
||||
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var arg = arguments[i];
|
||||
switch (typeof arg) {
|
||||
case 'function':
|
||||
latchFunction_ = arg;
|
||||
break;
|
||||
case 'string':
|
||||
optional_timeoutMessage_ = arg;
|
||||
break;
|
||||
case 'number':
|
||||
optional_timeout_ = arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
|
||||
this.addToQueue(waitsForFunc);
|
||||
return this;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* @param {jasmine.Spec} spec The Jasmine spec.
|
||||
*/
|
||||
jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
|
||||
this.timeout = timeout;
|
||||
this.timeout = timeout || env.defaultTimeoutInterval;
|
||||
this.latchFunction = latchFunction;
|
||||
this.message = message;
|
||||
this.totalTimeSpentWaitingForLatch = 0;
|
||||
|
|
23
src/base.js
23
src/base.js
|
@ -21,11 +21,16 @@ jasmine.unimplementedMethod_ = function() {
|
|||
jasmine.undefined = jasmine.___undefined___;
|
||||
|
||||
/**
|
||||
* Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed.
|
||||
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
|
||||
*
|
||||
*/
|
||||
jasmine.DEFAULT_UPDATE_INTERVAL = 250;
|
||||
|
||||
/**
|
||||
* Default timeout interval in milliseconds for waitsFor() blocks.
|
||||
*/
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||
|
||||
jasmine.getGlobal = function() {
|
||||
function getGlobal() {
|
||||
return this;
|
||||
|
@ -490,22 +495,24 @@ var runs = function(func) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Waits for a timeout before moving to the next runs()-defined block.
|
||||
* @param {Number} timeout
|
||||
* Waits a fixed time period before moving to the next block.
|
||||
*
|
||||
* @deprecated Use waitsFor() instead
|
||||
* @param {Number} timeout milliseconds to wait
|
||||
*/
|
||||
var waits = function(timeout) {
|
||||
jasmine.getEnv().currentSpec.waits(timeout);
|
||||
};
|
||||
|
||||
/**
|
||||
* Waits for the latchFunction to return true before proceeding to the next runs()-defined block.
|
||||
* Waits for the latchFunction to return true before proceeding to the next block.
|
||||
*
|
||||
* @param {Number} timeout
|
||||
* @param {Function} latchFunction
|
||||
* @param {String} message
|
||||
* @param {String} optional_timeoutMessage
|
||||
* @param {Number} optional_timeout
|
||||
*/
|
||||
var waitsFor = function(timeout, latchFunction, message) {
|
||||
jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message);
|
||||
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
||||
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue