Skip to content
Open
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
2 changes: 2 additions & 0 deletions mock/socket-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ function createMockSocketObject () {
var socket = {
on: function (ev, fn) {
(this._listeners[ev] = this._listeners[ev] || []).push(fn);
return this;
},
once: function (ev, fn) {
(this._listeners[ev] = this._listeners[ev] || []).push(fn);
fn._once = true;
return this;
},
emit: function (ev, data) {
if (this._listeners[ev]) {
Expand Down
4 changes: 2 additions & 2 deletions socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ angular.module('btford.socket-io', []).
var defaultScope = options.scope || $rootScope;

var addListener = function (eventName, callback) {
socket.on(eventName, callback.__ng = asyncAngularify(socket, callback));
return socket.on(eventName, callback.__ng = asyncAngularify(socket, callback));
};

var addOnceListener = function (eventName, callback) {
socket.once(eventName, callback.__ng = asyncAngularify(socket, callback));
return socket.once(eventName, callback.__ng = asyncAngularify(socket, callback));
};

var wrappedSocket = {
Expand Down
15 changes: 15 additions & 0 deletions socket.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ describe('socketFactory', function () {
expect(spy).toHaveBeenCalled();
});

it('should add listeners in chain', function () {
var counter = 0,
func = function () {
counter += 1;
};

socket.on('event1', func)
.on('event2', func);

mockIoSocket.emit('event1');
mockIoSocket.emit('event2');
$timeout.flush();

expect(counter).toBe(2);
});
});


Expand Down