mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-24 12:13:59 +01:00
Update testsuite to use equal and deepEqual. Fix tests that the fix for #219 (732f5ff04b) broke. The element method now returns true for dependency-mismatch, that's fine.
This commit is contained in:
236
test/test.js
236
test/test.js
@@ -28,8 +28,8 @@ module("validator");
|
||||
test("Constructor", function() {
|
||||
var v1 = $("#testForm1").validate();
|
||||
var v2 = $("#testForm1").validate();
|
||||
equals( v1, v2, "Calling validate() multiple times must return the same validator instance" );
|
||||
equals( v1.elements().length, 3, "validator elements" );
|
||||
equal( v1, v2, "Calling validate() multiple times must return the same validator instance" );
|
||||
equal( v1.elements().length, 3, "validator elements" );
|
||||
});
|
||||
|
||||
test("validate() without elements, with non-form elements", function() {
|
||||
@@ -96,8 +96,8 @@ test("addMethod2", function() {
|
||||
var rule = $.validator.methods.complicatedPassword,
|
||||
e = $('#text1')[0];
|
||||
e.value = "";
|
||||
ok( v.element(e) === undefined, "Rule is optional, valid" );
|
||||
equals( 0, v.size() );
|
||||
strictEqual( v.element(e), true, "Rule is optional, valid" );
|
||||
equal( 0, v.size() );
|
||||
e.value = "ko";
|
||||
ok( !v.element(e), "Invalid, doesn't contain one of the required characters" );
|
||||
e.value = "ko1";
|
||||
@@ -131,14 +131,14 @@ test("form(): radio buttons: required", function () {
|
||||
|
||||
var v = $(form).validate({ rules: { testForm10Radio: "required"} });
|
||||
ok(!v.form(), 'Invalid Form');
|
||||
equals($('#testForm10Radio1').attr('class'), 'error');
|
||||
equals($('#testForm10Radio2').attr('class'), 'error');
|
||||
equal($('#testForm10Radio1').attr('class'), 'error');
|
||||
equal($('#testForm10Radio2').attr('class'), 'error');
|
||||
|
||||
$('#testForm10Radio2').attr("checked", true);
|
||||
ok(v.form(), 'Valid form');
|
||||
|
||||
equals($('#testForm10Radio1').attr('class'), 'valid');
|
||||
equals($('#testForm10Radio2').attr('class'), 'valid');
|
||||
equal($('#testForm10Radio1').attr('class'), 'valid');
|
||||
equal($('#testForm10Radio2').attr('class'), 'valid');
|
||||
});
|
||||
|
||||
test("form(): selects: min/required", function() {
|
||||
@@ -251,8 +251,8 @@ test("submitHandler keeps submitting button", function() {
|
||||
submitHandler: function(form) {
|
||||
// dunno how to test this better; this tests the implementation that uses a hidden input
|
||||
var hidden = $(form).find("input:hidden")[0];
|
||||
same(hidden.value, button.value)
|
||||
same(hidden.name, button.name)
|
||||
deepEqual(hidden.value, button.value)
|
||||
deepEqual(hidden.name, button.name)
|
||||
}
|
||||
});
|
||||
$("#username").val("bla");
|
||||
@@ -267,10 +267,10 @@ test("showErrors()", function() {
|
||||
var element = $('#firstname')[0];
|
||||
var v = $('#testForm1').validate();
|
||||
ok( errorLabel.is(":hidden") );
|
||||
equals( 0, $("label.error[for=lastname]").size() );
|
||||
equal( 0, $("label.error[for=lastname]").size() );
|
||||
v.showErrors({"firstname": "required", "lastname": "bla"});
|
||||
equals( true, errorLabel.is(":visible") );
|
||||
equals( true, $("label.error[for=lastname]").is(":visible") );
|
||||
equal( true, errorLabel.is(":visible") );
|
||||
equal( true, $("label.error[for=lastname]").is(":visible") );
|
||||
});
|
||||
|
||||
test("showErrors(), allow empty string and null as default message", function() {
|
||||
@@ -289,11 +289,11 @@ test("showErrors(), allow empty string and null as default message", function()
|
||||
}
|
||||
});
|
||||
ok( !$("#username").valid() );
|
||||
equals( "", $("label.error[for=username]").text() );
|
||||
equal( "", $("label.error[for=username]").text() );
|
||||
|
||||
$("#username").val("ab");
|
||||
ok( !$("#username").valid() );
|
||||
equals( "too short", $("label.error[for=username]").text() );
|
||||
equal( "too short", $("label.error[for=username]").text() );
|
||||
|
||||
$("#username").val("abc");
|
||||
ok( $("#username").valid() );
|
||||
@@ -306,8 +306,8 @@ test("showErrors() - external messages", function() {
|
||||
var messages = $.extend({}, $.validator.messages);
|
||||
$.validator.addMethod("foo", function() { return false; });
|
||||
$.validator.addMethod("bar", function() { return false; });
|
||||
equals( 0, $("#testForm4 label.error[for=f1]").size() );
|
||||
equals( 0, $("#testForm4 label.error[for=f2]").size() );
|
||||
equal( 0, $("#testForm4 label.error[for=f1]").size() );
|
||||
equal( 0, $("#testForm4 label.error[for=f2]").size() );
|
||||
var form = $('#testForm4')[0];
|
||||
var v = $(form).validate({
|
||||
messages: {
|
||||
@@ -316,8 +316,8 @@ test("showErrors() - external messages", function() {
|
||||
}
|
||||
});
|
||||
v.form();
|
||||
equals( $("#testForm4 label.error[for=f1]").text(), "Please!" );
|
||||
equals( $("#testForm4 label.error[for=f2]").text(), "Wohoo!" );
|
||||
equal( $("#testForm4 label.error[for=f1]").text(), "Please!" );
|
||||
equal( $("#testForm4 label.error[for=f2]").text(), "Wohoo!" );
|
||||
|
||||
$.validator.methods = methods;
|
||||
$.validator.messages = messages;
|
||||
@@ -327,11 +327,11 @@ test("showErrors() - custom handler", function() {
|
||||
expect(5);
|
||||
var v = $('#testForm1').validate({
|
||||
showErrors: function(errorMap, errorList) {
|
||||
equals( v, this );
|
||||
equals( v.errorList, errorList );
|
||||
equals( v.errorMap, errorMap );
|
||||
equals( "buga", errorMap.firstname );
|
||||
equals( "buga", errorMap.lastname );
|
||||
equal( v, this );
|
||||
equal( v.errorList, errorList );
|
||||
equal( v.errorMap, errorMap );
|
||||
equal( "buga", errorMap.firstname );
|
||||
equal( "buga", errorMap.lastname );
|
||||
}
|
||||
});
|
||||
v.form();
|
||||
@@ -368,11 +368,11 @@ test("option: (un)highlight, custom", function() {
|
||||
expect(5);
|
||||
$("#testForm1clean").validate({
|
||||
highlight: function(element, errorClass) {
|
||||
equals( "invalid", errorClass );
|
||||
equal( "invalid", errorClass );
|
||||
$(element).hide();
|
||||
},
|
||||
unhighlight: function(element, errorClass) {
|
||||
equals( "invalid", errorClass )
|
||||
equal( "invalid", errorClass )
|
||||
$(element).show();
|
||||
},
|
||||
errorClass: "invalid",
|
||||
@@ -462,7 +462,7 @@ test("elements() order", function() {
|
||||
|
||||
test("defaultMessage(), empty title is ignored", function() {
|
||||
var v = $("#userForm").validate();
|
||||
equals( "This field is required.", v.defaultMessage($("#username")[0], "required") );
|
||||
equal( "This field is required.", v.defaultMessage($("#username")[0], "required") );
|
||||
});
|
||||
|
||||
test("formatAndAdd", function() {
|
||||
@@ -470,14 +470,14 @@ test("formatAndAdd", function() {
|
||||
var v = $("#form").validate();
|
||||
var fakeElement = { form: $("#form")[0], name: "bar" };
|
||||
v.formatAndAdd(fakeElement, {method: "maxlength", parameters: 2})
|
||||
equals( "Please enter no more than 2 characters.", v.errorList[0].message );
|
||||
equals( "bar", v.errorList[0].element.name );
|
||||
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]})
|
||||
equals( "Please enter a value between 2 and 4.", v.errorList[1].message );
|
||||
equal( "Please enter a value between 2 and 4.", v.errorList[1].message );
|
||||
|
||||
v.formatAndAdd(fakeElement, {method: "range", parameters:[0,4]})
|
||||
equals( "Please enter a value between 0 and 4.", v.errorList[2].message );
|
||||
equal( "Please enter a value between 0 and 4.", v.errorList[2].message );
|
||||
});
|
||||
|
||||
test("formatAndAdd2", function() {
|
||||
@@ -485,12 +485,12 @@ test("formatAndAdd2", function() {
|
||||
var v = $("#form").validate();
|
||||
var fakeElement = { form: $("#form")[0], name: "bar" };
|
||||
jQuery.validator.messages.test1 = function(param, element) {
|
||||
equals( v, this );
|
||||
equals( 0, param );
|
||||
equal( v, this );
|
||||
equal( 0, param );
|
||||
return "element " + element.name + " is not valid";
|
||||
};
|
||||
v.formatAndAdd(fakeElement, {method: "test1", parameters: 0})
|
||||
equals( "element bar is not valid", v.errorList[0].message );
|
||||
equal( "element bar is not valid", v.errorList[0].message );
|
||||
});
|
||||
|
||||
test("formatAndAdd, auto detect substitution string", function() {
|
||||
@@ -509,7 +509,7 @@ test("formatAndAdd, auto detect substitution string", function() {
|
||||
});
|
||||
$("#firstnamec").val("abc");
|
||||
v.form();
|
||||
equals( "at least 5, up to 10", v.errorList[0].message );
|
||||
equal( "at least 5, up to 10", v.errorList[0].message );
|
||||
})
|
||||
|
||||
test("error containers, simple", function() {
|
||||
@@ -525,24 +525,24 @@ test("error containers, simple", function() {
|
||||
|
||||
v.prepareForm();
|
||||
ok( v.valid(), "form is valid" );
|
||||
equals( 0, container.find("label").length, "There should be no error labels" );
|
||||
equals( "", container.find("h3").html() );
|
||||
equal( 0, container.find("label").length, "There should be no error labels" );
|
||||
equal( "", container.find("h3").html() );
|
||||
|
||||
v.prepareForm();
|
||||
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();
|
||||
equals( container.find("label").length, 2, "There should be two error labels" );
|
||||
equal( container.find("label").length, 2, "There should be two error labels" );
|
||||
ok( container.is(":visible"), "Check that the container is visible" );
|
||||
container.find("label").each(function() {
|
||||
ok( $(this).is(":visible"), "Check that each label is visible" );
|
||||
});
|
||||
equals( "There are 2 errors in your form.", container.find("h3").html() );
|
||||
equal( "There are 2 errors in your form.", container.find("h3").html() );
|
||||
|
||||
v.prepareForm();
|
||||
ok( v.valid(), "form is valid after a reset" );
|
||||
v.showErrors();
|
||||
equals( container.find("label").length, 2, "There should still be two error labels" );
|
||||
equal( container.find("label").length, 2, "There should still be two error labels" );
|
||||
ok( container.is(":hidden"), "Check that the container is hidden" );
|
||||
container.find("label").each(function() {
|
||||
ok( $(this).is(":hidden"), "Check that each label is hidden" );
|
||||
@@ -560,21 +560,21 @@ test("error containers, with labelcontainer I", function() {
|
||||
});
|
||||
|
||||
ok( v.valid(), "form is valid" );
|
||||
equals( 0, container.find("label").length, "There should be no error labels in the container" );
|
||||
equals( 0, labelcontainer.find("label").length, "There should be no error labels in the labelcontainer" );
|
||||
equals( 0, labelcontainer.find("li").length, "There should be no lis labels in the labelcontainer" );
|
||||
equal( 0, container.find("label").length, "There should be no error labels in the container" );
|
||||
equal( 0, labelcontainer.find("label").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"}}];
|
||||
ok( !v.valid(), "form is not valid after adding errors manually" );
|
||||
v.showErrors();
|
||||
equals( 0, container.find("label").length, "There should be no error label in the container" );
|
||||
equals( 2, labelcontainer.find("label").length, "There should be two error labels in the labelcontainer" );
|
||||
equals( 2, labelcontainer.find("li").length, "There should be two error lis in the labelcontainer" );
|
||||
equal( 0, container.find("label").length, "There should be no error label in the container" );
|
||||
equal( 2, labelcontainer.find("label").length, "There should be two error labels in the labelcontainer" );
|
||||
equal( 2, labelcontainer.find("li").length, "There should be two error lis in the labelcontainer" );
|
||||
ok( container.is(":visible"), "Check that the container is visible" );
|
||||
ok( labelcontainer.is(":visible"), "Check that the labelcontainer is visible" );
|
||||
var labels = labelcontainer.find("label").each(function() {
|
||||
ok( $(this).is(":visible"), "Check that each label is visible1" );
|
||||
equals( "li", $(this).parent()[0].tagName.toLowerCase(), "Check that each label is wrapped in an li" );
|
||||
equal( "li", $(this).parent()[0].tagName.toLowerCase(), "Check that each label is wrapped in an li" );
|
||||
ok( $(this).parent("li").is(":visible"), "Check that each parent li is visible" );
|
||||
});
|
||||
});
|
||||
@@ -594,20 +594,20 @@ test("errorcontainer, show/hide only on submit", function() {
|
||||
this.defaultShowErrors();
|
||||
}
|
||||
});
|
||||
equals( "", container.html(), "must be empty" );
|
||||
equals( "", labelContainer.html(), "must be empty" );
|
||||
equal( "", container.html(), "must be empty" );
|
||||
equal( "", labelContainer.html(), "must be empty" );
|
||||
// validate whole form, both showErrors and invalidHandler must be called once
|
||||
// preferably invalidHandler first, showErrors second
|
||||
ok( !v.form(), "invalid form" );
|
||||
equals( 2, labelContainer.find("label").length );
|
||||
equals( "There are 2 errors in your form.", container.html() );
|
||||
equal( 2, labelContainer.find("label").length );
|
||||
equal( "There are 2 errors in your form.", container.html() );
|
||||
ok( labelContainer.is(":visible"), "must be visible" );
|
||||
ok( container.is(":visible"), "must be visible" );
|
||||
|
||||
$("#firstname").val("hix").keyup();
|
||||
$("#testForm1").triggerHandler("keyup", [jQuery.event.fix({ type: "keyup", target: $("#firstname")[0] })]);
|
||||
equals( 1, labelContainer.find("label:visible").length );
|
||||
equals( "There are 1 errors in your form.", container.html() );
|
||||
equal( 1, labelContainer.find("label:visible").length );
|
||||
equal( "There are 1 errors in your form.", container.html() );
|
||||
|
||||
$("#lastname").val("abc");
|
||||
ok( v.form(), "Form now valid, trigger showErrors but not invalid-form" );
|
||||
@@ -635,7 +635,7 @@ test("focusInvalid()", function() {
|
||||
// TODO when using 1.4 focusin, triggered twice; fix once not testing against 1.3 anymore
|
||||
// expect(1);
|
||||
var inputs = $("#testForm1 input").focus(function() {
|
||||
equals( inputs[0], this, "focused first element" );
|
||||
equal( inputs[0], this, "focused first element" );
|
||||
});
|
||||
var v = $("#testForm1").validate();
|
||||
v.form();
|
||||
@@ -648,9 +648,9 @@ test("findLastActive()", function() {
|
||||
ok( !v.findLastActive() );
|
||||
v.form();
|
||||
v.focusInvalid();
|
||||
equals( v.findLastActive(), $("#firstname")[0] );
|
||||
equal( v.findLastActive(), $("#firstname")[0] );
|
||||
var lastActive = $("#lastname").trigger("focus").trigger("focusin")[0];
|
||||
equals( v.lastActive, lastActive );
|
||||
equal( v.lastActive, lastActive );
|
||||
});
|
||||
|
||||
test("validating multiple checkboxes with 'required'", function() {
|
||||
@@ -675,7 +675,7 @@ test("dynamic form", function() {
|
||||
$("<input class='{required:true}' name='list" + counter++ + "' />").appendTo("#testForm2");
|
||||
}
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
var v = $("#testForm2").validate();
|
||||
v.form();
|
||||
@@ -706,15 +706,15 @@ test("dynamic form", function() {
|
||||
test("idOrName()", function() {
|
||||
expect(4);
|
||||
var v = $("#testForm1").validate();
|
||||
equals( "form8input", v.idOrName( $("#form8input")[0] ) );
|
||||
equals( "check", v.idOrName( $("#form6check1")[0] ) );
|
||||
equals( "agree", v.idOrName( $("#agb")[0] ) );
|
||||
equals( "button", v.idOrName( $("#form :button")[0] ) );
|
||||
equal( "form8input", v.idOrName( $("#form8input")[0] ) );
|
||||
equal( "check", v.idOrName( $("#form6check1")[0] ) );
|
||||
equal( "agree", v.idOrName( $("#agb")[0] ) );
|
||||
equal( "button", v.idOrName( $("#form :button")[0] ) );
|
||||
});
|
||||
|
||||
test("resetForm()", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
var v = $("#testForm1").validate();
|
||||
v.form();
|
||||
@@ -722,19 +722,19 @@ test("resetForm()", function() {
|
||||
$("#firstname").val("hiy");
|
||||
v.resetForm();
|
||||
errors(0);
|
||||
equals("", $("#firstname").val(), "form plugin is included, therefor resetForm must also reset inputs, not only errors");
|
||||
equal("", $("#firstname").val(), "form plugin is included, therefor resetForm must also reset inputs, not only errors");
|
||||
});
|
||||
|
||||
test("message from title", function() {
|
||||
var v = $("#withTitle").validate();
|
||||
v.checkForm();
|
||||
equals(v.errorList[0].message, "fromtitle", "title not used");
|
||||
equal(v.errorList[0].message, "fromtitle", "title not used");
|
||||
});
|
||||
|
||||
test("ignoreTitle", function() {
|
||||
var v = $("#withTitle").validate({ignoreTitle:true});
|
||||
v.checkForm();
|
||||
equals(v.errorList[0].message, $.validator.messages["required"], "title used when it should have been ignored");
|
||||
equal(v.errorList[0].message, $.validator.messages["required"], "title used when it should have been ignored");
|
||||
});
|
||||
|
||||
test("ajaxSubmit", function() {
|
||||
@@ -746,7 +746,7 @@ test("ajaxSubmit", function() {
|
||||
submitHandler: function(form) {
|
||||
jQuery(form).ajaxSubmit({
|
||||
success: function(response) {
|
||||
equals("Hi Peter, welcome back.", response);
|
||||
equal("Hi Peter, welcome back.", response);
|
||||
start();
|
||||
}
|
||||
});
|
||||
@@ -760,7 +760,7 @@ module("misc");
|
||||
|
||||
test("success option", function() {
|
||||
expect(7);
|
||||
equals( "", $("#firstname").val() );
|
||||
equal( "", $("#firstname").val() );
|
||||
var v = $("#testForm1").validate({
|
||||
success: "valid"
|
||||
});
|
||||
@@ -778,7 +778,7 @@ test("success option", function() {
|
||||
|
||||
test("success option2", function() {
|
||||
expect(5);
|
||||
equals( "", $("#firstname").val() );
|
||||
equal( "", $("#firstname").val() );
|
||||
var v = $("#testForm1").validate({
|
||||
success: "valid"
|
||||
});
|
||||
@@ -793,16 +793,16 @@ test("success option2", function() {
|
||||
|
||||
test("success option3", function() {
|
||||
expect(5);
|
||||
equals( "", $("#firstname").val() );
|
||||
equal( "", $("#firstname").val() );
|
||||
$("#errorFirstname").remove();
|
||||
var v = $("#testForm1").validate({
|
||||
success: "valid"
|
||||
});
|
||||
equals( 0, $("#testForm1 label").size() );
|
||||
equal( 0, $("#testForm1 label").size() );
|
||||
$("#firstname").val("hi");
|
||||
v.form();
|
||||
var labels = $("#testForm1 label");
|
||||
equals( 3, labels.size() );
|
||||
equal( 3, labels.size() );
|
||||
ok( labels.eq(0).is(".valid") );
|
||||
ok( !labels.eq(1).is(".valid") );
|
||||
});
|
||||
@@ -810,12 +810,12 @@ test("success option3", function() {
|
||||
test("successlist", function() {
|
||||
var v = $("#form").validate({ success: "xyz" });
|
||||
v.form();
|
||||
equals(0, v.successList.length);
|
||||
equal(0, v.successList.length);
|
||||
});
|
||||
|
||||
test("success isn't called for optional elements", function() {
|
||||
expect(4);
|
||||
equals( "", $("#firstname").removeClass().val() );
|
||||
equal( "", $("#firstname").removeClass().val() );
|
||||
$("#something").remove();
|
||||
$("#lastname").remove();
|
||||
$("#errorFirstname").remove();
|
||||
@@ -827,16 +827,16 @@ test("success isn't called for optional elements", function() {
|
||||
firstname: "email"
|
||||
}
|
||||
});
|
||||
equals( 0, $("#testForm1 label").size() );
|
||||
equal( 0, $("#testForm1 label").size() );
|
||||
v.form();
|
||||
equals( 0, $("#testForm1 label").size() );
|
||||
equal( 0, $("#testForm1 label").size() );
|
||||
$("#firstname").valid();
|
||||
equals( 0, $("#testForm1 label").size() );
|
||||
equal( 0, $("#testForm1 label").size() );
|
||||
});
|
||||
|
||||
test("all rules are evaluated even if one returns a dependency-mistmatch", function() {
|
||||
expect(6);
|
||||
equals( "", $("#firstname").removeClass().val() );
|
||||
equal( "", $("#firstname").removeClass().val() );
|
||||
$("#lastname").remove();
|
||||
$("#errorFirstname").remove();
|
||||
$.validator.addMethod("custom1", function() {
|
||||
@@ -848,11 +848,11 @@ test("all rules are evaluated even if one returns a dependency-mistmatch", funct
|
||||
firstname: {email:true, custom1: true}
|
||||
}
|
||||
});
|
||||
equals( 0, $("#testForm1 label").size() );
|
||||
equal( 0, $("#testForm1 label").size() );
|
||||
v.form();
|
||||
equals( 0, $("#testForm1 label").size() );
|
||||
equal( 0, $("#testForm1 label").size() );
|
||||
$("#firstname").valid();
|
||||
equals( 0, $("#testForm1 label").size() );
|
||||
equal( 0, $("#testForm1 label").size() );
|
||||
|
||||
delete $.validator.methods.custom1;
|
||||
delete $.validator.messages.custom1;
|
||||
@@ -860,21 +860,21 @@ test("all rules are evaluated even if one returns a dependency-mistmatch", funct
|
||||
|
||||
test("messages", function() {
|
||||
var m = jQuery.validator.messages;
|
||||
equals( "Please enter no more than 0 characters.", m.maxlength(0) );
|
||||
equals( "Please enter at least 1 characters.", m.minlength(1) );
|
||||
equals( "Please enter a value between 1 and 2 characters long.", m.rangelength([1, 2]) );
|
||||
equals( "Please enter a value less than or equal to 1.", m.max(1) );
|
||||
equals( "Please enter a value greater than or equal to 0.", m.min(0) );
|
||||
equals( "Please enter a value between 1 and 2.", m.range([1, 2]) );
|
||||
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 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]) );
|
||||
});
|
||||
|
||||
test("jQuery.validator.format", function() {
|
||||
equals( "Please enter a value between 0 and 1.", jQuery.validator.format("Please enter a value between {0} and {1}.", 0, 1) );
|
||||
equals( "0 is too fast! Enter a value smaller then 0 and at least -15", jQuery.validator.format("{0} is too fast! Enter a value smaller then {0} and at least {1}", 0, -15) );
|
||||
equal( "Please enter a value between 0 and 1.", jQuery.validator.format("Please enter a value between {0} and {1}.", 0, 1) );
|
||||
equal( "0 is too fast! Enter a value smaller then 0 and at least -15", jQuery.validator.format("{0} is too fast! Enter a value smaller then {0} and at least {1}", 0, -15) );
|
||||
var template = jQuery.validator.format("{0} is too fast! Enter a value smaller then {0} and at least {1}");
|
||||
equals( "0 is too fast! Enter a value smaller then 0 and at least -15", template(0, -15) );
|
||||
equal( "0 is too fast! Enter a value smaller then 0 and at least -15", template(0, -15) );
|
||||
template = jQuery.validator.format("Please enter a value between {0} and {1}.");
|
||||
equals( "Please enter a value between 1 and 2.", template([1, 2]) );
|
||||
equal( "Please enter a value between 1 and 2.", template([1, 2]) );
|
||||
});
|
||||
|
||||
test("option: ignore", function() {
|
||||
@@ -882,7 +882,7 @@ test("option: ignore", function() {
|
||||
ignore: "[name=lastname]"
|
||||
});
|
||||
v.form();
|
||||
equals( 1, v.size() );
|
||||
equal( 1, v.size() );
|
||||
});
|
||||
|
||||
test("option: subformRequired", function() {
|
||||
@@ -893,10 +893,10 @@ test("option: subformRequired", function() {
|
||||
}, "");
|
||||
var v = $("#subformRequired").validate();
|
||||
v.form();
|
||||
equals( 1, v.size() );
|
||||
equal( 1, v.size() );
|
||||
$("#bill_to_co").attr("checked", false);
|
||||
v.form();
|
||||
equals( 2, v.size() );
|
||||
equal( 2, v.size() );
|
||||
|
||||
delete $.validator.methods.billingRequired;
|
||||
delete $.validator.messages.billingRequired;
|
||||
@@ -906,43 +906,43 @@ module("expressions");
|
||||
|
||||
test("expression: :blank", function() {
|
||||
var e = $("#lastname")[0];
|
||||
equals( 1, $(e).filter(":blank").length );
|
||||
equal( 1, $(e).filter(":blank").length );
|
||||
e.value = " ";
|
||||
equals( 1, $(e).filter(":blank").length );
|
||||
equal( 1, $(e).filter(":blank").length );
|
||||
e.value = " "
|
||||
equals( 1, $(e).filter(":blank").length );
|
||||
equal( 1, $(e).filter(":blank").length );
|
||||
e.value= " a ";
|
||||
equals( 0, $(e).filter(":blank").length );
|
||||
equal( 0, $(e).filter(":blank").length );
|
||||
});
|
||||
|
||||
test("expression: :filled", function() {
|
||||
var e = $("#lastname")[0];
|
||||
equals( 0, $(e).filter(":filled").length );
|
||||
equal( 0, $(e).filter(":filled").length );
|
||||
e.value = " ";
|
||||
equals( 0, $(e).filter(":filled").length );
|
||||
equal( 0, $(e).filter(":filled").length );
|
||||
e.value = " "
|
||||
equals( 0, $(e).filter(":filled").length );
|
||||
equal( 0, $(e).filter(":filled").length );
|
||||
e.value= " a ";
|
||||
equals( 1, $(e).filter(":filled").length );
|
||||
equal( 1, $(e).filter(":filled").length );
|
||||
});
|
||||
|
||||
test("expression: :unchecked", function() {
|
||||
var e = $("#check2")[0];
|
||||
equals( 1, $(e).filter(":unchecked").length );
|
||||
equal( 1, $(e).filter(":unchecked").length );
|
||||
e.checked = true;
|
||||
equals( 0, $(e).filter(":unchecked").length );
|
||||
equal( 0, $(e).filter(":unchecked").length );
|
||||
e.checked = false;
|
||||
equals( 1, $(e).filter(":unchecked").length );
|
||||
equal( 1, $(e).filter(":unchecked").length );
|
||||
});
|
||||
|
||||
module("events");
|
||||
|
||||
test("validate on blur", function() {
|
||||
function errors(expected, message) {
|
||||
equals(v.size(), expected, message );
|
||||
equal(v.size(), expected, message );
|
||||
}
|
||||
function labels(expected) {
|
||||
equals(v.errors().filter(":visible").size(), expected);
|
||||
equal(v.errors().filter(":visible").size(), expected);
|
||||
}
|
||||
function blur(target) {
|
||||
target.trigger("blur").trigger("focusout");
|
||||
@@ -981,7 +981,7 @@ test("validate on blur", function() {
|
||||
|
||||
test("validate on keyup", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
function keyup(target) {
|
||||
target.trigger("keyup");
|
||||
@@ -1011,7 +1011,7 @@ test("validate on keyup", function() {
|
||||
|
||||
test("validate on not keyup, only blur", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
var e = $("#firstname");
|
||||
var v = $("#testForm1").validate({
|
||||
@@ -1028,7 +1028,7 @@ test("validate on not keyup, only blur", function() {
|
||||
|
||||
test("validate on keyup and blur", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
var e = $("#firstname");
|
||||
var v = $("#testForm1").validate();
|
||||
@@ -1042,7 +1042,7 @@ test("validate on keyup and blur", function() {
|
||||
|
||||
test("validate email on keyup and blur", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
var e = $("#firstname");
|
||||
var v = $("#testForm1").validate();
|
||||
@@ -1058,7 +1058,7 @@ test("validate email on keyup and blur", function() {
|
||||
|
||||
test("validate checkbox on click", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
function trigger(element) {
|
||||
element.click();
|
||||
@@ -1074,7 +1074,7 @@ test("validate checkbox on click", function() {
|
||||
trigger(e);
|
||||
errors(0);
|
||||
trigger(e);
|
||||
equals( false, v.form() );
|
||||
equal( false, v.form() );
|
||||
errors(1);
|
||||
trigger(e);
|
||||
errors(0);
|
||||
@@ -1084,7 +1084,7 @@ test("validate checkbox on click", function() {
|
||||
|
||||
test("validate multiple checkbox on click", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
function trigger(element) {
|
||||
element.click();
|
||||
@@ -1105,7 +1105,7 @@ test("validate multiple checkbox on click", function() {
|
||||
trigger(e2);
|
||||
errors(0);
|
||||
trigger(e2);
|
||||
equals( false, v.form() );
|
||||
equal( false, v.form() );
|
||||
errors(1);
|
||||
trigger(e2);
|
||||
errors(0);
|
||||
@@ -1129,15 +1129,15 @@ test("correct checkbox receives the error", function(){
|
||||
}
|
||||
}
|
||||
});
|
||||
equals(false, v.form());
|
||||
equal(false, v.form());
|
||||
trigger(e1);
|
||||
equals(false, v.form());
|
||||
equal(false, v.form());
|
||||
ok(v.errorList[0].element.id === v.currentElements[0].id, "the proper checkbox has the error AND is present in currentElements");
|
||||
});
|
||||
|
||||
test("validate radio on click", function() {
|
||||
function errors(expected, message) {
|
||||
equals(expected, v.size(), message );
|
||||
equal(expected, v.size(), message );
|
||||
}
|
||||
function trigger(element) {
|
||||
element.click();
|
||||
@@ -1152,7 +1152,7 @@ test("validate radio on click", function() {
|
||||
}
|
||||
});
|
||||
errors(0);
|
||||
equals( false, v.form() );
|
||||
equal( false, v.form() );
|
||||
errors(1);
|
||||
trigger(e2);
|
||||
errors(0);
|
||||
|
||||
Reference in New Issue
Block a user