async-validate
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -18,3 +18,3 @@ var util = require('util'); | ||
&& (!source.hasOwnProperty(rule.field) | ||
|| value === undefined)) { | ||
|| value === undefined || value === null)) { | ||
errors.push(error(rule, | ||
@@ -21,0 +21,0 @@ util.format(options.messages.required, rule.field))); |
{ | ||
"name": "async-validate", | ||
"description": "Asynchronous validation for object properties.", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -50,2 +50,14 @@ var util = require('util'); | ||
}); | ||
test("validate a required string field (null)", function() { | ||
var descriptor = { | ||
name: {type: "string", required: true} | ||
} | ||
var validator = new schema(descriptor); | ||
validator.validate({name: null}, function(errors, fields) { | ||
assert.equal(errors.length, 1); | ||
assert.equal(errors[0].message, "name is required"); | ||
assert.equal(fields.name.length, 1); | ||
assert.isTrue((fields.name[0] instanceof ValidationError)); | ||
}); | ||
}); | ||
test("validate a field of type string is of the correct type", function() { | ||
@@ -52,0 +64,0 @@ var descriptor = { |
75931
1757