Skip to content

Commit

Permalink
Changing false validations to return invalid value so that they can b…
Browse files Browse the repository at this point in the history
…e used. Adding tests. This is an addition to PR angular-ui#149
  • Loading branch information
Matt M committed Feb 1, 2014
1 parent 32cf1e0 commit 4263c27
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/validate/test/validateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ describe('uiValidate', function () {
expect(scope.form.input.$valid).toBeFalsy();
expect(scope.form.input.$error).toEqual({ validator: true });
}));

it('should keep the invalid value in model if it is marked as invalid', inject(function () {

var testValue = 'test123';
scope.value = testValue;
scope.validate = falseValidator;
var inputElm = compileAndDigest('<input name="input" ng-model="value" ui-validate="\'validate($value)\'">', scope);
expect(scope.form.input.$valid).toBeFalsy();
expect(scope.value).toEqual(testValue);
expect(inputElm.val()).toEqual(testValue);
}));
});

describe('validation on model change', function () {
Expand Down Expand Up @@ -96,6 +107,19 @@ describe('uiValidate', function () {
expect(scope.form.input.$error.key1).toBeFalsy();
expect(scope.form.input.$error.key2).toBeTruthy();
});

it('should show subsequent validation errors as false if the first of multiple validators fails, but the other validations do not fail', function () {

scope.validate1 = falseValidator;
scope.validate2 = trueValidator;
scope.validate3 = trueValidator;

compileAndDigest('<input name="input" ng-model="value" ui-validate="{key1 : \'validate1($value)\', key2 : \'validate2($value)\', key3 : \'validate2($value)\'}">', scope);
expect(scope.form.input.$valid).toBeFalsy();
expect(scope.form.input.$error.key1).toBeTruthy();
expect(scope.form.input.$error.key2).toBeFalsy();
expect(scope.form.input.$error.key3).toBeFalsy();
});
});

describe('uiValidateWatch', function(){
Expand Down

0 comments on commit 4263c27

Please sign in to comment.