Skip to content

Commit

Permalink
add another validate() test
Browse files Browse the repository at this point in the history
shows calling validate() directly does not save
  • Loading branch information
aheckmann committed Mar 18, 2011
1 parent 79c876e commit 3bfd22c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/model.test.js
Expand Up @@ -831,6 +831,34 @@ module.exports = {
});
},

'test validation without saving': function(){

mongoose.model('TestCallingValidation', new Schema({
item: { type: String, required: true }
}));

var db = start()
, TestCallingValidation = db.model('TestCallingValidation');

var post = new TestCallingValidation;

should.strictEqual(post.isNew, true);

post.validate(function(err){
err.should.be.an.instanceof(MongooseError);
err.should.be.an.instanceof(ValidatorError);
should.strictEqual(post.isNew, true);

post.item = 'yo';
post.validate(function(err){
should.equal(err, null);
should.strictEqual(post.isNew, true);
db.close();
});
});

},

'test defaults application': function(){
var now = Date.now();

Expand Down

0 comments on commit 3bfd22c

Please sign in to comment.