title: How to correct the “connection.readyState” of mongoose in mocha from “connecting” to “connected?
body: <p>When I am trying to run the mocha test i am getting <strong>"Cannot determine state of server"</strong>
  since the mongoose connection is in connecting state.</p>
  
  <p>Please suggest how to handle this scenario.</p>
  
  <pre><code>var mongoose = require('mongoose');
  
  mongoose.connect('mongodb://localhost/test');
  
  console.log('conn ready:  '+mongoose.connection.readyState);
  
  // "conn ready: 2"  i.e connecting for test case as well as from user register form 
  
  
  var Schema = mongoose.Schema,
      ObjectId = Schema.ObjectId,
  
      UserSchema = new Schema({
  
         // schemas
  
      });
  
  
  UserSchema.statics.newUser = function (uname, email, pass) {
  
      var instance = new User();
  
      instance.uname  = uname;
  
      instance.email  = email;
  
      instance.pass   = pass;
  
      console.log("conn state: "+mongoose.connection.readyState); 
  
      // "conn state: 2"  i.e connecting for test case. But  1  i.e connected for  user register form 
  
      instance.save(function (err) {
        // Do rest
      });
  
  };
  
  var User = mongoose.model('User', UserSchema);
  exports.User = User;
  </code></pre>