@@ -219,6 +219,24 @@ describe('validators', function() {
219
219
expect ( $rootScope . form . test . $modelValue ) . toBe ( '12340' ) ;
220
220
expect ( inputElm ) . toBeValid ( ) ;
221
221
} ) ;
222
+
223
+
224
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
225
+ $rootScope . pattern = '\\d{4}' ;
226
+ var elm = $compile ( '<span ng-model="value" pattern="\\d{4}"></span>' ) ( $rootScope ) ;
227
+ var elmNg = $compile ( '<span ng-model="value" ng-pattern="pattern"></span>' ) ( $rootScope ) ;
228
+ var ctrl = elm . controller ( 'ngModel' ) ;
229
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
230
+
231
+ expect ( ctrl . $error . pattern ) . not . toBe ( true ) ;
232
+ expect ( ctrlNg . $error . pattern ) . not . toBe ( true ) ;
233
+
234
+ ctrl . $setViewValue ( '12' ) ;
235
+ ctrlNg . $setViewValue ( '12' ) ;
236
+
237
+ expect ( ctrl . $error . pattern ) . toBe ( true ) ;
238
+ expect ( ctrlNg . $error . pattern ) . toBe ( true ) ;
239
+ } ) ) ;
222
240
} ) ;
223
241
224
242
@@ -283,6 +301,24 @@ describe('validators', function() {
283
301
helper . changeInputValueTo ( '12345' ) ;
284
302
expect ( ctrl . $isEmpty ) . toHaveBeenCalledWith ( '12345' ) ;
285
303
} ) ;
304
+
305
+
306
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
307
+ $rootScope . min = 3 ;
308
+ var elm = $compile ( '<span ng-model="value" minlength="{{min}}"></span>' ) ( $rootScope ) ;
309
+ var elmNg = $compile ( '<span ng-model="value" ng-minlength="min"></span>' ) ( $rootScope ) ;
310
+ var ctrl = elm . controller ( 'ngModel' ) ;
311
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
312
+
313
+ expect ( ctrl . $error . minlength ) . not . toBe ( true ) ;
314
+ expect ( ctrlNg . $error . minlength ) . not . toBe ( true ) ;
315
+
316
+ ctrl . $setViewValue ( '12' ) ;
317
+ ctrlNg . $setViewValue ( '12' ) ;
318
+
319
+ expect ( ctrl . $error . minlength ) . toBe ( true ) ;
320
+ expect ( ctrlNg . $error . minlength ) . toBe ( true ) ;
321
+ } ) ) ;
286
322
} ) ;
287
323
288
324
@@ -453,6 +489,24 @@ describe('validators', function() {
453
489
helper . changeInputValueTo ( '12345' ) ;
454
490
expect ( ctrl . $isEmpty ) . toHaveBeenCalledWith ( '12345' ) ;
455
491
} ) ;
492
+
493
+
494
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
495
+ $rootScope . max = 3 ;
496
+ var elm = $compile ( '<span ng-model="value" maxlength="{{max}}"></span>' ) ( $rootScope ) ;
497
+ var elmNg = $compile ( '<span ng-model="value" ng-maxlength="max"></span>' ) ( $rootScope ) ;
498
+ var ctrl = elm . controller ( 'ngModel' ) ;
499
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
500
+
501
+ expect ( ctrl . $error . maxlength ) . not . toBe ( true ) ;
502
+ expect ( ctrlNg . $error . maxlength ) . not . toBe ( true ) ;
503
+
504
+ ctrl . $setViewValue ( '1234' ) ;
505
+ ctrlNg . $setViewValue ( '1234' ) ;
506
+
507
+ expect ( ctrl . $error . maxlength ) . toBe ( true ) ;
508
+ expect ( ctrlNg . $error . maxlength ) . toBe ( true ) ;
509
+ } ) ) ;
456
510
} ) ;
457
511
458
512
@@ -547,6 +601,7 @@ describe('validators', function() {
547
601
expect ( inputElm ) . toBeValid ( ) ;
548
602
} ) ;
549
603
604
+
550
605
it ( 'should validate emptiness against the viewValue' , function ( ) {
551
606
var inputElm = helper . compileInput ( '<input type="text" name="input" ng-model="value" required />' ) ;
552
607
@@ -560,5 +615,23 @@ describe('validators', function() {
560
615
helper . changeInputValueTo ( '12345' ) ;
561
616
expect ( ctrl . $isEmpty ) . toHaveBeenCalledWith ( '12345' ) ;
562
617
} ) ;
618
+
619
+
620
+ it ( 'should validate on non-input elements' , inject ( function ( $compile ) {
621
+ $rootScope . value = '12' ;
622
+ var elm = $compile ( '<span ng-model="value" required></span>' ) ( $rootScope ) ;
623
+ var elmNg = $compile ( '<span ng-model="value" ng-required="true"></span>' ) ( $rootScope ) ;
624
+ var ctrl = elm . controller ( 'ngModel' ) ;
625
+ var ctrlNg = elmNg . controller ( 'ngModel' ) ;
626
+
627
+ expect ( ctrl . $error . required ) . not . toBe ( true ) ;
628
+ expect ( ctrlNg . $error . required ) . not . toBe ( true ) ;
629
+
630
+ ctrl . $setViewValue ( '' ) ;
631
+ ctrlNg . $setViewValue ( '' ) ;
632
+
633
+ expect ( ctrl . $error . required ) . toBe ( true ) ;
634
+ expect ( ctrlNg . $error . required ) . toBe ( true ) ;
635
+ } ) ) ;
563
636
} ) ;
564
637
} ) ;
0 commit comments