Skip to content

Commit

Permalink
Added test suite + of method on the namespace so we have a simular ap…
Browse files Browse the repository at this point in the history
…i on the client

as we would have on the server.
  • Loading branch information
3rd-Eden committed Jul 3, 2011
1 parent f41d213 commit ca5d229
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@

SocketNamespace.prototype.$emit = io.EventEmitter.prototype.emit;

/**
* Creates a new namespace, by proxying the request to the socket. This
* allows us to use the synax as we do on the server.
*
* @api public
*/

SocketNamespace.prototype.of = function () {
return this.socket.of.apply(this.socket, arguments);
};

/**
* Sends a packet.
*
Expand Down
6 changes: 6 additions & 0 deletions support/test-runner/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ suite('socket.test.js', function () {
});
});

server('test different namespace connection methods', function (io) {
io.of('/a').on('connection', function (socket) {});
io.of('/b').on('connection', function (socket) {});
io.of('/c').on('connection', function (socket) {});
});

server('test disconnecting from namespaces', function (io) {
io.of('/a').on('connection', function (socket) {});
io.of('/b').on('connection', function (socket) {});
Expand Down
31 changes: 31 additions & 0 deletions test/socket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,37 @@

},

'test different namespace connection methods': function (next) {
var io = create('/a')
, connect = 0
, socket = io.socket;

function finish () {
socket.of('').disconnect();
connect.should().equal(3);
next();
}

io.on('connect', function () {
if (++connect === 3) finish();
}).on('error', function (msg) {
throw new Error(msg || 'Received an error');
});

socket.of('/b').on('connect', function () {
if (++connect === 3) finish();
}).on('error', function (msg) {
throw new Error(msg || 'Received an error');
});

io.of('/c').on('connect', function () {
if (++connect === 3) finish();
}).on('error', function (msg) {
throw new Error(msg || 'Received an error');
});

},

'test disconnecting from namespaces': function (next) {
var socket = create().socket
, namespaces = 2
Expand Down

0 comments on commit ca5d229

Please sign in to comment.