Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Forked from martinaglv/test.js
Last active August 29, 2015 13:58
Show Gist options
  • Save bendrucker/9961275 to your computer and use it in GitHub Desktop.
Save bendrucker/9961275 to your computer and use it in GitHub Desktop.
var sinon = require('sinon');
var Promise = require('bookshelf/dialects/base/promise').Promise;
var Bookshelf = require('bookshelf');
var unhandled = sinon.spy();
var caught = sinon.spy();
Promise.onPossiblyUnhandledRejection(unhandled);
var MySql = Bookshelf.initialize({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'root',
password : '',
database : 'testdb',
charset : 'utf8'
}
});
var User = MySql.Model.extend({
tableName: 'users',
initialize: function(){
this.on('saving', validate);
}
});
var validate = function (){
throw new Error('this is always thrown!');
};
new User().save().catch(caught).finally(function () {
console.log(unhandled.called); // => false
});
process.nextTick(function () {
console.log(caught.called) // => true
console.log(unhandled.called); // => true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment