@@ -423,6 +423,15 @@ describe('input', function() {
423423 scope . $digest ( ) ;
424424 }
425425
426+ var attrs ;
427+ beforeEach ( module ( function ( $compileProvider ) {
428+ $compileProvider . directive ( 'attrCapture' , function ( ) {
429+ return function ( scope , element , $attrs ) {
430+ attrs = $attrs ;
431+ } ;
432+ } ) ;
433+ } ) ) ;
434+
426435 beforeEach ( inject ( function ( $injector , _$sniffer_ , _$browser_ ) {
427436 $sniffer = _$sniffer_ ;
428437 $browser = _$browser_ ;
@@ -1073,6 +1082,19 @@ describe('input', function() {
10731082 expect ( inputElm ) . toBeInvalid ( ) ;
10741083 } ) ;
10751084
1085+ it ( 'should listen on ng-pattern when pattern is observed' , function ( ) {
1086+ var value , patternVal = / ^ \w + $ / ;
1087+ compileInput ( '<input type="text" ng-model="value" ng-pattern="pat" attr-capture />' ) ;
1088+ attrs . $observe ( 'pattern' , function ( v ) {
1089+ value = attrs . pattern ;
1090+ } ) ;
1091+
1092+ scope . $apply ( function ( ) {
1093+ scope . pat = patternVal ;
1094+ } ) ;
1095+
1096+ expect ( value ) . toBe ( patternVal ) ;
1097+ } ) ;
10761098
10771099 it ( 'should validate in-lined pattern with modifiers' , function ( ) {
10781100 compileInput ( '<input type="text" ng-model="value" ng-pattern="/^abc?$/i" />' ) ;
@@ -1104,7 +1126,9 @@ describe('input', function() {
11041126 changeInputValueTo ( 'x' ) ;
11051127 expect ( inputElm ) . toBeInvalid ( ) ;
11061128
1107- scope . regexp = / a b c ? / ;
1129+ scope . $apply ( function ( ) {
1130+ scope . regexp = / a b c ? / ;
1131+ } ) ;
11081132
11091133 changeInputValueTo ( 'ab' ) ;
11101134 expect ( inputElm ) . toBeValid ( ) ;
@@ -1114,10 +1138,12 @@ describe('input', function() {
11141138 } ) ;
11151139
11161140
1117- it ( 'should throw an error when scope pattern can\'t be found ' , function ( ) {
1141+ it ( 'should throw an error when scope pattern is invalid ' , function ( ) {
11181142 expect ( function ( ) {
11191143 compileInput ( '<input type="text" ng-model="foo" ng-pattern="fooRegexp" />' ) ;
1120- scope . $apply ( ) ;
1144+ scope . $apply ( function ( ) {
1145+ scope . fooRegexp = '/...' ;
1146+ } ) ;
11211147 } ) . toThrowMatching ( / ^ \[ n g P a t t e r n : n o r e g e x p \] E x p e c t e d f o o R e g e x p t o b e a R e g E x p b u t w a s / ) ;
11221148 } ) ;
11231149 } ) ;
@@ -1134,6 +1160,20 @@ describe('input', function() {
11341160 changeInputValueTo ( 'aaa' ) ;
11351161 expect ( scope . value ) . toBe ( 'aaa' ) ;
11361162 } ) ;
1163+
1164+ it ( 'should listen on ng-minlength when minlength is observed' , function ( ) {
1165+ var value = 0 ;
1166+ compileInput ( '<input type="text" ng-model="value" ng-minlength="min" attr-capture />' ) ;
1167+ attrs . $observe ( 'minlength' , function ( v ) {
1168+ value = int ( attrs . minlength ) ;
1169+ } ) ;
1170+
1171+ scope . $apply ( function ( ) {
1172+ scope . min = 5 ;
1173+ } ) ;
1174+
1175+ expect ( value ) . toBe ( 5 ) ;
1176+ } ) ;
11371177 } ) ;
11381178
11391179
@@ -1148,6 +1188,20 @@ describe('input', function() {
11481188 changeInputValueTo ( 'aaa' ) ;
11491189 expect ( scope . value ) . toBe ( 'aaa' ) ;
11501190 } ) ;
1191+
1192+ it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
1193+ var value = 0 ;
1194+ compileInput ( '<input type="text" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
1195+ attrs . $observe ( 'maxlength' , function ( v ) {
1196+ value = int ( attrs . maxlength ) ;
1197+ } ) ;
1198+
1199+ scope . $apply ( function ( ) {
1200+ scope . max = 10 ;
1201+ } ) ;
1202+
1203+ expect ( value ) . toBe ( 10 ) ;
1204+ } ) ;
11511205 } ) ;
11521206
11531207
0 commit comments