Skip to content

Commit c9899c5

Browse files
committed
test(ngModel): group validation tests
1 parent 4d4e603 commit c9899c5

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

test/ng/directive/inputSpec.js

+51-48
Original file line numberDiff line numberDiff line change
@@ -484,72 +484,75 @@ describe('NgModelController', function() {
484484

485485
});
486486

487-
describe('validations pipeline', function() {
487+
describe('validation', function() {
488488

489-
it('should perform validations when $validate() is called', function() {
490-
scope.$apply('value = ""');
491-
492-
var validatorResult = false;
493-
ctrl.$validators.someValidator = function(value) {
494-
return validatorResult;
495-
};
496-
497-
ctrl.$validate();
489+
describe('$validate', function() {
490+
it('should perform validations when $validate() is called', function() {
491+
scope.$apply('value = ""');
498492

499-
expect(ctrl.$valid).toBe(false);
493+
var validatorResult = false;
494+
ctrl.$validators.someValidator = function(value) {
495+
return validatorResult;
496+
};
500497

501-
validatorResult = true;
502-
ctrl.$validate();
498+
ctrl.$validate();
503499

504-
expect(ctrl.$valid).toBe(true);
505-
});
500+
expect(ctrl.$valid).toBe(false);
506501

507-
it('should always perform validations using the parsed model value', function() {
508-
var captures;
509-
ctrl.$validators.raw = function() {
510-
captures = arguments;
511-
return captures[0];
512-
};
502+
validatorResult = true;
503+
ctrl.$validate();
513504

514-
ctrl.$parsers.push(function(value) {
515-
return value.toUpperCase();
505+
expect(ctrl.$valid).toBe(true);
516506
});
517507

518-
ctrl.$setViewValue('my-value');
508+
describe('view -> model update', function() {
509+
it('should always perform validations using the parsed model value', function() {
510+
var captures;
511+
ctrl.$validators.raw = function() {
512+
captures = arguments;
513+
return captures[0];
514+
};
519515

520-
expect(captures).toEqual(['MY-VALUE', 'my-value']);
521-
});
516+
ctrl.$parsers.push(function(value) {
517+
return value.toUpperCase();
518+
});
522519

523-
it('should always perform validations using the formatted view value', function() {
524-
var captures;
525-
ctrl.$validators.raw = function() {
526-
captures = arguments;
527-
return captures[0];
528-
};
520+
ctrl.$setViewValue('my-value');
529521

530-
ctrl.$formatters.push(function(value) {
531-
return value + '...';
522+
expect(captures).toEqual(['MY-VALUE', 'my-value']);
532523
});
533524

534-
scope.$apply('value = "matias"');
525+
it('should always perform validations using the formatted view value', function() {
526+
var captures;
527+
ctrl.$validators.raw = function() {
528+
captures = arguments;
529+
return captures[0];
530+
};
535531

536-
expect(captures).toEqual(['matias', 'matias...']);
537-
});
532+
ctrl.$formatters.push(function(value) {
533+
return value + '...';
534+
});
538535

539-
it('should only perform validations if the view value is different', function() {
540-
var count = 0;
541-
ctrl.$validators.countMe = function() {
542-
count++;
543-
};
536+
scope.$apply('value = "matias"');
544537

545-
ctrl.$setViewValue('my-value');
546-
expect(count).toBe(1);
538+
expect(captures).toEqual(['matias', 'matias...']);
539+
});
547540

548-
ctrl.$setViewValue('my-value');
549-
expect(count).toBe(1);
541+
it('should only perform validations if the view value is different', function() {
542+
var count = 0;
543+
ctrl.$validators.countMe = function() {
544+
count++;
545+
};
550546

551-
ctrl.$setViewValue('your-value');
552-
expect(count).toBe(2);
547+
ctrl.$setViewValue('my-value');
548+
expect(count).toBe(1);
549+
550+
ctrl.$setViewValue('my-value');
551+
expect(count).toBe(1);
552+
553+
ctrl.$setViewValue('your-value');
554+
expect(count).toBe(2);
555+
});
553556
});
554557

555558
it('should perform validations twice each time the model value changes within a digest', function() {

0 commit comments

Comments
 (0)