Skip to content

Commit

Permalink
test(document): repro #4885
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 22, 2017
1 parent 5140e62 commit e01527c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,24 @@ describe('document', function() {
});
});

it('validate errors (gh-4885)', function(done) {
var testSchema = new Schema({ title: { type: String, required: true } });

var called = 0;
testSchema.post('validate', function(error, doc, next) {
++called;
next(error);
});

var Test = db.model('gh4885', testSchema);

Test.create({}, function(error) {
assert.ok(error);
assert.equal(called, 1);
done();
});
});

it('handles non-errors', function(done) {
var schema = new Schema({
name: { type: String, required: true }
Expand Down
18 changes: 18 additions & 0 deletions test/query.middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ describe('query middleware', function() {
});
});

it('error handlers for validate (gh-4885)', function(done) {
var testSchema = new Schema({ title: { type: String, required: true } });

var called = 0;
testSchema.post('validate', function(error, doc, next) {
++called;
next(error);
});

var Test = db.model('gh4885', testSchema);

Test.create({}, function(error) {
assert.ok(error);
assert.equal(called, 1);
done();
});
});

it('error handlers with findOneAndUpdate and passRawResult (gh-4836)', function(done) {
var schema = new Schema({name: {type: String}});

Expand Down

0 comments on commit e01527c

Please sign in to comment.