-
-
Save bendrucker/9961275 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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