Created
March 7, 2014 01:12
-
-
Save bendrucker/9403147 to your computer and use it in GitHub Desktop.
halting events in bookshelf
This file contains 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
module.exports = Bookshelf.Model.extend({ | |
initialize: function () { | |
this.on('saving', this.validate); | |
}, | |
validate: function () {} | |
}); |
This file contains 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
describe('Model events', function () { | |
var model; | |
beforeEach(function () { | |
model = new Model(); | |
}); | |
it('should permit saving by default', function () { | |
return model.save(); | |
}); | |
it('halts saving if validation throws', function () { | |
var err = new Error(); | |
sinon.stub(model.validate).throws(err); | |
return expect(model.save()) | |
.to.be.rejectedWith(err); | |
}); | |
it('halts saving if the validation returns a rejected promise', function () { | |
var err = new Error(); | |
sinon.stub(model.validate).returns(Promise.reject(err)); | |
return expect(model.save()) | |
.to.be.rejectedWith(err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment