Build: Run JSCS against tests

This commit is contained in:
Nick Schonning
2014-05-27 00:08:54 -04:00
parent 56a2a18368
commit d0c56e005e
6 changed files with 214 additions and 149 deletions

View File

@@ -16,6 +16,7 @@
"requireMultipleVarDecl": "onevar",
"disallowTrailingWhitespace": true,
"validateQuoteMarks": "\"",
"requireSpacesInsideArrayBrackets": "allButNested",
"excludeFiles": [
"node_modules/**",
"dist/**"

View File

@@ -7,13 +7,36 @@ test( "elements() order", function() {
wrap: "li"
});
deepEqual( v.elements().map( function() {
deepEqual(
v.elements().map( function() {
return $( this ).attr( "id" );
}).get(), ["order1", "order2", "order3", "order4", "order5", "order6"], "elements must be in document order" );
}).get(),
[
"order1",
"order2",
"order3",
"order4",
"order5",
"order6"
],
"elements must be in document order"
);
v.form();
deepEqual( container.children().map( function() {
deepEqual(
container.children().map( function() {
return $( this ).attr( "id" );
}).get(), ["order1-error", "order2-error", "order3-error", "order4-error", "order5-error", "order6-error"], "labels in error container must be in document order" );
}).get(),
[
"order1-error",
"order2-error",
"order3-error",
"order4-error",
"order5-error",
"order6-error"
],
"labels in error container must be in document order"
);
});
test( "error containers, simple", function() {
@@ -33,7 +56,21 @@ test( "error containers, simple", function() {
equal( "", container.find( "h3" ).html() );
v.prepareForm();
v.errorList = [{message:"bar", element: {name:"foo"}}, {message: "necessary", element: {name:"required"}}];
v.errorList = [
{
message: "bar",
element: {
name: "foo"
}
},
{
message: "necessary",
element: {
name: "required"
}
}
];
ok( !v.valid(), "form is not valid after adding errors manually" );
v.showErrors();
equal( container.find( ".error:not(input)" ).length, 2, "There should be two error labels" );
@@ -68,7 +105,22 @@ test( "error containers, with labelcontainer I", function() {
equal( 0, labelcontainer.find( ".error:not(input)" ).length, "There should be no error labels in the labelcontainer" );
equal( 0, labelcontainer.find( "li" ).length, "There should be no lis labels in the labelcontainer" );
v.errorList = [{message:"bar", element: {name:"foo"}}, {name: "required", message: "necessary", element: {name:"required"}}];
v.errorList = [
{
message: "bar",
element: {
name: "foo"
}
},
{
name: "required",
message: "necessary",
element: {
name: "required"
}
}
];
ok( !v.valid(), "form is not valid after adding errors manually" );
v.showErrors();
equal( 0, container.find( ".error:not(input)" ).length, "There should be no error label in the container" );
@@ -110,7 +162,12 @@ test( "errorcontainer, show/hide only on submit", function() {
ok( container.is( ":visible" ), "must be visible" );
$( "#firstname" ).val( "hix" ).keyup();
$( "#testForm1" ).triggerHandler( "keyup", [jQuery.event.fix({ type: "keyup", target: $( "#firstname" )[0] })]);
$( "#testForm1" ).triggerHandler( "keyup", [
jQuery.event.fix({
type: "keyup",
target: $( "#firstname" )[ 0 ]
})
]);
equal( 1, labelContainer.find( ".error:visible" ).length );
equal( "There are 1 errors in your form.", container.html() );
@@ -209,7 +266,7 @@ test( "test existing label used as error element", function(assert) {
var form = $( "#testForm14" ),
field = $( "#testForm14text" );
form.validate({errorElement: "label"});
form.validate({ errorElement: "label" });
ok( !field.valid() );
assert.hasError( field, "required" );
@@ -224,7 +281,7 @@ test( "test existing non-label used as error element", function(assert) {
var form = $( "#testForm15" ),
field = $( "#testForm15text" );
form.validate({errorElement: "span"});
form.validate({ errorElement: "span" });
ok( !field.valid() );
assert.hasError( field );

View File

@@ -11,7 +11,7 @@ test("predefined message not overwritten by addMethod(a, b, undefined)", functio
test("group error messages", function() {
$.validator.addClassRules({
requiredDateRange: {required:true, date:true, dateRange:true}
requiredDateRange: { required: true, date: true, dateRange: true }
});
$.validator.addMethod("dateRange", function() {
return new Date($("#fromDate").val()) < new Date($("#toDate").val());
@@ -57,7 +57,6 @@ test("read messages from metadata", function() {
equal( form.find("#testGeneric9").next(".error:not(input)").text(), "email" );
});
test("read messages from metadata, with meta option specified, but no metadata in there", function() {
var form = $("#testForm1clean");
form.validate({

View File

@@ -269,7 +269,7 @@ test("maxlength", function() {
test("rangelength", function() {
var v = jQuery("#form").validate(),
method = $.validator.methods.rangelength,
param = [2, 4],
param = [ 2, 4 ],
e = $("#text1, #text2, #text3");
ok( method.call( v, e[0].value, e[0], param), "Valid text input" );
@@ -302,7 +302,7 @@ test("max", function() {
test("range", function() {
var v = jQuery("#form").validate(),
method = $.validator.methods.range,
param = [4,12],
param = [ 4, 12 ],
e = $("#value1, #value2, #value3");
ok(!method.call( v, e[0].value, e[0], param), "Invalid text input" );
@@ -420,7 +420,6 @@ asyncTest("remote, customized ajax options", function() {
$("#userForm").valid();
});
asyncTest("remote extensions", function() {
expect(5);
var e = $("#username"),
@@ -492,7 +491,7 @@ asyncTest("remote reset clear old value", function() {
url: "echo.php",
dataFilter: function(data) {
var json = JSON.parse(data);
if(json.username === "asdf") {
if (json.username === "asdf") {
return "\"asdf is already taken\"";
}
return "\"" + true + "\"";
@@ -507,14 +506,12 @@ asyncTest("remote reset clear old value", function() {
$(document).unbind("ajaxStop");
$(document).ajaxStop(function() {
clearTimeout(waitTimeout);
ok( true, "Remote request sent to server" );
start();
});
v.resetForm();
e.val("asdf");
waitTimeout = setTimeout(function() {
@@ -900,11 +897,11 @@ test("maxWords", function() {
test("rangeWords", function() {
var method = methodTest("rangeWords");
ok( method( "hello", [0, 2] ), "plain text, valid" );
ok( method( "hello worlds", [0, 2] ), "plain text, valid" );
ok( method( "<b>hello</b> world", [0, 2] ), "html, valid" );
ok(!method( "hello worlds what is up", [0, 2] ), "plain text, invalid" );
ok(!method( "<b>Hello</b> <b>world</b> <b>hello</b>", [0, 2] ), "html, invalid" );
ok( method( "hello", [ 0, 2 ] ), "plain text, valid" );
ok( method( "hello worlds", [ 0, 2 ] ), "plain text, valid" );
ok( method( "<b>hello</b> world", [ 0, 2 ] ), "html, valid" );
ok(!method( "hello worlds what is up", [ 0, 2 ] ), "plain text, invalid" );
ok(!method( "<b>Hello</b> <b>world</b> <b>hello</b>", [ 0, 2 ] ), "html, invalid" );
});
test("pattern", function() {
@@ -993,71 +990,71 @@ function fillFormWithValuesAndExpect(formSelector, inputValues, expected) {
test("require_from_group", function() {
$("#productInfo").validate({
rules: {
partnumber: {require_from_group: [2,".productInfo"]},
description: {require_from_group: [2,".productInfo"]},
discount: {require_from_group: [2,".productInfo"]}
partnumber: { require_from_group: [ 2,".productInfo" ] },
description: { require_from_group: [ 2,".productInfo" ] },
discount: { require_from_group: [ 2,".productInfo" ] }
}
});
fillFormWithValuesAndExpect("#productInfo", [], false);
fillFormWithValuesAndExpect("#productInfo", [123], false);
fillFormWithValuesAndExpect("#productInfo", [ 123 ], false);
$("#productInfo input[type='checkbox']").attr("checked", "checked");
fillFormWithValuesAndExpect("#productInfo", [123], true);
fillFormWithValuesAndExpect("#productInfo", [ 123 ], true);
$("#productInfo input[type='checkbox']").removeAttr("checked");
fillFormWithValuesAndExpect("#productInfo", [123, "widget"], true);
fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red"], true);
fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red"], true);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget" ], true);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red" ], true);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red" ], true);
});
test("require_from_group preserve other rules", function() {
$("#productInfo").validate({
rules: {
partnumber: {require_from_group: [2,".productInfo"]},
description: {require_from_group: [2,".productInfo"]},
color: {require_from_group: [2,".productInfo"]},
supplier: {required: true}
partnumber: { require_from_group: [ 2,".productInfo" ] },
description: { require_from_group: [ 2,".productInfo" ] },
color: { require_from_group: [ 2,".productInfo" ] },
supplier: { required: true }
}
});
fillFormWithValuesAndExpect("#productInfo", [], false);
fillFormWithValuesAndExpect("#productInfo", [123], false);
fillFormWithValuesAndExpect("#productInfo", [123, "widget"], false);
fillFormWithValuesAndExpect("#productInfo", ["", "", "", "Acme"], false);
fillFormWithValuesAndExpect("#productInfo", [123, "", "", "Acme"], false);
fillFormWithValuesAndExpect("#productInfo", [123, "widget", "", "Acme"], true);
fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red", "Acme"], true);
fillFormWithValuesAndExpect("#productInfo", [ 123 ], false);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget" ], false);
fillFormWithValuesAndExpect("#productInfo", [ "", "", "", "Acme" ], false);
fillFormWithValuesAndExpect("#productInfo", [ 123, "", "", "Acme" ], false);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "", "Acme" ], true);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red", "Acme" ], true);
});
test("skip_or_fill_minimum", function() {
$("#productInfo").validate({
rules: {
partnumber: {skip_or_fill_minimum: [2,".productInfo"]},
description: {skip_or_fill_minimum: [2,".productInfo"]},
color: {skip_or_fill_minimum: [2,".productInfo"]}
partnumber: { skip_or_fill_minimum: [ 2,".productInfo" ] },
description: { skip_or_fill_minimum: [ 2,".productInfo" ] },
color: { skip_or_fill_minimum: [ 2,".productInfo" ] }
}
});
fillFormWithValuesAndExpect("#productInfo", [], true);
fillFormWithValuesAndExpect("#productInfo", [123], false);
fillFormWithValuesAndExpect("#productInfo", [123, "widget"], true);
fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red"], true);
fillFormWithValuesAndExpect("#productInfo", [ 123 ], false);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget" ], true);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red" ], true);
});
test("skip_or_fill_minimum preserve other rules", function() {
$("#productInfo").validate({
rules: {
partnumber: {skip_or_fill_minimum: [2,".productInfo"]},
description: {skip_or_fill_minimum: [2,".productInfo"]},
color: {skip_or_fill_minimum: [2,".productInfo"]},
supplier: {required: true}
partnumber: { skip_or_fill_minimum: [ 2,".productInfo" ] },
description: { skip_or_fill_minimum: [ 2,".productInfo" ] },
color: { skip_or_fill_minimum: [ 2,".productInfo" ] },
supplier: { required: true }
}
});
fillFormWithValuesAndExpect("#productInfo", [], false);
fillFormWithValuesAndExpect("#productInfo", ["", "", "", "Acme"], true);
fillFormWithValuesAndExpect("#productInfo", [123, "", "", "Acme"], false);
fillFormWithValuesAndExpect("#productInfo", [123, "widget", "", "Acme"], true);
fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red", "Acme"], true);
fillFormWithValuesAndExpect("#productInfo", [ "", "", "", "Acme" ], true);
fillFormWithValuesAndExpect("#productInfo", [ 123, "", "", "Acme" ], false);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "", "Acme" ], true);
fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red", "Acme" ], true);
});
test("zipcodeUS", function() {
@@ -1166,7 +1163,7 @@ test("cifES", function() {
ok(!method( "B-43.522.192" ), "CIF invalid: dots and dash" );
});
test("maxWords", function(){
test("maxWords", function() {
var method = methodTest("maxWords"),
maxWords = 6;
@@ -1178,7 +1175,7 @@ test("maxWords", function(){
ok(!method( "<div>But you can “count” me as too long</div>", maxWords), "Too many words with smartquotes w/ HTML");
});
test("minWords", function(){
test("minWords", function() {
var method = methodTest("minWords"),
minWords = 6;
@@ -1190,9 +1187,9 @@ test("minWords", function(){
ok( method( "<div>But you can “count” me as too long</div>", minWords), "Too many words with smartquotes w/ HTML");
});
test("rangeWords", function(){
test("rangeWords", function() {
var method = methodTest("rangeWords"),
rangeWords = [3,6];
rangeWords = [ 3, 6 ];
ok(!method( "I'm going to be longer than “six words!”", rangeWords), "Longer than 6 with smartquotes");
ok( method( "I'm just the right amount!", rangeWords), "In between");
@@ -1211,13 +1208,13 @@ test("currency", function() { // Works with any symbol
ok( method( "£9,999.9", "£"), "£, thousand, comma separator, one decimal" );
ok( method( "£9,999.99", "£"), "£, thousand, comma separator, two decimal" );
ok( method( "£9,999,999.9", "£"), "£, million, comma separators, one decimal" );
ok( method( "9", ["£", false]), "Valid currency" );
ok( method( "9.9", ["£", false]), "Valid currency" );
ok( method( "9.99", ["£", false]), "Valid currency" );
ok( method( "9.90", ["£", false]), "Valid currency" );
ok( method( "9,999.9", ["£", false]), "Valid currency" );
ok( method( "9,999.99", ["£", false]), "Valid currency" );
ok( method( "9,999,999.9", ["£", false]), "Valid currency" );
ok( method( "9", [ "£", false ]), "Valid currency" );
ok( method( "9.9", [ "£", false ]), "Valid currency" );
ok( method( "9.99", [ "£", false ]), "Valid currency" );
ok( method( "9.90", [ "£", false ]), "Valid currency" );
ok( method( "9,999.9", [ "£", false ]), "Valid currency" );
ok( method( "9,999.99", [ "£", false ]), "Valid currency" );
ok( method( "9,999,999.9", [ "£", false ]), "Valid currency" );
ok(!method( "9,", "£"), "Invalid currency" );
ok(!method( "9,99.99", "£"), "Invalid currency" );
ok(!method( "9,", "£"), "Invalid currency" );

View File

@@ -33,7 +33,7 @@ test("rules() - internal - select", function() {
$("#testForm3").validate();
deepEqual( element.rules(), {required: true} );
deepEqual( element.rules(), { required: true } );
});
test("rules() - external", function() {
@@ -41,11 +41,11 @@ test("rules() - external", function() {
$("#form").validate({
rules: {
action: {date: true, min: 5}
action: { date: true, min: 5 }
}
});
deepEqual( element.rules(), {date: true, min: 5} );
deepEqual( element.rules(), { date: true, min: 5 } );
});
test("rules() - external - complete form", function() {
@@ -61,7 +61,7 @@ test("rules() - external - complete form", function() {
});
v = $("#form").validate({
rules: {
action: {verifyTest: true}
action: { verifyTest: true }
}
});
v.form();
@@ -75,7 +75,7 @@ test("rules() - internal - input", function() {
$("#testForm8").validate();
deepEqual( element.rules(), {required: true, number: true, rangelength: [2, 8]});
deepEqual( element.rules(), { required: true, number: true, rangelength: [ 2, 8 ] } );
});
test("rules(), merge min/max to range, minlength/maxlength to rangelength", function() {
@@ -94,9 +94,9 @@ test("rules(), merge min/max to range, minlength/maxlength to rangelength", func
}
});
deepEqual( $("#firstnamec").rules(), {range: [5, 12]});
deepEqual( $("#firstnamec").rules(), { range: [ 5, 12 ] } );
deepEqual( $("#lastnamec").rules(), {rangelength: [2, 8]} );
deepEqual( $("#lastnamec").rules(), { rangelength: [ 2, 8 ] } );
jQuery.validator.autoCreateRanges = false;
});
@@ -142,7 +142,7 @@ test("rules(), evaluate dynamic parameters", function() {
}
});
deepEqual( $("#firstnamec").rules(), {min:12});
deepEqual( $("#firstnamec").rules(), { min: 12 });
});
test("rules(), class and attribute combinations", function() {
@@ -170,8 +170,8 @@ test("rules(), class and attribute combinations", function() {
deepEqual( $("#v2-i4").rules(), { required: true, minlength: 2 });
deepEqual( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" });
jQuery.validator.autoCreateRanges = true;
deepEqual( $("#v2-i5").rules(), { required: true, customMethod1: "123", rangelength: [2, 5] });
deepEqual( $("#v2-i6").rules(), { required: true, customMethod2: true, rangelength: [2, 5] });
deepEqual( $("#v2-i5").rules(), { required: true, customMethod1: "123", rangelength: [ 2, 5 ] });
deepEqual( $("#v2-i6").rules(), { required: true, customMethod2: true, rangelength: [ 2, 5 ] });
jQuery.validator.autoCreateRanges = false;
deepEqual( $("#v2-i7").rules(), { required: true, minlength: 2, customMethod: true });
@@ -207,9 +207,9 @@ test("rules(), dependency checks", function() {
equal( 0, v.objectLength(rules) );
$("#firstnamec").val("ab");
deepEqual( $("#firstnamec").rules(), {min:5});
deepEqual( $("#firstnamec").rules(), { min: 5 });
deepEqual( $("#lastnamec").rules(), {max:12, email:true});
deepEqual( $("#lastnamec").rules(), { max: 12, email: true });
});
test("rules(), add and remove", function() {
@@ -223,7 +223,7 @@ test("rules(), add and remove", function() {
$("#v2-i5").addClass("required").attr(removedAttrs);
deepEqual( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" });
$("#v2-i5").addClass("email").attr({min: 5});
$("#v2-i5").addClass("email").attr({ min: 5 });
deepEqual( $("#v2-i5").rules(), { required: true, email: true, minlength: 2, maxlength: 5, min: 5, customMethod1: "123" });
$("#v2-i5").removeClass("required email").removeAttrs("minlength maxlength customMethod1 min");
@@ -257,7 +257,6 @@ test("rules(), add and remove static rules", function() {
$("#firstnamec").rules("add", "required email");
deepEqual( $("#firstnamec").rules(), { required: true, email: true } );
deepEqual( $("#lastnamec").rules(), {} );
$("#lastnamec").rules("add", "required");
$("#lastnamec").rules("add", {
@@ -265,7 +264,6 @@ test("rules(), add and remove static rules", function() {
});
deepEqual( $("#lastnamec").rules(), { required: true, minlength: 2 } );
var removedRules = $("#lastnamec").rules("remove", "required email");
deepEqual( $("#lastnamec").rules(), { minlength: 2 } );
$("#lastnamec").rules("add", removedRules);
@@ -301,6 +299,6 @@ test( "rules(), rangelength attribute as array", function() {
$("#testForm13").validate();
deepEqual( $("#cars-select").rules(), {
required: true,
rangelength: [2,3]
rangelength: [ 2, 3 ]
});
});

View File

@@ -10,20 +10,27 @@ $.mockjax({
responseStatus: 200,
responseTime: 1
});
$.mockjax({
url: "users.php",
data: { username: /Peter2?|asdf/},
data: {
username: /Peter2?|asdf/
},
responseText: "false",
responseStatus: 200,
responseTime: 1
});
$.mockjax({
url: "users2.php",
data: { username: "asdf"},
data: {
username: "asdf"
},
responseText: "\"asdf is already taken, please try something else\"",
responseStatus: 200,
responseTime: 1
});
$.mockjax({
url: "echo.php",
response: function( data ) {
@@ -155,10 +162,14 @@ test( "form(): checkboxes: min/required", function() {
ok( v.form(), "Valid form" );
});
test( "form(): radio buttons: required", function () {
test( "form(): radio buttons: required", function() {
expect( 6 );
var form = $( "#testForm10" )[ 0 ],
v = $( form ).validate({ rules: { testForm10Radio: "required"} });
v = $( form ).validate({
rules: {
testForm10Radio: "required"
}
});
ok(!v.form(), "Invalid Form" );
equal($( "#testForm10Radio1" ).attr( "class" ), "error" );
@@ -210,7 +221,6 @@ test( "form(): with equalTo and onfocusout=false", function() {
ok( !v.form(), "Invalid form" );
});
test( "check(): simple", function() {
expect( 3 );
var element = $( "#firstname" )[ 0 ],
@@ -231,7 +241,7 @@ test( "hide(): input", function() {
element = $( "#firstname" )[ 0 ],
v;
element.value ="bla";
element.value = "bla";
v = $( "#testForm1" ).validate();
errorLabel.show();
@@ -290,16 +300,24 @@ test( "hide(): container", function() {
test( "valid()", function() {
expect( 4 );
var errorList = [{ name:"meal", message:"foo", element:$( "#meal" )[ 0 ] }],
var errorList = [
{
name: "meal",
message: "foo",
element: $( "#meal" )[ 0 ]
}
],
v = $( "#testForm3" ).validate();
ok( v.valid(), "No errors, must be valid" );
v.errorList = errorList;
ok( !v.valid(), "One error, must be invalid" );
QUnit.reset();
v = $( "#testForm3" ).validate({ submitHandler: function() {
v = $( "#testForm3" ).validate({
submitHandler: function() {
ok( false, "Submit handler was called" );
}});
}
});
ok( v.valid(), "No errors, must be valid and returning true, even with the submit handler" );
v.errorList = errorList;
ok( !v.valid(), "One error, must be invalid, no call to submit handler" );
@@ -348,12 +366,12 @@ asyncTest("validation triggered on radio/checkbox when using keyboard", function
];
input = $("#form :radio:first");
for(i = 0; i < events.length; i++) {
for (i = 0; i < events.length; i++) {
input.trigger(events[i]);
}
input = $("#form :checkbox:first");
for(i = 0; i < events.length; i++) {
for (i = 0; i < events.length; i++) {
input.trigger(events[i]);
}
@@ -379,12 +397,12 @@ asyncTest("validation triggered on radio/checkbox when using mouseclick", functi
];
input = $("#form :radio:first");
for(i = 0; i < events.length; i++) {
for (i = 0; i < events.length; i++) {
input.trigger(events[i]);
}
input = $("#form :checkbox:first");
for(i = 0; i < events.length; i++) {
for (i = 0; i < events.length; i++) {
input.trigger(events[i]);
}
@@ -402,7 +420,7 @@ test( "showErrors()", function() {
ok( errorLabel.is( ":hidden" ) );
equal( 0, $( "#lastname" ).next( ".error:not(input)" ).size() );
v.showErrors({"firstname": "required", "lastname": "bla"});
v.showErrors({ "firstname": "required", "lastname": "bla" });
equal( true, errorLabel.is( ":visible" ) );
equal( true, $( "#lastname" ).next( ".error:not(input)" ).is( ":visible" ) );
});
@@ -612,15 +630,15 @@ test( "formatAndAdd", function() {
var v = $( "#form" ).validate(),
fakeElement = { form: $( "#form" )[ 0 ], name: "bar" };
v.formatAndAdd( fakeElement, {method: "maxlength", parameters: 2});
v.formatAndAdd( fakeElement, { method: "maxlength", parameters: 2 });
equal( "Please enter no more than 2 characters.", v.errorList[ 0 ].message );
equal( "bar", v.errorList[ 0 ].element.name );
v.formatAndAdd( fakeElement, {method: "range", parameters:[2,4]});
equal( "Please enter a value between 2 and 4.", v.errorList[1].message );
v.formatAndAdd( fakeElement, { method: "range", parameters: [ 2, 4 ] });
equal( "Please enter a value between 2 and 4.", v.errorList[ 1 ].message );
v.formatAndAdd( fakeElement, {method: "range", parameters:[0,4]});
equal( "Please enter a value between 0 and 4.", v.errorList[2].message );
v.formatAndAdd( fakeElement, { method: "range", parameters: [ 0, 4 ] });
equal( "Please enter a value between 0 and 4.", v.errorList[ 2 ].message );
});
test( "formatAndAdd2", function() {
@@ -633,7 +651,7 @@ test( "formatAndAdd2", function() {
equal( 0, param );
return "element " + element.name + " is not valid";
};
v.formatAndAdd( fakeElement, {method: "test1", parameters: 0});
v.formatAndAdd( fakeElement, { method: "test1", parameters: 0 });
equal( "element bar is not valid", v.errorList[ 0 ].message );
});
@@ -642,7 +660,7 @@ test( "formatAndAdd, auto detect substitution string", function() {
rules: {
firstnamec: {
required: true,
rangelength: [5, 10]
rangelength: [ 5, 10 ]
}
},
messages: {
@@ -788,7 +806,7 @@ test( "message from title", function() {
});
test( "ignoreTitle", function() {
var v = $( "#withTitle" ).validate({ ignoreTitle:true });
var v = $( "#withTitle" ).validate({ ignoreTitle: true });
v.checkForm();
equal( v.errorList[ 0 ].message, $.validator.messages.required, "title used when it should have been ignored" );
});
@@ -814,7 +832,7 @@ test( "validating groups settings parameter", function() {
var form = $( "<form>" ),
validate = form.validate({
groups: {
arrayGroup: ["input one", "input-two", "input three"],
arrayGroup: [ "input one", "input-two", "input three" ],
stringGroup: "input-four input-five input-six"
}
});
@@ -827,14 +845,14 @@ test( "validating groups settings parameter", function() {
equal( validate.groups[ "input-six" ], "stringGroup" );
});
test( "bypassing validation on form submission",function () {
test( "bypassing validation on form submission", function() {
var form = $( "#bypassValidation" ),
normalSubmission = $( "form#bypassValidation :input[id=normalSubmit]" ),
bypassSubmitWithCancel = $( "form#bypassValidation :input[id=bypassSubmitWithCancel]" ),
bypassSubmitWithNoValidate1 = $( "form#bypassValidation :input[id=bypassSubmitWithNoValidate1]" ),
bypassSubmitWithNoValidate2 = $( "form#bypassValidation :input[id=bypassSubmitWithNoValidate2]" ),
$v = form.validate({
debug : true
debug: true
});
bypassSubmitWithCancel.click();
@@ -853,7 +871,6 @@ test( "bypassing validation on form submission",function () {
equal($v.numberOfInvalids(), 1, "Validation failed correctly" );
});
module( "misc" );
test( "success option", function() {
@@ -961,7 +978,6 @@ test( "success is called for optional elements with other rules", function() {
delete $.validator.methods.custom1;
});
test( "success callback with element", function() {
expect( 1 );
var v = $( "#userForm" ).validate({
@@ -984,7 +1000,10 @@ test( "all rules are evaluated even if one returns a dependency-mistmatch", func
}, "" );
var v = $( "#testForm1" ).validate({
rules: {
firstname: {email:true, custom1: true}
firstname: {
email: true,
custom1: true
}
}
});
equal( 0, $( "#testForm1 .error:not(input)" ).size() );
@@ -1001,10 +1020,10 @@ test( "messages", function() {
var m = jQuery.validator.messages;
equal( "Please enter no more than 0 characters.", m.maxlength( 0 ) );
equal( "Please enter at least 1 characters.", m.minlength( 1 ) );
equal( "Please enter a value between 1 and 2 characters long.", m.rangelength([1, 2]) );
equal( "Please enter a value between 1 and 2 characters long.", m.rangelength( [ 1, 2 ] ) );
equal( "Please enter a value less than or equal to 1.", m.max( 1 ) );
equal( "Please enter a value greater than or equal to 0.", m.min( 0 ) );
equal( "Please enter a value between 1 and 2.", m.range([1, 2]) );
equal( "Please enter a value between 1 and 2.", m.range( [ 1, 2 ] ) );
});
test( "jQuery.validator.format", function() {
@@ -1058,7 +1077,7 @@ test( "expression: :blank", function() {
equal( 1, $( e ).filter( ":blank" ).length );
e.value = " ";
equal( 1, $( e ).filter( ":blank" ).length );
e.value= " a ";
e.value = " a ";
equal( 0, $( e ).filter( ":blank" ).length );
});
@@ -1069,7 +1088,7 @@ test( "expression: :filled", function() {
equal( 0, $( e ).filter( ":filled" ).length );
e.value = " ";
equal( 0, $( e ).filter( ":filled" ).length );
e.value= " a ";
e.value = " a ";
equal( 1, $( e ).filter( ":filled" ).length );
});
@@ -1267,7 +1286,7 @@ test( "validate multiple checkbox on click", function() {
errors( 1 );
});
test( "correct checkbox receives the error", function(){
test( "correct checkbox receives the error", function() {
function trigger( element ) {
element.click();
// triggered click event screws up checked-state in 1.4
@@ -1278,7 +1297,7 @@ test( "correct checkbox receives the error", function(){
$( "#check1b" ).attr( "checked", false );
v = $( "#form" ).find( "[type=checkbox]" ).attr( "checked", false ).end().validate({
rules:{
rules: {
check: {
required: true,
minlength: 2
@@ -1333,24 +1352,24 @@ test( "validate input with no type attribute, defaulting to text", function() {
errors( 0 );
});
test( "ignore hidden elements", function(){
test( "ignore hidden elements", function() {
var form = $( "#userForm" ),
validate = form.validate({
rules:{
rules: {
"username": "required"
}
});
form.get( 0 ).reset();
ok(! validate.form(), "form should be initially invalid" );
ok( !validate.form(), "form should be initially invalid" );
$( "#userForm [name=username]" ).hide();
ok( validate.form(), "hidden elements should be ignored by default" );
});
test( "ignore hidden elements at start", function(){
test( "ignore hidden elements at start", function() {
var form = $( "#userForm" ),
validate = form.validate({
rules:{
rules: {
"username": "required"
}
});
@@ -1359,7 +1378,7 @@ test( "ignore hidden elements at start", function(){
$( "#userForm [name=username]" ).hide();
ok( validate.form(), "hidden elements should be ignored by default" );
$( "#userForm [name=username]" ).show();
ok(! validate.form(), "form should be invalid when required element is visible" );
ok( !validate.form(), "form should be invalid when required element is visible" );
});
test( "Specify error messages through data attributes", function() {
@@ -1539,7 +1558,6 @@ test( "calling blur on ignored element", function() {
equal( form.valid(), false, "valid() should return false" );
});
test( "Min and Max type absent set by attributes greater", function() {
var form = $( "#ranges" ),
name = $( "#rangeAbsentInvalidGreater" ),
@@ -1579,8 +1597,6 @@ test( "Min and Max type absent set by attributes valid", function() {
equal( label.text(), "", "Correct error label" );
});
test( "Min and Max range set by attributes valid", function() {
//
// cannot test for overflow:
@@ -1601,7 +1617,6 @@ test( "Min and Max range set by attributes valid", function() {
equal( label.text(), "", "Correct error label" );
});
test( "Min and Max number set by attributes valid", function() {
var form = $( "#ranges" ),
name = $( "#rangeNumberValid" ),
@@ -1615,7 +1630,6 @@ test( "Min and Max number set by attributes valid", function() {
equal( label.text(), "", "Correct error label" );
});
test( "Min and Max number set by attributes greater", function() {
var form = $( "#ranges" ),
name = $( "#rangeNumberInvalidGreater" ),
@@ -1629,7 +1643,6 @@ test( "Min and Max number set by attributes greater", function() {
equal( label.text(), "Please enter a value less than or equal to 200.", "Correct error label" );
});
test( "Min and Max number set by attributes less", function() {
var form = $( "#ranges" ),
name = $( "#rangeNumberInvalidLess" ),