title: Mockgoose: how to simulate a error in mongoose?
body: <p>I am trying to do unit test around a mongoose powered application.
  While mockgoose does a great work at simulating mongoose so I can test around it, I didn t find a way to push it to fail a call, so I can test the error handling logic.</p>
  
  <p>Is it a supported use case? Or should I find another framework?</p>
  
  <p>Code:</p>
  
  <pre><code>var mongoose = require('mongoose');
  
  var Test = {},
      Doc = require('./model/Doc.js');
  
  var dbURL = 'mongodb://127.0.0.1/',
      dbName = 'Test';
  
  function connect(callback) {
      Test = mongoose.createConnection(dbURL + dbName); //&lt;-- Push this to fail
      Test.on('error', (err) =&gt; {
          callback(err);
      });
      Test.once('open', function () {
          callback();
      }); 
  }
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>var chai = require('chai'),
      expect = chai.expect,
      util = require('util');
  
  var config = require('./config.json');
  
  var proxyquire =  require('proxyquire').noPreserveCache();
  var sinon = require('sinon');
  var mongoose = require('mongoose');
  var mockgoose = require('mockgoose');
  
  describe('test', () =&gt; {
      describe('Connect', () =&gt; {
          beforeEach((callback) =&gt; {
              mockgoose(mongoose).then(() =&gt; {
                  callback();
              });
          });
  
          it('Expect to connect to the database', (done) =&gt; {
              var stub = {
                      mongoose: mongoose
                  },
                  test = proxyquire('./../test.js', {
                      'mongoose': stub.mongoose
                  });
  
              test.connect((err) =&gt; {
                  try {
                      expect(err).to.not.be.ok;
                      done();
                  } catch(err) {
                      done(err);
                  }
              });
  
          it('Expect to throw error when failing to connect to the database', (done) =&gt; {
              var stub = {
                      mongoose: mongoose
                  },
                  medical = proxyquire('./../medical.js', {
                      'mongoose': stub.mongoose
                  });
  
              medical.connect((err) =&gt; {
                  try {
                      expect(err).to.be.ok;
                      done();
                  } catch(err) {
                      done(err);
                  }
              });
          });
      });
  });
  </code></pre>
  
  <p>Result in:</p>
  
  <pre><code>Connect
        ✓ Expect to connect to the database
        1) Expect to throw error when failing to connect to the database
  
  
    1 passing (234ms)
    1 failing
  
    1) Medical Connect Expect to throw error when failing to connect to the database:
       AssertionError: expected undefined to be truthy
  </code></pre>