Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0b8461c

Browse files
committed
test(validators): minlength and required must use viewValue in $isEmpty
1 parent abd8e2a commit 0b8461c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/ng/directive/validatorsSpec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ describe('validators', function() {
254254
expect($rootScope.value).toBe(12345);
255255
expect($rootScope.form.input.$error.minlength).toBeUndefined();
256256
});
257+
258+
it('should validate emptiness against the viewValue', function() {
259+
var inputElm = helper.compileInput('<input type="text" name="input" ng-model="value" minlength="3" />');
260+
261+
var ctrl = inputElm.controller('ngModel');
262+
spyOn(ctrl, '$isEmpty').andCallThrough();
263+
264+
ctrl.$parsers.push(function(value) {
265+
return value + '678';
266+
});
267+
268+
helper.changeInputValueTo('12345');
269+
expect(ctrl.$isEmpty).toHaveBeenCalledWith('12345');
270+
});
257271
});
258272

259273

@@ -517,5 +531,19 @@ describe('validators', function() {
517531
$rootScope.$apply("answer = false");
518532
expect(inputElm).toBeValid();
519533
});
534+
535+
it('should validate emptiness against the viewValue', function() {
536+
var inputElm = helper.compileInput('<input type="text" name="input" ng-model="value" required />');
537+
538+
var ctrl = inputElm.controller('ngModel');
539+
spyOn(ctrl, '$isEmpty').andCallThrough();
540+
541+
ctrl.$parsers.push(function(value) {
542+
return value + '678';
543+
});
544+
545+
helper.changeInputValueTo('12345');
546+
expect(ctrl.$isEmpty).toHaveBeenCalledWith('12345');
547+
});
520548
});
521549
});

0 commit comments

Comments
 (0)