Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a0a2b0

Browse files
author
Joe Wallace
committed
Adding tests for #29
1 parent 1163816 commit 2a0a2b0

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

spec/ValidatorSpec.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,165 @@ describe('Validator', function() {
11561156

11571157
});
11581158

1159+
describe('for the digits between rule', function() {
1160+
1161+
it('should pass for a number of appropriate length', function() {
1162+
1163+
var elem = null,
1164+
elemValid = null,
1165+
formValid = null;
1166+
1167+
textInput.data('validations', 'digits_between:2,4')
1168+
.val('123');
1169+
1170+
testForm.validator($.extend({
1171+
callback: function(e, v) {
1172+
elem = e;
1173+
elemValid = v;
1174+
},
1175+
done: function(v) {
1176+
formValid = v;
1177+
}
1178+
}, defaultOptions)).submit();
1179+
1180+
waitsFor(function() {
1181+
return elem !== null &&
1182+
formValid !== null;
1183+
});
1184+
1185+
runs(function() {
1186+
expect($(elem).attr('name')).toEqual(textInput.attr('name'));
1187+
expect(elemValid).toEqual(true);
1188+
expect(formValid).toEqual(true);
1189+
});
1190+
});
1191+
1192+
it('should pass for a number with the same length as the lower limit', function() {
1193+
1194+
var elem = null,
1195+
elemValid = null,
1196+
formValid = null;
1197+
1198+
textInput.data('validations', 'digits_between:2,4')
1199+
.val('12');
1200+
1201+
testForm.validator($.extend({
1202+
callback: function(e, v) {
1203+
elem = e;
1204+
elemValid = v;
1205+
},
1206+
done: function(v) {
1207+
formValid = v;
1208+
}
1209+
}, defaultOptions)).submit();
1210+
1211+
waitsFor(function() {
1212+
return elem !== null &&
1213+
formValid !== null;
1214+
});
1215+
1216+
runs(function() {
1217+
expect($(elem).attr('name')).toEqual(textInput.attr('name'));
1218+
expect(elemValid).toEqual(true);
1219+
expect(formValid).toEqual(true);
1220+
});
1221+
});
1222+
1223+
it('should pass for a number with the same length as the upper limit', function() {
1224+
1225+
var elem = null,
1226+
elemValid = null,
1227+
formValid = null;
1228+
1229+
textInput.data('validations', 'digits_between:2,4')
1230+
.val('1234');
1231+
1232+
testForm.validator($.extend({
1233+
callback: function(e, v) {
1234+
elem = e;
1235+
elemValid = v;
1236+
},
1237+
done: function(v) {
1238+
formValid = v;
1239+
}
1240+
}, defaultOptions)).submit();
1241+
1242+
waitsFor(function() {
1243+
return elem !== null &&
1244+
formValid !== null;
1245+
});
1246+
1247+
runs(function() {
1248+
expect($(elem).attr('name')).toEqual(textInput.attr('name'));
1249+
expect(elemValid).toEqual(true);
1250+
expect(formValid).toEqual(true);
1251+
});
1252+
});
1253+
1254+
it('should fail for a number shorter than the lower limit', function() {
1255+
1256+
var elem = null,
1257+
elemValid = null,
1258+
formValid = null;
1259+
1260+
textInput.data('validations', 'digits_between:2,4')
1261+
.val('1');
1262+
1263+
testForm.validator($.extend({
1264+
callback: function(e, v) {
1265+
elem = e;
1266+
elemValid = v;
1267+
},
1268+
done: function(v) {
1269+
formValid = v;
1270+
}
1271+
}, defaultOptions)).submit();
1272+
1273+
waitsFor(function() {
1274+
return elem !== null &&
1275+
formValid !== null;
1276+
});
1277+
1278+
runs(function() {
1279+
expect($(elem).attr('name')).toEqual(textInput.attr('name'));
1280+
expect(elemValid).toEqual(false);
1281+
expect(formValid).toEqual(false);
1282+
});
1283+
});
1284+
1285+
it('should fail for a number longer than the upper limit', function() {
1286+
1287+
var elem = null,
1288+
elemValid = null,
1289+
formValid = null;
1290+
1291+
textInput.data('validations', 'digits_between:2,4')
1292+
.val('12345');
1293+
1294+
testForm.validator($.extend({
1295+
callback: function(e, v) {
1296+
elem = e;
1297+
elemValid = v;
1298+
},
1299+
done: function(v) {
1300+
formValid = v;
1301+
}
1302+
}, defaultOptions)).submit();
1303+
1304+
waitsFor(function() {
1305+
return elem !== null &&
1306+
formValid !== null;
1307+
});
1308+
1309+
runs(function() {
1310+
expect($(elem).attr('name')).toEqual(textInput.attr('name'));
1311+
expect(elemValid).toEqual(false);
1312+
expect(formValid).toEqual(false);
1313+
});
1314+
});
1315+
1316+
});
1317+
11591318
describe('for the email rule', function() {
11601319

11611320
it ('should pass for a valid email address', function() {

0 commit comments

Comments
 (0)