Skip to content

Commit 359cfa5

Browse files
Christophe KrebserCameron Knight
Christophe Krebser
authored and
Cameron Knight
committed
test(input): test that input[email"] and ngRequired don't interfere w/ eachother
ngRequired added to an email field wasn't working properly. ng-invalid-required stayed true unless a valid email was entered. correct behaviour is that it turns to ng-valid-required at first entered key. Closes angular#7849
1 parent dd5ff8a commit 359cfa5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/ng/directive/inputSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ describe('ngModel', function() {
486486
expect(element).toHaveClass('ng-invalid-required');
487487
}));
488488

489+
489490
it('should set the control touched state on "blur" event', inject(function($compile, $rootScope) {
490491
var element = $compile('<form name="myForm">' +
491492
'<input name="myControl" ng-model="value" >' +
@@ -2718,6 +2719,16 @@ describe('input', function() {
27182719
});
27192720

27202721

2722+
it('should set $valid even if model fails other validators', function() {
2723+
compileInput('<input type="email" ng-model="value" required />');
2724+
changeInputValueTo('bademail');
2725+
2726+
expect(inputElm).toHaveClass('ng-valid-required');
2727+
expect(inputElm.controller('ngModel').$error.required).toBe(false);
2728+
expect(inputElm).toBeInvalid(); // invalid because of the email validator
2729+
});
2730+
2731+
27212732
it('should allow `false` as a valid value when the input type is not "checkbox"', function() {
27222733
compileInput('<input type="radio" ng-value="true" ng-model="answer" required />' +
27232734
'<input type="radio" ng-value="false" ng-model="answer" required />');

0 commit comments

Comments
 (0)