Skip to content

Instantly share code, notes, and snippets.

@parkerproject
Forked from bulkan/user.js
Created March 15, 2018 02:51
Show Gist options
  • Save parkerproject/782eeda0a5aef149808cb4a103298219 to your computer and use it in GitHub Desktop.
Save parkerproject/782eeda0a5aef149808cb4a103298219 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');
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment