@@ -484,72 +484,75 @@ describe('NgModelController', function() {
484
484
485
485
} ) ;
486
486
487
- describe ( 'validations pipeline ' , function ( ) {
487
+ describe ( 'validation ' , function ( ) {
488
488
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 = ""' ) ;
498
492
499
- expect ( ctrl . $valid ) . toBe ( false ) ;
493
+ var validatorResult = false ;
494
+ ctrl . $validators . someValidator = function ( value ) {
495
+ return validatorResult ;
496
+ } ;
500
497
501
- validatorResult = true ;
502
- ctrl . $validate ( ) ;
498
+ ctrl . $validate ( ) ;
503
499
504
- expect ( ctrl . $valid ) . toBe ( true ) ;
505
- } ) ;
500
+ expect ( ctrl . $valid ) . toBe ( false ) ;
506
501
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 ( ) ;
513
504
514
- ctrl . $parsers . push ( function ( value ) {
515
- return value . toUpperCase ( ) ;
505
+ expect ( ctrl . $valid ) . toBe ( true ) ;
516
506
} ) ;
517
507
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
+ } ;
519
515
520
- expect ( captures ) . toEqual ( [ 'MY-VALUE' , 'my-value' ] ) ;
521
- } ) ;
516
+ ctrl . $parsers . push ( function ( value ) {
517
+ return value . toUpperCase ( ) ;
518
+ } ) ;
522
519
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' ) ;
529
521
530
- ctrl . $formatters . push ( function ( value ) {
531
- return value + '...' ;
522
+ expect ( captures ) . toEqual ( [ 'MY-VALUE' , 'my-value' ] ) ;
532
523
} ) ;
533
524
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
+ } ;
535
531
536
- expect ( captures ) . toEqual ( [ 'matias' , 'matias...' ] ) ;
537
- } ) ;
532
+ ctrl . $formatters . push ( function ( value ) {
533
+ return value + '...' ;
534
+ } ) ;
538
535
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"' ) ;
544
537
545
- ctrl . $setViewValue ( 'my-value' ) ;
546
- expect ( count ) . toBe ( 1 ) ;
538
+ expect ( captures ) . toEqual ( [ 'matias' , 'matias...' ] ) ;
539
+ } ) ;
547
540
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
+ } ;
550
546
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
+ } ) ;
553
556
} ) ;
554
557
555
558
it ( 'should perform validations twice each time the model value changes within a digest' , function ( ) {
0 commit comments