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

Commit b7eb0a5

Browse files
committed
test(validators): min/maxlength validate the viewValue, not collection items
1 parent 0095b27 commit b7eb0a5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/ng/directive/validatorsSpec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,25 @@ describe('validators', function() {
319319
expect(ctrl.$error.minlength).toBe(true);
320320
expect(ctrlNg.$error.minlength).toBe(true);
321321
}));
322+
323+
describe('collection validation', function() {
324+
325+
it('should validate the viewValue and not the individual values', function() {
326+
var inputElm = helper.compileInput('<input type="text" minlength="10" ng-list ng-model="list">');
327+
var ctrl = inputElm.controller('ngModel');
328+
spyOn(ctrl.$validators, 'minlength').andCallThrough();
329+
330+
helper.changeInputValueTo('2,2');
331+
expect(inputElm).toBeInvalid();
332+
expect(ctrl.$error.minlength).toBe(true);
333+
expect(ctrl.$validators.minlength.calls[0].args).toEqual([['2','2'], '2,2']);
334+
335+
helper.changeInputValueTo('20000,20000');
336+
expect(inputElm).toBeInvalid();
337+
expect(ctrl.$error.minlength).toBe(false);
338+
});
339+
});
340+
322341
});
323342

324343

@@ -507,6 +526,24 @@ describe('validators', function() {
507526
expect(ctrl.$error.maxlength).toBe(true);
508527
expect(ctrlNg.$error.maxlength).toBe(true);
509528
}));
529+
530+
describe('collection validation', function() {
531+
532+
it('should validate the viewValue and not the individual values', function() {
533+
var inputElm = helper.compileInput('<input type="text" maxlength="10" ng-list ng-model="list">');
534+
var ctrl = inputElm.controller('ngModel');
535+
spyOn(ctrl.$validators, 'maxlength').andCallThrough();
536+
537+
helper.changeInputValueTo('2,2');
538+
expect(inputElm).toBeValid();
539+
expect(ctrl.$error.maxlength).toBeFalsy();
540+
expect(ctrl.$validators.maxlength.calls[0].args).toEqual([['2','2'], '2,2']);
541+
542+
helper.changeInputValueTo('20000,20000');
543+
expect(inputElm).toBeInvalid();
544+
expect(ctrl.$error.maxlength).toBe(true);
545+
});
546+
});
510547
});
511548

512549

0 commit comments

Comments
 (0)