Skip to content

Commit

Permalink
fix(usPhoneNumber): fix validation issues on us phone number
Browse files Browse the repository at this point in the history
* Fix validation issues

* Add test case for validation of US phone number

Model value is added as a number which ensures it can validate (which
is what this PR is for). I noticed other tests are adding the phone
number as a string (in br-phone.test.js), which probably defeats the
test.

* Fix mixed tabs and spaces which prevents tests from passing
  • Loading branch information
houmark authored and assisrafael committed Aug 27, 2016
1 parent 65c7f2b commit 2ea6056
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/us/phone/us-phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = maskFactory({
},
validations: {
usPhoneNumber: function(value) {
return value.length > 9;
return value && value.toString().length > 9;
}
}
});
13 changes: 13 additions & 0 deletions src/us/phone/us-phone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ describe('ui-us-phone-mask', function() {
expect(model.$modelValue).toBe(test.modelValue);
});
});

it('should validate a phone number', function() {
var input = TestUtil.compile('<input ng-model="model" ui-us-phone-number>', {
model: 30112
});
var model = input.controller('ngModel');
expect(model.$valid).toBe(false);
expect(model.$error.usPhoneNumber).toBe(true);
input.val(3011201034).triggerHandler('input');
expect(model.$valid).toBe(true);
expect(model.$error.usPhoneNumber).toBeUndefined();
});

});

0 comments on commit 2ea6056

Please sign in to comment.