Skip to content

Commit cc28ee8

Browse files
committed
test: removeAllListeners
1 parent caea7ac commit cc28ee8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

mock/socket-io.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ function createMockSocketObject () {
3232
} else {
3333
delete this._listeners[ev];
3434
}
35-
}
35+
},
36+
removeAllListeners: function (ev) {
37+
if (ev) {
38+
delete this._listeners[ev];
39+
} else {
40+
this._listeners = {};
41+
}
42+
},
3643
};
3744

3845
return socket;

socket.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,31 @@ describe('socketFactory', function () {
121121
});
122122

123123

124+
describe('#removeAllListeners', function () {
125+
126+
it('should not call after removing listeners for an event', function () {
127+
socket.on('event', spy);
128+
socket.removeAllListeners('event');
129+
130+
mockIoSocket.emit('event');
131+
132+
expect($browser.deferredFns.length).toBe(0);
133+
});
134+
135+
it('should not call after removing all listeners', function () {
136+
socket.on('event', spy);
137+
socket.on('event2', spy);
138+
socket.removeAllListeners();
139+
140+
mockIoSocket.emit('event');
141+
mockIoSocket.emit('event2');
142+
143+
expect($browser.deferredFns.length).toBe(0);
144+
});
145+
146+
});
147+
148+
124149
describe('#forward', function () {
125150

126151
it('should forward events', function () {

0 commit comments

Comments
 (0)