Stubbing a Mongoose model with Sinon
问题 I want to create a stub for the Mongoose save method in a particular model, so that any instance of my model I create will call the stub instead of the normal Mongoose save method. My understanding is that the only way to do this is to stub the entire model like this: var stub = sinon.stub(myModel.prototype); Unfortunately, this line of code causes my tests to throw the following error: TypeError: Cannot read property 'states' of undefined Does anyone know what is going wrong here? 回答1: There