Permalink
Browse files

Merge pull request #48 from ben-ng/master

Add unit test for #47
  • Loading branch information...
2 parents 3ac5c8d + f1a1977 commit 2951dc9626f6c414c118c00c356a4bc9ce58828a @mde mde committed Mar 23, 2013
Showing with 16 additions and 1 deletion.
  1. +1 −1 lib/validators.js
  2. +15 −0 test/validators.js
View
@@ -34,7 +34,7 @@ var validators = {
present: function (name, val, params, rule, locale) {
var msg;
// Empty string, null/undefined (null is double-equal to undefined)
- if (val === '' || val === undefined) {
+ if (val === '' || val == undefined) {
//'Field "' + name + '" is required.';
msg = rule.message || i18n.getText('model.validatesPresent',
{name: name}, locale);
View
@@ -24,6 +24,21 @@ tests = {
requiredPropertyAddedByProperty.validations.present);
}
+, 'Validating present with 0': function () {
+ var msg = validators.present('foo', 0, null, {qualifier:true});
+ assert.ok(!msg);
+ }
+
+, 'Validating present with null': function () {
+ var msg = validators.present('foo', null, null, {qualifier:true});
+ assert.equal('[[model.validatesPresent]]', msg);
+ }
+
+, 'Validating present with undefined': function () {
+ var msg = validators.present('foo', undefined, null, {qualifier:true});
+ assert.equal('[[model.validatesPresent]]', msg);
+ }
+
, 'Validating exact length with incorrect length': function () {
var msg = validators.length('foo', '1111', null, {qualifier: 3});
assert.equal('[[model.validatesExactLength]]', msg);

0 comments on commit 2951dc9

Please sign in to comment.