Skip to content

Commit

Permalink
Update version
Browse files Browse the repository at this point in the history
  • Loading branch information
yadicksonbasedos committed Jan 28, 2019
1 parent bb3e444 commit ef456cf
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularjs-atmosphere",
"version": "1.1.0",
"version": "1.1.1",
"description": "Angular JS atmosphere wrapper",
"main": "dist/angularjs-atmosphere.js",
"dependencies": {
Expand Down
11 changes: 8 additions & 3 deletions src/angularjs-atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
close: close,
on: on,
off: off,
emit: emit
emit: emit,
request: request
};

function init(requestObj) {
Expand Down Expand Up @@ -53,8 +54,8 @@
}

function off(id) {
var type = listenerIndex[id];
var typeListeners = listeners[type];
var type = listenerIndex[id] || '';
var typeListeners = listeners[type] || [];
var removed = false;

for (var i = 0; i < typeListeners.length; i++) {
Expand Down Expand Up @@ -91,6 +92,10 @@
}
}

function request() {
return $.atmosphere.AtmosphereRequest();
}

}]);

})();
71 changes: 71 additions & 0 deletions test/angularjs-atmosphere-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,54 @@
expect(fn.called).to.be.false;
});

it('it should remove a function from the listeners object given an id with two registers', function() {
var fn = sinon.spy();
var fn2 = sinon.spy();

var key = atmosphereService.on('test', fn);
var key2 = atmosphereService.on('test2', fn2);

atmosphereService.off(key2);

atmosphereService.emit('test', 'test');
atmosphereService.emit('test2', 'test');

expect(!!key).to.be.true;
expect(fn.called).to.be.true;

expect(!!key2).to.be.true;
expect(fn2.called).to.be.false;
});

it('it emit json object a function from the listeners object given an id with two registers', function() {
var fn = sinon.spy();
var fn2 = sinon.spy();

var key = atmosphereService.on('test', fn);
var key2 = atmosphereService.on('test2', fn2);

atmosphereService.emit('test', angular.toJson('{"m":"test1"}'));
atmosphereService.emit('test2', angular.toJson('{"m":"test2"}'));

expect(!!key).to.be.true;
expect(fn.called).to.be.true;

expect(!!key2).to.be.true;
expect(fn2.called).to.be.true;
});

it('it remove a function is not present in the listeners object', function() {
var fn = sinon.spy();
var fn2 = sinon.spy();

var key = atmosphereService.on('test', fn);
var key2 = atmosphereService.on('test2', fn2);

var removed = atmosphereService.off(-1);

expect(removed).to.be.false;
});

it('should call all the functions for a given event on a response', function() {
var fn = sinon.spy();
var fn2 = sinon.spy();
Expand All @@ -60,6 +108,29 @@
expect(fn2.called).to.be.true;
});

it('should call all the functions for a different event on a response', function() {
var fn = sinon.spy();
var fn2 = sinon.spy();

var key = atmosphereService.on('test', fn);
var key2 = atmosphereService.on('test2', fn2);

atmosphereService.emit('test', 'test');

expect(!!key).to.be.true;
expect(!!key2).to.be.true;

expect(fn.called).to.be.true;
expect(fn2.called).to.be.false;
});

it('call default request', function() {

var request = atmosphereService.request();

expect(!!request).to.be.true;
});

});

})();

0 comments on commit ef456cf

Please sign in to comment.