Skip to content
This repository was archived by the owner on Jun 14, 2019. It is now read-only.

fix(protractor-$timeout): use $interval service for reply timeouts so pr... #36

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/service.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ angular.module('knalli.angular-vertxbus')
return this
@skipUnauthorizeds.displayName = "#{CONSTANTS.MODULE}/#{CONSTANTS.COMPONENT}: provider.skipUnauthorizeds"

@$get = ($rootScope, $q, $interval, $timeout, vertxEventBus, $log) ->
@$get = ($rootScope, $q, $interval, vertxEventBus, $log) ->
# Extract options (with defaults)
{ enabled, debugEnabled, prefix, urlServer, urlPath, reconnectEnabled,
sockjsStateInterval, sockjsReconnectInterval, sockjsOptions,
Expand Down Expand Up @@ -219,7 +219,7 @@ angular.module('knalli.angular-vertxbus')
vertxEventBus.send address, message, (reply) ->
if deferred then deferred.resolve reply
# Register timeout for promise rejecting.
if deferred then $timeout (-> deferred.reject()), timeout
if deferred then $interval (-> deferred.reject()), timeout, 1
next.displayName = "#{CONSTANTS.MODULE}/#{CONSTANTS.COMPONENT}: util.send (ensureOpenAuthConnection callback)"
dispatched = ensureOpenAuthConnection next
if deferred and !dispatched then deferred.reject()
Expand Down Expand Up @@ -248,7 +248,7 @@ angular.module('knalli.angular-vertxbus')
$rootScope.$broadcast "#{prefix}system.login.failed", (status: reply?.status)
next.displayName = "#{CONSTANTS.MODULE}/#{CONSTANTS.COMPONENT}: util.login (callback)"
vertxEventBus.login username, password, next
$timeout (-> deferred.reject()), timeout
$interval (-> deferred.reject()), timeout, 1
return deferred.promise

util.registerHandler.displayName = "#{CONSTANTS.MODULE}/#{CONSTANTS.COMPONENT}: util.registerHandler"
Expand Down
10 changes: 8 additions & 2 deletions test/unit/angularVertxbusAdapterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,12 @@ describe('knalli.angular-vertxbus', function () {

describe('send() should call the error callback', function () {

var $interval;

beforeEach(inject(function (_$interval_) {
$interval = _$interval_; // angular.mock.$interval
}));

it('via promise.then()', function (done) {
var successCalled, errorCalled;
setTimeout(function () {
Expand All @@ -560,7 +566,7 @@ describe('knalli.angular-vertxbus', function () {
errorCalled = true;
});
setTimeout(function () {
$timeout.flush();
$interval.flush(20); // goto T+20
expect(successCalled).to.be(undefined);
expect(errorCalled).to.be(true);
done();
Expand All @@ -578,7 +584,7 @@ describe('knalli.angular-vertxbus', function () {
errorCalled = true;
});
setTimeout(function () {
$timeout.flush();
$interval.flush(20); // goto T+20
expect(successCalled).to.be(undefined);
expect(errorCalled).to.be(true);
done();
Expand Down