Last active
August 29, 2015 14:11
-
-
Save nidate/0311382784f7895d13a6 to your computer and use it in GitHub Desktop.
Replace method by sinon.stub for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sinon = require 'sinon' | |
MongooseModel = require 'mongoosemodeldefinition' | |
describe 'when the mongoose document failed to save', ()-> | |
stub = null | |
before (done)-> | |
origSave = MongooseModel.prototype.save | |
createCount = 0 | |
stub = sinon.stub MongooseModel.prototype, 'save', (cb)-> | |
createCount += 1 | |
if createCount > 3 | |
return cb new Error 'Cannot create greater than 3 documents' | |
origSave.apply this, arguments | |
do done | |
after (done)-> | |
stub.restore() | |
do done | |
it '(write test...)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment