How to close a net.Server in Node.js tests?

The example works find, but when I replace server.listen(1234); with server.listen(1234, '127.0.0.1'); the test return the following error: "Error: Not running"

describe('Server', function() {
  it('should do something', function(done) {
    var server = new net.Server();
    server.listen(1234);

    // do something

    server.close();
    done();
  });
});

Can you explain to mw why?

That is because listen is asynchronous. It just happens that in the case where no second parameter is given, it opens synchronously enough that close doesn't fail. For that matter, close is also async.

it('should do something', function(done) {
  var server = new net.Server();
  server.listen(1234, '127.0.0.1', function(){
    // do something

    server.close(done);
  });
});