@@ -3,6 +3,17 @@ library ng_model_validators;
3
3
import '../_specs.dart' ;
4
4
5
5
void main () {
6
+ they (should, tokens, callback, [exclusive= false ]) {
7
+ tokens.forEach ((token) {
8
+ describe (token, () {
9
+ (exclusive ? iit : it)(should, () => callback (token));
10
+ });
11
+ });
12
+ }
13
+
14
+ tthey (should, tokens, callback) =>
15
+ they (should, tokens, callback, true );
16
+
6
17
describe ('ngModel validators' , () {
7
18
TestBed _;
8
19
@@ -128,9 +139,12 @@ void main() {
128
139
}));
129
140
});
130
141
131
- describe ('[type="number"]' , () {
132
- it ('should validate the input field given a valid or invalid number' , inject ((RootScope scope) {
133
- _.compile ('<input type="number" ng-model="val" probe="i" />' );
142
+ describe ('[type="number|range"]' , () {
143
+ they ('should validate the input field given a valid or invalid number' ,
144
+ ['range' , 'number' ],
145
+ (type) {
146
+
147
+ _.compile ('<input type="$type " ng-model="val" probe="i" />' );
134
148
Probe probe = _.rootScope.context['i' ];
135
149
var model = probe.directive (NgModel );
136
150
@@ -162,12 +176,13 @@ void main() {
162
176
model.validate ();
163
177
expect (model.valid).toEqual (false );
164
178
expect (model.invalid).toEqual (true );
165
- })) ;
179
+ });
166
180
167
- it ('should perform a max number validation if a max attribute value is present' ,
168
- inject ((RootScope scope) {
181
+ they ('should perform a max number validation if a max attribute value is present' ,
182
+ ['range' , 'number' ],
183
+ (type) {
169
184
170
- _.compile ('<input type="number " ng-model="val" max="10" probe="i" />' );
185
+ _.compile ('<input type="$ type " ng-model="val" max="10" probe="i" />' );
171
186
Probe probe = _.rootScope.context['i' ];
172
187
var model = probe.directive (NgModel );
173
188
@@ -198,12 +213,13 @@ void main() {
198
213
expect (model.invalid).toEqual (true );
199
214
expect (model.hasError ('max' )).toBe (false );
200
215
expect (model.hasError ('number' )).toBe (true );
201
- })) ;
216
+ });
202
217
203
- it ('should perform a max number validation if a ng-max attribute value is present and/or changed' ,
204
- inject ((RootScope scope) {
218
+ they ('should perform a max number validation if a ng-max attribute value is present and/or changed' ,
219
+ ['range' , 'number' ],
220
+ (type) {
205
221
206
- _.compile ('<input type="number " ng-model="val" ng-max="maxVal" probe="i" />' );
222
+ _.compile ('<input type="$ type " ng-model="val" ng-max="maxVal" probe="i" />' );
207
223
Probe probe = _.rootScope.context['i' ];
208
224
var model = probe.directive (NgModel );
209
225
@@ -239,12 +255,13 @@ void main() {
239
255
expect (model.valid).toEqual (true );
240
256
expect (model.invalid).toEqual (false );
241
257
expect (model.hasError ('max' )).toBe (false );
242
- })) ;
258
+ });
243
259
244
- it ('should perform a min number validation if a min attribute value is present' ,
245
- inject ((RootScope scope) {
260
+ they ('should perform a min number validation if a min attribute value is present' ,
261
+ ['range' , 'number' ],
262
+ (type) {
246
263
247
- _.compile ('<input type="number " ng-model="val" min="-10" probe="i" />' );
264
+ _.compile ('<input type="$ type " ng-model="val" min="-10" probe="i" />' );
248
265
Probe probe = _.rootScope.context['i' ];
249
266
var model = probe.directive (NgModel );
250
267
@@ -275,12 +292,13 @@ void main() {
275
292
expect (model.invalid).toEqual (true );
276
293
expect (model.hasError ('min' )).toBe (false );
277
294
expect (model.hasError ('number' )).toBe (true );
278
- })) ;
295
+ });
279
296
280
- it ('should perform a min number validation if a ng-min attribute value is present and/or changed' ,
281
- inject ((RootScope scope) {
297
+ they ('should perform a min number validation if a ng-min attribute value is present and/or changed' ,
298
+ ['range' , 'number' ],
299
+ (type) {
282
300
283
- _.compile ('<input type="number " ng-model="val" ng-min="minVal" probe="i" />' );
301
+ _.compile ('<input type="$ type " ng-model="val" ng-min="minVal" probe="i" />' );
284
302
Probe probe = _.rootScope.context['i' ];
285
303
var model = probe.directive (NgModel );
286
304
@@ -316,7 +334,7 @@ void main() {
316
334
expect (model.valid).toEqual (true );
317
335
expect (model.invalid).toEqual (false );
318
336
expect (model.hasError ('min' )).toBe (false );
319
- })) ;
337
+ });
320
338
});
321
339
322
340
describe ('pattern' , () {
0 commit comments