title: How to unit test a method which connects to mongo, without actually connecting to mongo?
body: <p>I'm trying to write a test to test a method that connects to mongo, but I don't actually want to have to have mongo running and actually make a connection to it to have my tests pass successfully.</p>
  
  <p>Here's my current test which is successful when my mongo daemon is running.</p>
  
  <pre><code>describe('with a valid mongo string parameter', function() {
      it('should return a rejected promise', function(done) {
          var con = mongoFactory.getConnection('mongodb://localhost:27017');
          expect(con).to.be.fulfilled;
          done();
      });
  });
  </code></pre>
  
  <p>mongoFactory.getConnection code:</p>
  
  <pre><code>getConnection: function getConnection(connectionString) {
  
        // do stuff here
  
          // Initialize connection once
          MongoClient.connect(connectionString, function(err, database) {
            if (err) {
              def.reject(err);
            }
  
            def.resolve(database);
          });
  
        return def.promise;
      }
  </code></pre>