Skip to content

Commit

Permalink
[draft] add console.warn in emit prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
hugohil committed Nov 24, 2016
1 parent fa14f91 commit 00eba0e
Show file tree
Hide file tree
Showing 4 changed files with 6,090 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
/node_modules
/coverage
npm-debug.log
1 change: 1 addition & 0 deletions lib/socket.js
Expand Up @@ -134,6 +134,7 @@ Socket.prototype.send = function () {
Socket.prototype.emit = function (ev) {
if (events.hasOwnProperty(ev)) {
emit.apply(this, arguments);
console.warn(`${ev} is a reserved internal event.`);
return this;
}

Expand Down
9 changes: 9 additions & 0 deletions test/socket.js
Expand Up @@ -108,4 +108,13 @@ describe('socket', function () {
socket3.disconnect();
done();
});

it('should not be able to emit internals events', function (done) {
var socket = io({ forceNew: true });
var events = ['connect', 'connect_error', 'connect_timeout', 'connecting', 'disconnect', 'error', 'reconnect', 'reconnect_attempt', 'reconnect_failed', 'reconnect_error', 'reconnecting', 'ping'];
events.forEach((event) => {
socket.emit(event);
expect(console.warn.calledWith(`${event} is a reserved internal event.`)).to.be.true;
});
});
});

0 comments on commit 00eba0e

Please sign in to comment.