Sha256: 56e0d566c183321c8f64c4dd30ab5cc3d166340379e8eb9e399f4a60de8a9c52

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

/**
 * A block which waits for some condition to become true, with timeout.
 *
 * @constructor
 * @extends jasmine.Block
 * @param {jasmine.Env} env The Jasmine environment.
 * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
 * @param {Function} latchFunction A function which returns true when the desired condition has been met.
 * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
 * @param {jasmine.Spec} spec The Jasmine spec.
 */
jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
  this.timeout = timeout || env.defaultTimeoutInterval;
  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 = 10;

jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
  this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
  var latchFunctionResult;
  try {
    latchFunctionResult = this.latchFunction.apply(this.spec);
  } catch (e) {
    this.spec.fail(e);
    onComplete();
    return;
  }

  if (latchFunctionResult) {
    onComplete();
  } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
    var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
    this.spec.fail({
      name: 'timeout',
      message: message
    });

    this.abort = true;
    onComplete();
  } else {
    this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
    var self = this;
    this.env.setTimeout(function() {
      self.execute(onComplete);
    }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
  }
};

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
evergreen-1.0.0.rc lib/jasmine/src/WaitsForBlock.js
rails31-evergreen-0.4.1 lib/jasmine/src/WaitsForBlock.js
evergreen-0.4.1 lib/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.3.0 vendor/jasmine/src/WaitsForBlock.js
jasmine-1.0.2.0 jasmine/src/WaitsForBlock.js
danieldkim-evergreen-0.4.0.6 lib/jasmine/src/WaitsForBlock.js
gjastrab-evergreen-0.4.0.3 lib/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.2.9 vendor/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.2.8 vendor/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.2.7 vendor/jasmine/src/WaitsForBlock.js
evergreen-0.4.0 lib/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.2.6 vendor/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.2.5 vendor/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.2.1 vendor/jasmine/src/WaitsForBlock.js
js-test-driver-rails-0.2.0 vendor/jasmine/src/WaitsForBlock.js