不要怂,就是干,撸起袖子干!

Commit def14aac by Mick Hansen

unit test that unique constraints are actual errors

1 parent e43b9db1
Showing with 26 additions and 0 deletions
...@@ -154,6 +154,32 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -154,6 +154,32 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should return an error for a unique constraint error', function (done) {
var User = this.sequelize.define('User', {
'email': {
type: DataTypes.STRING,
unique: { name: 'email', msg: 'Email is already registered.' },
validate: {
notEmpty: true,
isEmail: true
}
}
})
this.sequelize.sync({force: true}).done(function (err) {
expect(err).not.to.be.ok
User.create({email: 'hello@sequelize.com'}).done(function (err) {
expect(err).not.to.be.ok
User.create({email: 'hello@sequelize.com'}).done(function (err) {
expect(err).to.be.ok
console.log(err)
expect(err).to.be.an.instanceof(Error)
done()
})
})
})
})
it('supports transactions', function(done) { it('supports transactions', function(done) {
var self = this var self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!