title: Is it possible to test socket.io app with Mocha
body: <p>I have a Node.js with Socket.io server. So I want to write tests with Mocha to improve development. I've googled a lot to find anything about testing socket.io server with Mocha and all  I found is <a href="http://liamkaufman.com/blog/2012/01/28/testing-socketio-with-mocha-should-and-socketio-client/" rel="nofollow">http://liamkaufman.com/blog/2012/01/28/testing-socketio-with-mocha-should-and-socketio-client/</a></p>
  
  <p>But there are Server and Tests under Mocha's test directory and both starts with Mocha, when I already have working Server and just want to test it.</p>
  
  <p>So i wrote next code:</p>
  
  <pre>
  <code>
  
      var assert = require("assert"),
        should = require('should'),
        io = require('socket.io-client'),
        socketURL = 'http://localhost:3102',
        options ={
        transports: ['websocket'],
        'force new connection': true,
        'reconnection delay' : 0,
        'reopen delay' : 0
        };
      describe('Server', function(){
        var socket;
        beforeEach(function(done) {
          // Setup
          console.log('Establishing connection');
          socket = io.connect(socketURL, options);
  
          socket.on('connect', function() {
            console.log('worked...');
            done();
          });
      });
      ...
        it('should receive messages', function(done){
          socket.on('message', function(data){
            console.log('received');
            done();
          });
      ...
      })
  
  </code></pre>
  
  <p>And the result is:</p>
  
  <pre>
  <code>
  
      Server
      Establishing connection
          1) "before each" hook
  
        0 passing (2s)
        1 failing
  
        1) Server "before each" hook:
           Error: timeout of 2000ms exceeded
            at null. (\npm\node_modules\mocha\lib\runnable.js:139:19)
            at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
  
  </code>
  </pre>
  
  <p>I've checked server's log and there's no connections.. nothing. It doesn't even tried to connect to server.</p>
  
  <p>So I wonder if it's possible to do the tests with Mocha in this way? When you have complete working server and trying to test request-response functionality.</p>