@@ -423,6 +423,15 @@ describe('input', function() {
423
423
scope . $digest ( ) ;
424
424
}
425
425
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
+
426
435
beforeEach ( inject ( function ( $injector , _$sniffer_ , _$browser_ ) {
427
436
$sniffer = _$sniffer_ ;
428
437
$browser = _$browser_ ;
@@ -1073,9 +1082,22 @@ describe('input', function() {
1073
1082
expect ( inputElm ) . toBeInvalid ( ) ;
1074
1083
} ) ;
1075
1084
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
+ } ) ;
1076
1098
1077
1099
it ( 'should validate in-lined pattern with modifiers' , function ( ) {
1078
- compileInput ( '<input type="text" ng-model="value" ng-pattern="/^abc?$/i" />' ) ;
1100
+ compileInput ( '<input type="text" ng-model="value" ng-pattern="\' /^abc?$/i\' " />' ) ;
1079
1101
1080
1102
changeInputValueTo ( 'aB' ) ;
1081
1103
expect ( inputElm ) . toBeValid ( ) ;
@@ -1104,7 +1126,9 @@ describe('input', function() {
1104
1126
changeInputValueTo ( 'x' ) ;
1105
1127
expect ( inputElm ) . toBeInvalid ( ) ;
1106
1128
1107
- scope . regexp = / a b c ? / ;
1129
+ scope . $apply ( function ( ) {
1130
+ scope . regexp = / a b c ? / ;
1131
+ } ) ;
1108
1132
1109
1133
changeInputValueTo ( 'ab' ) ;
1110
1134
expect ( inputElm ) . toBeValid ( ) ;
@@ -1114,10 +1138,12 @@ describe('input', function() {
1114
1138
} ) ;
1115
1139
1116
1140
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 ( ) {
1118
1142
expect ( function ( ) {
1119
1143
compileInput ( '<input type="text" ng-model="foo" ng-pattern="fooRegexp" />' ) ;
1120
- scope . $apply ( ) ;
1144
+ scope . $apply ( function ( ) {
1145
+ scope . fooRegexp = '/...' ;
1146
+ } ) ;
1121
1147
} ) . 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 / ) ;
1122
1148
} ) ;
1123
1149
} ) ;
@@ -1134,6 +1160,20 @@ describe('input', function() {
1134
1160
changeInputValueTo ( 'aaa' ) ;
1135
1161
expect ( scope . value ) . toBe ( 'aaa' ) ;
1136
1162
} ) ;
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
+ } ) ;
1137
1177
} ) ;
1138
1178
1139
1179
@@ -1148,6 +1188,20 @@ describe('input', function() {
1148
1188
changeInputValueTo ( 'aaa' ) ;
1149
1189
expect ( scope . value ) . toBe ( 'aaa' ) ;
1150
1190
} ) ;
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
+ } ) ;
1151
1205
} ) ;
1152
1206
1153
1207
0 commit comments