Browse files

Added test suite + of method on the namespace so we have a simular ap…

…i on the client

as we would have on the server.
  • Loading branch information...
1 parent f41d213 commit ca5d229508a103f00ce762b677b733ab02a568d3 @3rd-Eden 3rd-Eden committed Jul 3, 2011
Showing with 48 additions and 0 deletions.
  1. +11 −0 lib/namespace.js
  2. +6 −0 support/test-runner/app.js
  3. +31 −0 test/socket.test.js
View
11 lib/namespace.js
@@ -43,6 +43,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.
*
* @api private
View
6 support/test-runner/app.js
@@ -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) {});
View
31 test/socket.test.js
@@ -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

0 comments on commit ca5d229

Please sign in to comment.