@@ -204,6 +204,24 @@ describe('validators', function() {
204
204
expect ( $rootScope . form . test . $error . pattern ) . toBe ( true ) ;
205
205
expect ( inputElm ) . not . toBeValid ( ) ;
206
206
} ) ;
207
+
208
+
209
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
210
+ $rootScope . pattern = '\\d{4}' ;
211
+ var elm = $compile ( '<span ng-model="value" pattern="\\d{4}"></span>' ) ( $rootScope ) ;
212
+ var elmNg = $compile ( '<span ng-model="value" ng-pattern="pattern"></span>' ) ( $rootScope ) ;
213
+ var ctrl = elm . controller ( 'ngModel' ) ;
214
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
215
+
216
+ expect ( ctrl . $error . pattern ) . not . toBe ( true ) ;
217
+ expect ( ctrlNg . $error . pattern ) . not . toBe ( true ) ;
218
+
219
+ ctrl . $setViewValue ( '12' ) ;
220
+ ctrlNg . $setViewValue ( '12' ) ;
221
+
222
+ expect ( ctrl . $error . pattern ) . toBe ( true ) ;
223
+ expect ( ctrlNg . $error . pattern ) . toBe ( true ) ;
224
+ } ) ) ;
207
225
} ) ;
208
226
209
227
@@ -268,6 +286,24 @@ describe('validators', function() {
268
286
helper . changeInputValueTo ( '12345' ) ;
269
287
expect ( ctrl . $isEmpty ) . toHaveBeenCalledWith ( '12345' ) ;
270
288
} ) ;
289
+
290
+
291
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
292
+ $rootScope . min = 3 ;
293
+ var elm = $compile ( '<span ng-model="value" minlength="{{min}}"></span>' ) ( $rootScope ) ;
294
+ var elmNg = $compile ( '<span ng-model="value" ng-minlength="min"></span>' ) ( $rootScope ) ;
295
+ var ctrl = elm . controller ( 'ngModel' ) ;
296
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
297
+
298
+ expect ( ctrl . $error . minlength ) . not . toBe ( true ) ;
299
+ expect ( ctrlNg . $error . minlength ) . not . toBe ( true ) ;
300
+
301
+ ctrl . $setViewValue ( '12' ) ;
302
+ ctrlNg . $setViewValue ( '12' ) ;
303
+
304
+ expect ( ctrl . $error . minlength ) . toBe ( true ) ;
305
+ expect ( ctrlNg . $error . minlength ) . toBe ( true ) ;
306
+ } ) ) ;
271
307
} ) ;
272
308
273
309
@@ -438,6 +474,24 @@ describe('validators', function() {
438
474
helper . changeInputValueTo ( '12345' ) ;
439
475
expect ( ctrl . $isEmpty ) . toHaveBeenCalledWith ( '12345' ) ;
440
476
} ) ;
477
+
478
+
479
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
480
+ $rootScope . max = 3 ;
481
+ var elm = $compile ( '<span ng-model="value" maxlength="{{max}}"></span>' ) ( $rootScope ) ;
482
+ var elmNg = $compile ( '<span ng-model="value" ng-maxlength="max"></span>' ) ( $rootScope ) ;
483
+ var ctrl = elm . controller ( 'ngModel' ) ;
484
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
485
+
486
+ expect ( ctrl . $error . maxlength ) . not . toBe ( true ) ;
487
+ expect ( ctrlNg . $error . maxlength ) . not . toBe ( true ) ;
488
+
489
+ ctrl . $setViewValue ( '1234' ) ;
490
+ ctrlNg . $setViewValue ( '1234' ) ;
491
+
492
+ expect ( ctrl . $error . maxlength ) . toBe ( true ) ;
493
+ expect ( ctrlNg . $error . maxlength ) . toBe ( true ) ;
494
+ } ) ) ;
441
495
} ) ;
442
496
443
497
@@ -532,6 +586,7 @@ describe('validators', function() {
532
586
expect ( inputElm ) . toBeValid ( ) ;
533
587
} ) ;
534
588
589
+
535
590
it ( 'should validate emptiness against the viewValue' , function ( ) {
536
591
var inputElm = helper . compileInput ( '<input type="text" name="input" ng-model="value" required />' ) ;
537
592
@@ -545,5 +600,23 @@ describe('validators', function() {
545
600
helper . changeInputValueTo ( '12345' ) ;
546
601
expect ( ctrl . $isEmpty ) . toHaveBeenCalledWith ( '12345' ) ;
547
602
} ) ;
603
+
604
+
605
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
606
+ $rootScope . value = '12' ;
607
+ var elm = $compile ( '<span ng-model="value" required></span>' ) ( $rootScope ) ;
608
+ var elmNg = $compile ( '<span ng-model="value" ng-required="true"></span>' ) ( $rootScope ) ;
609
+ var ctrl = elm . controller ( 'ngModel' ) ;
610
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
611
+
612
+ expect ( ctrl . $error . required ) . not . toBe ( true ) ;
613
+ expect ( ctrlNg . $error . required ) . not . toBe ( true ) ;
614
+
615
+ ctrl . $setViewValue ( '' ) ;
616
+ ctrlNg . $setViewValue ( '' ) ;
617
+
618
+ expect ( ctrl . $error . required ) . toBe ( true ) ;
619
+ expect ( ctrlNg . $error . required ) . toBe ( true ) ;
620
+ } ) ) ;
548
621
} ) ;
549
622
} ) ;
0 commit comments