Skip to content

Instantly share code, notes, and snippets.

@bulkan
Created January 7, 2015 22:39
Show Gist options
  • Save bulkan/39290b0e4cb9fc76082d to your computer and use it in GitHub Desktop.
Save bulkan/39290b0e4cb9fc76082d to your computer and use it in GitHub Desktop.
Mocking Sequelize model function
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');
})
})
})
@walshe
Copy link

walshe commented May 17, 2017

any chance you could show an example of a sequelize create(obj) method that returns normally with success ?

@peterkingsbury
Copy link

peterkingsbury commented Aug 23, 2017

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