Created
January 7, 2015 22:39
-
-
Save bulkan/39290b0e4cb9fc76082d to your computer and use it in GitHub Desktop.
Mocking Sequelize model function
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
var Promise = require('bluebird'); | |
var sinon = require('sinon'); | |
var User = require('./db/models').User; | |
describe('User model', function(){ | |
var userFindStub; | |
var sandbox; | |
before(function(){ | |
sandbox = sinon.sandbox.create(); | |
userFindStub = sanbox.stub(User, 'find'); | |
}) | |
it('should catch', function(){ | |
userFindStub.returns(Promise.reject(new Error('test-error'))) | |
return User.find({}) | |
.catch(function(err){ | |
should.exist(err); | |
err.message.should.equal('test-error'); | |
}) | |
}) | |
}) |
Line #11 contains a typo in sandbox
(i.e. sanbox
).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any chance you could show an example of a sequelize create(obj) method that returns normally with success ?