title: Not able to assert that mongoose save function was called in a unit test
body: <p>I've looked through several posts related to unit testing mocha/sinon with mongoose but I still haven't gotten it to work to verify that the save method is called on my mongoose model. I want to test that order.save was called in my controller. The error I get is that order.save is not a function in the production code orderController.js.</p>
  
  <p>I've tried a few different ways but I haven't been able to assert that save is called.</p>
  
  <p>A simple model:</p>
  
  <p><strong>orderModel.js</strong></p>
  
  <pre><code>const mongoose = require('mongoose'),
      Schema = mongoose.Schema;
  
  const orderModel = new Schema({
      location: {type: String},
      cost: {type: Number},
      status: {type: String, default: 'unpaid'}
  });
  
  module.exports = mongoose.model('Order', orderModel);
  
  The controller is the production code that I want to test
  orderController.js
  var orderController = function (Order) {
  
      var post = function (req, res) {
          var order = new Order();
          order.save();
          res.status(201);
      }
  
      return {
          post: post
      }
  }
  
  module.exports = orderController;
  </code></pre>
  
  <p>This is the spec file. I want to verify that save was called, it doesn't matter if it's a stub, spy or a mock. I just haven't been able to assert after the call to ctrl.post that it was called</p>
  
  <p><strong>orderController.spec.js</strong></p>
  
  <pre><code>var sinon = require('sinon'),
  chai = require('chai'),
  expect = chai.expect,
  mongoose = require('mongoose');
  
  describe('Order Controller', function() {
  
      it('should save an order', function() {
          var Order = require('../../app/models/orderModel');
          var orderStub = sinon.stub(Order.prototype, 'save');
          var ctrl = require('../../app/controllers/orderController')(orderStub);
  
          var req, res;
          req = res = {};
          res.status = sinon.spy();
          ctrl.post(req, res);
          sinon.assert.called(orderStub.prototype.save);
      });
  });
  </code></pre>