From 842e7ff5ddf7f9c092e811e8bb0ab573ae3dc49e Mon Sep 17 00:00:00 2001 From: Brahim Arkni Date: Sat, 19 Sep 2015 16:58:16 +0100 Subject: [PATCH] Test: Fix misuse of `equal` method & some spacing issues. --- test/aria.js | 96 +-- test/error-placement.js | 60 +- test/messages.js | 85 +-- test/methods.js | 1358 +++++++++++++++++++-------------------- test/rules.js | 300 ++++----- test/test.js | 678 +++++++++---------- 6 files changed, 1290 insertions(+), 1287 deletions(-) diff --git a/test/aria.js b/test/aria.js index 8ac7d1b..0bfc129 100644 --- a/test/aria.js +++ b/test/aria.js @@ -1,83 +1,83 @@ -module("aria"); +module( "aria" ); -test("Invalid field adds aria-invalid=true", function() { - var ariaInvalidFirstName = $("#ariaInvalidFirstName"), - form = $("#ariaInvalid"); +test( "Invalid field adds aria-invalid=true", function() { + var ariaInvalidFirstName = $( "#ariaInvalidFirstName" ), + form = $( "#ariaInvalid" ); - form.validate({ + form.validate( { rules: { ariaInvalidFirstName: "required" } - }); - ariaInvalidFirstName.val(""); + } ); + ariaInvalidFirstName.val( "" ); ariaInvalidFirstName.valid(); - equal(ariaInvalidFirstName.attr("aria-invalid"), "true"); -}); + equal( ariaInvalidFirstName.attr( "aria-invalid" ), "true" ); +} ); -test("Valid field adds aria-invalid=false", function() { - var ariaInvalidFirstName = $("#ariaInvalidFirstName"), - form = $("#ariaInvalid"); +test( "Valid field adds aria-invalid=false", function() { + var ariaInvalidFirstName = $( "#ariaInvalidFirstName" ), + form = $( "#ariaInvalid" ); - form.validate({ + form.validate( { rules: { ariaInvalidFirstName: "required" } - }); - ariaInvalidFirstName.val("not empty"); + } ); + ariaInvalidFirstName.val( "not empty" ); ariaInvalidFirstName.valid(); - equal(ariaInvalidFirstName.attr("aria-invalid"), "false"); - equal($("#ariaInvalid [aria-invalid=false]").length, 1); -}); + equal( ariaInvalidFirstName.attr( "aria-invalid" ), "false" ); + equal( $( "#ariaInvalid [aria-invalid=false]" ).length, 1 ); +} ); -test("resetForm(): removes all aria-invalid attributes", function() { - var ariaInvalidFirstName = $("#ariaInvalidFirstName"), - form = $("#ariaInvalid"), - validator = form.validate({ +test( "resetForm(): removes all aria-invalid attributes", function() { + var ariaInvalidFirstName = $( "#ariaInvalidFirstName" ), + form = $( "#ariaInvalid" ), + validator = form.validate( { rules: { ariaInvalidFirstName: "required" } - }); + } ); - ariaInvalidFirstName.val("not empty"); + ariaInvalidFirstName.val( "not empty" ); ariaInvalidFirstName.valid(); validator.resetForm(); - equal($("#ariaInvalid [aria-invalid]").length, 0, "resetForm() should remove any aria-invalid attributes"); -}); + equal( $( "#ariaInvalid [aria-invalid]" ).length, 0, "resetForm() should remove any aria-invalid attributes" ); +} ); -test("Static required field adds aria-required", function() { - var ariaRequiredStatic = $("#ariaRequiredStatic"), - form = $("#ariaRequired"); +test( "Static required field adds aria-required", function() { + var ariaRequiredStatic = $( "#ariaRequiredStatic" ), + form = $( "#ariaRequired" ); form.validate(); - equal(ariaRequiredStatic.attr("aria-required"), "true"); -}); + equal( ariaRequiredStatic.attr( "aria-required" ), "true" ); +} ); -test("Data required field adds aria-required", function() { - var ariaRequiredData = $("#ariaRequiredData"), - form = $("#ariaRequired"); +test( "Data required field adds aria-required", function() { + var ariaRequiredData = $( "#ariaRequiredData" ), + form = $( "#ariaRequired" ); form.validate(); - equal(ariaRequiredData.attr("aria-required"), "true"); -}); + equal( ariaRequiredData.attr( "aria-required" ), "true" ); +} ); -test("Class required field adds aria-required", function() { - var ariaRequiredClass = $("#ariaRequiredClass"), - form = $("#ariaRequired"); +test( "Class required field adds aria-required", function() { + var ariaRequiredClass = $( "#ariaRequiredClass" ), + form = $( "#ariaRequired" ); form.validate(); - equal(ariaRequiredClass.attr("aria-required"), "true"); -}); + equal( ariaRequiredClass.attr( "aria-required" ), "true" ); +} ); -test("Dynamically required field adds aria-required after valid()", function() { - var ariaRequiredDynamic = $("#ariaRequiredDynamic"), - form = $("#ariaRequired"); +test( "Dynamically required field adds aria-required after valid()", function() { + var ariaRequiredDynamic = $( "#ariaRequiredDynamic" ), + form = $( "#ariaRequired" ); form.resetForm(); - form.validate({ + form.validate( { rules: { ariaRequiredDynamic: "required" } - }); + } ); ariaRequiredDynamic.valid(); - equal(ariaRequiredDynamic.attr("aria-required"), "true"); -}); + equal( ariaRequiredDynamic.attr( "aria-required" ), "true" ); +} ); diff --git a/test/error-placement.js b/test/error-placement.js index 40d7e09..ba8f7a3 100644 --- a/test/error-placement.js +++ b/test/error-placement.js @@ -52,8 +52,8 @@ test( "error containers, simple", function() { v.prepareForm(); ok( v.valid(), "form is valid" ); - equal( 0, container.find( ".error:not(input)" ).length, "There should be no error labels" ); - equal( "", container.find( "h3" ).html() ); + equal( container.find( ".error:not(input)" ).length, 0, "There should be no error labels" ); + equal( container.find( "h3" ).html(), "" ); v.prepareForm(); v.errorList = [ @@ -78,7 +78,7 @@ test( "error containers, simple", function() { container.find( ".error:not(input)" ).each(function() { ok( $( this ).is( ":visible" ), "Check that each label is visible" ); }); - equal( "There are 2 errors in your form.", container.find( "h3" ).html() ); + equal( container.find( "h3" ).html(), "There are 2 errors in your form." ); v.prepareForm(); ok( v.valid(), "form is valid after a reset" ); @@ -101,9 +101,9 @@ test( "error containers, with labelcontainer I", function() { }); ok( v.valid(), "form is valid" ); - equal( 0, container.find( ".error:not(input)" ).length, "There should be no error labels in the container" ); - 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" ); + equal( container.find( ".error:not(input)" ).length, 0, "There should be no error labels in the container" ); + equal( labelcontainer.find( ".error:not(input)" ).length, 0, "There should be no error labels in the labelcontainer" ); + equal( labelcontainer.find( "li" ).length, 0, "There should be no lis labels in the labelcontainer" ); v.errorList = [ { @@ -123,14 +123,14 @@ test( "error containers, with labelcontainer I", function() { 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" ); - equal( 2, labelcontainer.find( ".error:not(input)" ).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" ); + equal( container.find( ".error:not(input)" ).length, 0, "There should be no error label in the container" ); + equal( labelcontainer.find( ".error:not(input)" ).length, 2, "There should be two error labels in the labelcontainer" ); + equal( labelcontainer.find( "li" ).length, 2, "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" ); labelcontainer.find( ".error:not(input)" ).each(function() { ok( $( this ).is( ":visible" ), "Check that each label is visible1" ); - equal( "li", $( this ).parent()[0].tagName.toLowerCase(), "Check that each label is wrapped in an li" ); + equal( $( this ).parent()[0].tagName.toLowerCase(), "li", "Check that each label is wrapped in an li" ); ok( $( this ).parent( "li" ).is( ":visible" ), "Check that each parent li is visible" ); }); }); @@ -151,13 +151,13 @@ test( "errorcontainer, show/hide only on submit", function() { } }); - equal( "", container.html(), "must be empty" ); - equal( "", 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" ); - equal( 2, labelContainer.find( ".error:not(input)" ).length ); - equal( "There are 2 errors in your form.", container.html() ); + equal( labelContainer.find( ".error:not(input)" ).length, 2 ); + equal( container.html(), "There are 2 errors in your form." ); ok( labelContainer.is( ":visible" ), "must be visible" ); ok( container.is( ":visible" ), "must be visible" ); @@ -168,8 +168,8 @@ test( "errorcontainer, show/hide only on submit", function() { target: $( "#firstname" )[ 0 ] }) ]); - equal( 1, labelContainer.find( ".error:visible" ).length ); - equal( "There are 1 errors in your form.", container.html() ); + equal( labelContainer.find( ".error:visible" ).length, 1 ); + equal( container.html(), "There are 1 errors in your form." ); $( "#lastname" ).val( "abc" ); ok( v.form(), "Form now valid, trigger showErrors but not invalid-form" ); @@ -189,13 +189,13 @@ test( "test label used as error container", function(assert) { }); ok( !field.valid() ); - equal( "Field Label", field.next( "label" ).contents().first().text(), "container label isn't disrupted" ); + equal( field.next( "label" ).contents().first().text(), "Field Label", "container label isn't disrupted" ); assert.hasError(field, "missing"); ok( !field.attr( "aria-describedby" ), "field does not require aria-describedby attribute" ); field.val( "foo" ); ok( field.valid() ); - equal( "Field Label", field.next( "label" ).contents().first().text(), "container label isn't disrupted" ); + equal( field.next( "label" ).contents().first().text(), "Field Label", "container label isn't disrupted" ); ok( !field.attr( "aria-describedby" ), "field does not require aria-describedby attribute" ); assert.noErrorFor(field); }); @@ -210,14 +210,14 @@ test( "test error placed adjacent to descriptive label", function(assert) { }); ok( !field.valid() ); - equal( 1, form.find( "label" ).length ); - equal( "Field Label", form.find( "label" ).text(), "container label isn't disrupted" ); + equal( form.find( "label" ).length, 1 ); + equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" ); assert.hasError( field, "missing" ); field.val( "foo" ); ok( field.valid() ); - equal( 1, form.find( "label" ).length ); - equal( "Field Label", form.find( "label" ).text(), "container label isn't disrupted" ); + equal( form.find( "label" ).length, 1 ); + equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" ); assert.noErrorFor( field ); }); @@ -231,14 +231,14 @@ test( "test descriptive label used alongside error label", function(assert) { }); ok( !field.valid() ); - equal( 1, form.find( "label.title" ).length ); - equal( "Field Label", form.find( "label.title" ).text(), "container label isn't disrupted" ); + equal( form.find( "label.title" ).length, 1 ); + equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" ); assert.hasError( field, "missing" ); field.val( "foo" ); ok( field.valid() ); - equal( 1, form.find( "label.title" ).length ); - equal( "Field Label", form.find( "label.title" ).text(), "container label isn't disrupted" ); + equal( form.find( "label.title" ).length, 1 ); + equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" ); assert.noErrorFor( field ); }); @@ -307,8 +307,8 @@ test( "test existing non-error aria-describedby", function( assert ) { ok( field.valid() ); assert.noErrorFor( field ); - strictEqual( "This is where you enter your data", $("#testForm17text-description").text() ); - strictEqual( "", $("#testForm17text-error").text(), "Error label is empty for valid field" ); + strictEqual( $("#testForm17text-description").text(), "This is where you enter your data" ); + strictEqual( $("#testForm17text-error").text(), "", "Error label is empty for valid field" ); }); test( "test pre-assigned non-error aria-describedby", function( assert ) { @@ -328,8 +328,8 @@ test( "test pre-assigned non-error aria-describedby", function( assert ) { ok( field.valid() ); assert.noErrorFor( field ); - strictEqual( "This is where you enter your data", $("#testForm17text-description").text() ); - strictEqual( "", $("#testForm17text-error").text(), "Error label is empty for valid field" ); + strictEqual( $("#testForm17text-description").text(), "This is where you enter your data" ); + strictEqual( $("#testForm17text-error").text(), "", "Error label is empty for valid field" ); }); test( "test id/name containing brackets", function( assert ) { diff --git a/test/messages.js b/test/messages.js index 10b4fde..8be9133 100644 --- a/test/messages.js +++ b/test/messages.js @@ -1,69 +1,72 @@ -module("messages"); +module( "messages" ); -test("predefined message not overwritten by addMethod(a, b, undefined)", function() { +test( "predefined message not overwritten by addMethod( a, b, undefined )", function() { var message = "my custom message"; $.validator.messages.custom = message; - $.validator.addMethod("custom", function() {}); - deepEqual(message, $.validator.messages.custom); + $.validator.addMethod( "custom", function() {} ); + deepEqual( $.validator.messages.custom, message ); delete $.validator.messages.custom; delete $.validator.methods.custom; -}); +} ); -test("group error messages", function() { - $.validator.addClassRules({ +test( "group error messages", function() { + $.validator.addClassRules( { requiredDateRange: { required: true, date: true, dateRange: true } - }); - $.validator.addMethod("dateRange", function() { - return new Date($("#fromDate").val()) < new Date($("#toDate").val()); - }, "Please specify a correct date range."); - var form = $("#dateRangeForm"); - form.validate({ + } ); + + $.validator.addMethod( "dateRange", function() { + return new Date( $( "#fromDate" ).val() ) < new Date( $( "#toDate" ).val() ); + }, "Please specify a correct date range." ); + + var form = $( "#dateRangeForm" ); + form.validate( { groups: { dateRange: "fromDate toDate" }, - errorPlacement: function(error) { - form.find(".errorContainer").append(error); + errorPlacement: function( error ) { + form.find( ".errorContainer" ).append( error ); } - }); - ok( !form.valid() ); - equal( 1, form.find(".errorContainer *").length ); - equal( "Please enter a valid date.", form.find(".errorContainer .error:not(input)").text() ); + } ); - $("#fromDate").val("12/03/2006"); - $("#toDate").val("12/01/2006"); ok( !form.valid() ); - equal( "Please specify a correct date range.", form.find(".errorContainer .error:not(input)").text() ); + equal( form.find( ".errorContainer *" ).length, 1 ); + equal( form.find( ".errorContainer .error:not(input)" ).text(), "Please enter a valid date." ); - $("#toDate").val("12/04/2006"); + $( "#fromDate" ).val( "12/03/2006" ); + $( "#toDate" ).val( "12/01/2006" ); + ok( !form.valid() ); + equal( form.find( ".errorContainer .error:not(input)" ).text(), "Please specify a correct date range." ); + + $( "#toDate" ).val( "12/04/2006" ); ok( form.valid() ); - ok( form.find(".errorContainer .error:not(input)").is(":hidden") ); -}); + ok( form.find( ".errorContainer .error:not(input)" ).is( ":hidden" ) ); +} ); -test("read messages from metadata", function() { - var form = $("#testForm9"), +test( "read messages from metadata", function() { + var form = $( "#testForm9" ), e, g; form.validate(); - e = $("#testEmail9"); + e = $( "#testEmail9" ); e.valid(); - equal( form.find("#testEmail9").next(".error:not(input)").text(), "required" ); - e.val("bla").valid(); - equal( form.find("#testEmail9").next(".error:not(input)").text(), "email" ); + equal( form.find( "#testEmail9" ).next( ".error:not(input)" ).text(), "required" ); + e.val( "bla" ).valid(); + equal( form.find( "#testEmail9" ).next( ".error:not(input)" ).text(), "email" ); g = $("#testGeneric9"); g.valid(); - equal( form.find("#testGeneric9").next(".error:not(input)").text(), "generic"); - g.val("bla").valid(); - equal( form.find("#testGeneric9").next(".error:not(input)").text(), "email" ); -}); + equal( form.find( "#testGeneric9" ).next( ".error:not(input)" ).text(), "generic"); + g.val( "bla" ).valid(); + 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({ +test( "read messages from metadata, with meta option specified, but no metadata in there", function() { + var form = $( "#testForm1clean" ); + form.validate( { meta: "validate", rules: { firstnamec: "required" } - }); - ok(!form.valid(), "not valid"); -}); + } ); + ok( !form.valid(), "not valid" ); +} ); diff --git a/test/methods.js b/test/methods.js index 86c37d6..8294f9d 100644 --- a/test/methods.js +++ b/test/methods.js @@ -1,37 +1,37 @@ -(function($) { +( function( $ ) { function methodTest( methodName ) { - var v = jQuery("#form").validate(), - method = $.validator.methods[methodName], - element = $("#firstname")[0]; + var v = jQuery( "#form" ).validate(), + method = $.validator.methods[ methodName ], + element = $( "#firstname" )[ 0 ]; - return function(value, param) { + return function( value, param ) { element.value = value; return method.call( v, value, element, param ); }; } -module("methods"); +module( "methods" ); -test("default messages", function() { +test( "default messages", function() { var m = $.validator.methods; - $.each(m, function(key) { - ok( jQuery.validator.messages[key], key + " has a default message." ); - }); -}); + $.each( m, function( key ) { + ok( jQuery.validator.messages[ key ], key + " has a default message." ); + } ); +} ); -test("digit", function() { - var method = methodTest("digits"); +test( "digit", function() { + var method = methodTest( "digits" ); ok( method( "123" ), "Valid digits" ); - ok(!method( "123.000" ), "Invalid digits" ); - ok(!method( "123.000,00" ), "Invalid digits" ); - ok(!method( "123.0.0,0" ), "Invalid digits" ); - ok(!method( "x123" ), "Invalid digits" ); - ok(!method( "100.100,0,0" ), "Invalid digits" ); -}); + ok( !method( "123.000" ), "Invalid digits" ); + ok( !method( "123.000,00" ), "Invalid digits" ); + ok( !method( "123.0.0,0" ), "Invalid digits" ); + ok( !method( "x123" ), "Invalid digits" ); + ok( !method( "100.100,0,0" ), "Invalid digits" ); +} ); -test("url", function() { - var method = methodTest("url"); +test( "url", function() { + var method = methodTest( "url" ); ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" ); ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" ); ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" ); @@ -41,68 +41,68 @@ test("url", function() { ok( method( "http://pro.photography" ), "Valid long TLD" ); ok( method( "//code.jquery.com/jquery-1.11.3.min.js" ), "Valid protocol-relative url" ); ok( method( "//142.42.1.1" ), "Valid protocol-relative IP Address" ); - ok(!method( "htp://code.jquery.com/jquery-1.11.3.min.js" ), "Invalid protocol" ); - ok(!method( "http://192.168.8." ), "Invalid IP Address" ); - ok(!method( "http://bassistance" ), "Invalid url" ); // valid - ok(!method( "http://bassistance." ), "Invalid url" ); // valid - ok(!method( "http://bassistance,de" ), "Invalid url" ); - ok(!method( "http://bassistance;de" ), "Invalid url" ); - ok(!method( "http://.bassistancede" ), "Invalid url" ); - ok(!method( "bassistance.de" ), "Invalid url" ); -}); + ok( !method( "htp://code.jquery.com/jquery-1.11.3.min.js" ), "Invalid protocol" ); + ok( !method( "http://192.168.8." ), "Invalid IP Address" ); + ok( !method( "http://bassistance" ), "Invalid url" ); // valid + ok( !method( "http://bassistance." ), "Invalid url" ); // valid + ok( !method( "http://bassistance,de" ), "Invalid url" ); + ok( !method( "http://bassistance;de" ), "Invalid url" ); + ok( !method( "http://.bassistancede" ), "Invalid url" ); + ok( !method( "bassistance.de" ), "Invalid url" ); +} ); -test("url2 (tld optional)", function() { - var method = methodTest("url2"); +test( "url2 (tld optional)", function() { + var method = methodTest( "url2" ); ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" ); ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" ); ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" ); ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" ); ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" ); ok( method( "http://192.168.8.5" ), "Valid IP Address" ); - ok(!method( "http://192.168.8." ), "Invalid IP Address" ); + ok( !method( "http://192.168.8." ), "Invalid IP Address" ); ok( method( "http://bassistance" ), "Invalid url" ); ok( method( "http://bassistance." ), "Invalid url" ); - ok(!method( "http://bassistance,de" ), "Invalid url" ); - ok(!method( "http://bassistance;de" ), "Invalid url" ); - ok(!method( "http://.bassistancede" ), "Invalid url" ); - ok(!method( "bassistance.de" ), "Invalid url" ); -}); + ok( !method( "http://bassistance,de" ), "Invalid url" ); + ok( !method( "http://bassistance;de" ), "Invalid url" ); + ok( !method( "http://.bassistancede" ), "Invalid url" ); + ok( !method( "bassistance.de" ), "Invalid url" ); +} ); -test("email", function() { - var method = methodTest("email"); +test( "email", function() { + var method = methodTest( "email" ); ok( method( "name@domain.tld" ), "Valid email" ); ok( method( "name@domain.tl" ), "Valid email" ); ok( method( "bart+bart@tokbox.com" ), "Valid email" ); ok( method( "bart+bart@tokbox.travel" ), "Valid email" ); ok( method( "n@d.tld" ), "Valid email" ); - ok( method( "bla.blu@g.mail.com"), "Valid email" ); + ok( method( "bla.blu@g.mail.com" ), "Valid email" ); ok( method( "name@domain" ), "Valid email" ); ok( method( "name.@domain.tld" ), "Valid email" ); ok( method( "name@website.a" ), "Valid email" ); ok( method( "name@pro.photography" ), "Valid email" ); - ok(!method( "ole@føtex.dk"), "Invalid email" ); - ok(!method( "jörn@bassistance.de"), "Invalid email" ); - ok(!method( "name" ), "Invalid email" ); - ok(!method( "test@test-.com" ), "Invalid email" ); - ok(!method( "name@" ), "Invalid email" ); - ok(!method( "name,@domain.tld" ), "Invalid email" ); - ok(!method( "name;@domain.tld" ), "Invalid email" ); - ok(!method( "name;@domain.tld." ), "Invalid email" ); -}); + ok( !method( "ole@føtex.dk" ), "Invalid email" ); + ok( !method( "jörn@bassistance.de" ), "Invalid email" ); + ok( !method( "name" ), "Invalid email" ); + ok( !method( "test@test-.com" ), "Invalid email" ); + ok( !method( "name@" ), "Invalid email" ); + ok( !method( "name,@domain.tld" ), "Invalid email" ); + ok( !method( "name;@domain.tld" ), "Invalid email" ); + ok( !method( "name;@domain.tld." ), "Invalid email" ); +} ); -test("number", function() { - var method = methodTest("number"); +test( "number", function() { + var method = methodTest( "number" ); ok( method( "123" ), "Valid number" ); ok( method( "-123" ), "Valid number" ); ok( method( "123,000" ), "Valid number" ); ok( method( "-123,000" ), "Valid number" ); ok( method( "123,000.00" ), "Valid number" ); ok( method( "-123,000.00" ), "Valid number" ); - ok(!method( "-" ), "Invalid number" ); - ok(!method( "123.000,00" ), "Invalid number" ); - ok(!method( "123.0.0,0" ), "Invalid number" ); - ok(!method( "x123" ), "Invalid number" ); - ok(!method( "100.100,0,0" ), "Invalid number" ); + ok( !method( "-" ), "Invalid number" ); + ok( !method( "123.000,00" ), "Invalid number" ); + ok( !method( "123.0.0,0" ), "Invalid number" ); + ok( !method( "x123" ), "Invalid number" ); + ok( !method( "100.100,0,0" ), "Invalid number" ); ok( method( "" ), "Blank is valid" ); ok( method( "123" ), "Valid decimal" ); @@ -113,11 +113,11 @@ test("number", function() { ok( method( "123,000.00" ), "Valid decimal" ); ok( method( "-123,000.00" ), "Valid decimal" ); ok( method( ".100" ), "Valid decimal" ); - ok(!method( "1230,000.00" ), "Invalid decimal" ); - ok(!method( "123.0.0,0" ), "Invalid decimal" ); - ok(!method( "x123" ), "Invalid decimal" ); - ok(!method( "100.100,0,0" ), "Invalid decimal" ); -}); + ok( !method( "1230,000.00" ), "Invalid decimal" ); + ok( !method( "123.0.0,0" ), "Invalid decimal" ); + ok( !method( "x123" ), "Invalid decimal" ); + ok( !method( "100.100,0,0" ), "Invalid decimal" ); +} ); /* disabled for now, need to figure out how to test localized methods test("numberDE", function() { @@ -147,15 +147,15 @@ test("numberDE", function() { }); */ -test("date", function() { - var method = methodTest("date"); +test( "date", function() { + var method = methodTest( "date" ); ok( method( "06/06/1990" ), "Valid date" ); ok( method( "6/6/06" ), "Valid date" ); - ok(!method( "1990x-06-06" ), "Invalid date" ); -}); + ok( !method( "1990x-06-06" ), "Invalid date" ); +} ); -test("dateISO", function() { - var method = methodTest("dateISO"); +test( "dateISO", function() { + var method = methodTest( "dateISO" ); ok( method( "1990-06-06" ), "Valid date" ); ok( method( "1990-01-01" ), "Valid date" ); ok( method( "1990-01-31" ), "Valid date" ); @@ -164,14 +164,14 @@ test("dateISO", function() { ok( method( "1990/06/06" ), "Valid date" ); ok( method( "1990-6-6" ), "Valid date" ); ok( method( "1990/6/6" ), "Valid date" ); - ok(!method( "1990-106-06" ), "Invalid date" ); - ok(!method( "190-06-06" ), "Invalid date" ); - ok(!method( "1990-00-06" ), "Invalid date" ); - ok(!method( "1990-13-01" ), "Invalid date" ); - ok(!method( "1990-01-00" ), "Invalid date" ); - ok(!method( "1990-01-32" ), "Invalid date" ); - ok(!method( "1990-13-32" ), "Invalid date" ); -}); + ok( !method( "1990-106-06" ), "Invalid date" ); + ok( !method( "190-06-06" ), "Invalid date" ); + ok( !method( "1990-00-06" ), "Invalid date" ); + ok( !method( "1990-13-01" ), "Invalid date" ); + ok( !method( "1990-01-00" ), "Invalid date" ); + ok( !method( "1990-01-32" ), "Invalid date" ); + ok( !method( "1990-13-32" ), "Invalid date" ); +} ); /* disabled for now, need to figure out how to test localized methods test("dateDE", function() { @@ -185,191 +185,191 @@ test("dateDE", function() { }); */ -test("required", function() { - var v = jQuery("#form").validate(), +test( "required", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.required, - e = $("#text1, #text1b, #hidden2, #select1, #select2"); - ok( method.call( v, e[0].value, e[0]), "Valid text input" ); - ok(!method.call( v, e[1].value, e[1]), "Invalid text input" ); - ok(!method.call( v, e[2].value, e[2]), "Invalid text input" ); + e = $( "#text1, #text1b, #hidden2, #select1, #select2" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid text input" ); + ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid text input" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ] ), "Invalid text input" ); - ok(!method.call( v, e[3].value, e[3]), "Invalid select" ); - ok( method.call( v, e[4].value, e[4]), "Valid select" ); + ok( !method.call( v, e[ 3 ].value, e[ 3 ] ), "Invalid select" ); + ok( method.call( v, e[ 4 ].value, e[ 4 ] ), "Valid select" ); - e = $("#area1, #area2, #pw1, #pw2"); - ok( method.call( v, e[0].value, e[0]), "Valid textarea" ); - ok(!method.call( v, e[1].value, e[1]), "Invalid textarea" ); - ok( method.call( v, e[2].value, e[2]), "Valid password input" ); - ok(!method.call( v, e[3].value, e[3]), "Invalid password input" ); + e = $( "#area1, #area2, #pw1, #pw2" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid textarea" ); + ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid textarea" ); + ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid password input" ); + ok( !method.call( v, e[ 3 ].value, e[ 3 ] ), "Invalid password input" ); - e = $("#radio1, #radio2, #radio3"); - ok(!method.call( v, e[0].value, e[0]), "Invalid radio" ); - ok( method.call( v, e[1].value, e[1]), "Valid radio" ); - ok( method.call( v, e[2].value, e[2]), "Valid radio" ); + e = $( "#radio1, #radio2, #radio3" ); + ok( !method.call( v, e[ 0 ].value, e[ 0 ] ), "Invalid radio" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ] ), "Valid radio" ); + ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid radio" ); - e = $("#check1, #check2"); - ok( method.call( v, e[0].value, e[0]), "Valid checkbox" ); - ok(!method.call( v, e[1].value, e[1]), "Invalid checkbox" ); + e = $( "#check1, #check2" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid checkbox" ); + ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid checkbox" ); - e = $("#select1, #select2, #select3, #select4"); - ok(!method.call( v, e[0].value, e[0]), "Invalid select" ); - ok( method.call( v, e[1].value, e[1]), "Valid select" ); - ok( method.call( v, e[2].value, e[2]), "Valid select" ); - ok( method.call( v, e[3].value, e[3]), "Valid select" ); -}); + e = $( "#select1, #select2, #select3, #select4" ); + ok( !method.call( v, e[ 0 ].value, e[ 0 ] ), "Invalid select" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ] ), "Valid select" ); + ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid select" ); + ok( method.call( v, e[ 3 ].value, e[ 3 ] ), "Valid select" ); +} ); -test("required with dependencies", function() { - var v = jQuery("#form").validate(), +test( "required with dependencies", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.required, - e = $("#hidden2, #select1, #area2, #radio1, #check2"); - ok( method.call( v, e[0].value, e[0], "asffsaa" ), "Valid text input due to dependency not met" ); - ok(!method.call( v, e[0].value, e[0], "input" ), "Invalid text input" ); - ok( method.call( v, e[0].value, e[0], function() { return false; }), "Valid text input due to dependency not met" ); - ok(!method.call( v, e[0].value, e[0], function() { return true; }), "Invalid text input" ); - ok( method.call( v, e[1].value, e[1], "asfsfa" ), "Valid select due to dependency not met" ); - ok(!method.call( v, e[1].value, e[1], "input" ), "Invalid select" ); - ok( method.call( v, e[2].value, e[2], "asfsafsfa" ), "Valid textarea due to dependency not met" ); - ok(!method.call( v, e[2].value, e[2], "input" ), "Invalid textarea" ); - ok( method.call( v, e[3].value, e[3], "asfsafsfa" ), "Valid radio due to dependency not met" ); - ok(!method.call( v, e[3].value, e[3], "input" ), "Invalid radio" ); - ok( method.call( v, e[4].value, e[4], "asfsafsfa" ), "Valid checkbox due to dependency not met" ); - ok(!method.call( v, e[4].value, e[4], "input" ), "Invalid checkbox" ); -}); + e = $( "#hidden2, #select1, #area2, #radio1, #check2" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ], "asffsaa" ), "Valid text input due to dependency not met" ); + ok( !method.call( v, e[ 0 ].value, e[ 0 ], "input" ), "Invalid text input" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ], function() { return false; } ), "Valid text input due to dependency not met" ); + ok( !method.call( v, e[ 0 ].value, e[ 0 ], function() { return true; } ), "Invalid text input" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], "asfsfa" ), "Valid select due to dependency not met" ); + ok( !method.call( v, e[ 1 ].value, e[ 1 ], "input" ), "Invalid select" ); + ok( method.call( v, e[ 2 ].value, e[ 2 ], "asfsafsfa" ), "Valid textarea due to dependency not met" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ], "input" ), "Invalid textarea" ); + ok( method.call( v, e[ 3 ].value, e[ 3 ], "asfsafsfa" ), "Valid radio due to dependency not met" ); + ok( !method.call( v, e[ 3 ].value, e[ 3 ], "input" ), "Invalid radio" ); + ok( method.call( v, e[ 4 ].value, e[ 4 ], "asfsafsfa" ), "Valid checkbox due to dependency not met" ); + ok( !method.call( v, e[ 4 ].value, e[ 4 ], "input" ), "Invalid checkbox" ); +} ); -test("minlength", function() { - var v = jQuery("#form").validate(), +test( "minlength", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.minlength, param = 2, - e = $("#text1, #text1c, #text2, #text3"); - ok( method.call( v, e[0].value, e[0], param), "Valid text input" ); - ok( method.call( v, e[1].value, e[1], param), "Valid text input" ); - ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" ); - ok( method.call( v, e[3].value, e[3], param), "Valid text input" ); + e = $( "#text1, #text1c, #text2, #text3" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" ); + ok( method.call( v, e[ 3 ].value, e[ 3 ], param ), "Valid text input" ); - e = $("#check1, #check2, #check3"); - ok(!method.call( v, e[0].value, e[0], param), "Valid checkbox" ); - ok( method.call( v, e[1].value, e[1], param), "Valid checkbox" ); - ok( method.call( v, e[2].value, e[2], param), "Invalid checkbox" ); + e = $( "#check1, #check2, #check3" ); + ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid checkbox" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid checkbox" ); + ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid checkbox" ); - e = $("#select1, #select2, #select3, #select4, #select5"); - ok(method.call( v, e[0].value, e[0], param), "Valid select " + e[0].id ); - ok(!method.call( v, e[1].value, e[1], param), "Invalid select " + e[1].id ); - ok( method.call( v, e[2].value, e[2], param), "Valid select " + e[2].id ); - ok( method.call( v, e[3].value, e[3], param), "Valid select " + e[3].id ); - ok( method.call( v, e[4].value, e[4], param), "Valid select " + e[4].id ); -}); + e = $( "#select1, #select2, #select3, #select4, #select5" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid select " + e[ 0 ].id ); + ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid select " + e[ 1 ].id ); + ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid select " + e[ 2 ].id ); + ok( method.call( v, e[ 3 ].value, e[ 3 ], param ), "Valid select " + e[ 3 ].id ); + ok( method.call( v, e[ 4 ].value, e[ 4 ], param ), "Valid select " + e[ 4 ].id ); +} ); -test("maxlength", function() { - var v = jQuery("#form").validate(), +test( "maxlength", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.maxlength, param = 4, - e = $("#text1, #text2, #text3"); + e = $( "#text1, #text2, #text3" ); - ok( method.call( v, e[0].value, e[0], param), "Valid text input" ); - ok( method.call( v, e[1].value, e[1], param), "Valid text input" ); - ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" ); - e = $("#check1, #check2, #check3"); - ok( method.call( v, e[0].value, e[0], param), "Valid checkbox" ); - ok( method.call( v, e[1].value, e[1], param), "Invalid checkbox" ); - ok(!method.call( v, e[2].value, e[2], param), "Invalid checkbox" ); + e = $( "#check1, #check2, #check3" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid checkbox" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid checkbox" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid checkbox" ); - e = $("#select1, #select2, #select3, #select4"); - ok( method.call( v, e[0].value, e[0], param), "Valid select" ); - ok( method.call( v, e[1].value, e[1], param), "Valid select" ); - ok( method.call( v, e[2].value, e[2], param), "Valid select" ); - ok(!method.call( v, e[3].value, e[3], param), "Invalid select" ); -}); + e = $( "#select1, #select2, #select3, #select4" ); + ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid select" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid select" ); + ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid select" ); + ok( !method.call( v, e[ 3 ].value, e[ 3 ], param ), "Invalid select" ); +} ); -test("rangelength", function() { - var v = jQuery("#form").validate(), +test( "rangelength", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.rangelength, param = [ 2, 4 ], - e = $("#text1, #text2, #text3"); + e = $( "#text1, #text2, #text3" ); - ok( method.call( v, e[0].value, e[0], param), "Valid text input" ); - ok(!method.call( v, e[1].value, e[1], param), "Invalid text input" ); - ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" ); -}); + ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" ); + ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid text input" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" ); +} ); -test("min", function() { - var v = jQuery("#form").validate(), +test( "min", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.min, param = 8, - e = $("#value1, #value2, #value3"); + e = $( "#value1, #value2, #value3" ); - ok(!method.call( v, e[0].value, e[0], param), "Invalid text input" ); - ok( method.call( v, e[1].value, e[1], param), "Valid text input" ); - ok( method.call( v, e[2].value, e[2], param), "Valid text input" ); -}); + ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Invalid text input" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" ); + ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid text input" ); +} ); -test("max", function() { - var v = jQuery("#form").validate(), +test( "max", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.max, param = 12, - e = $("#value1, #value2, #value3"); + e = $( "#value1, #value2, #value3" ); - ok( method.call( v, e[0].value, e[0], param), "Valid text input" ); - ok( method.call( v, e[1].value, e[1], param), "Valid text input" ); - ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" ); -}); + ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" ); +} ); -test("range", function() { - var v = jQuery("#form").validate(), +test( "range", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.range, param = [ 4, 12 ], - e = $("#value1, #value2, #value3"); + e = $( "#value1, #value2, #value3" ); - ok(!method.call( v, e[0].value, e[0], param), "Invalid text input" ); - ok( method.call( v, e[1].value, e[1], param), "Valid text input" ); - ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" ); -}); + ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Invalid text input" ); + ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" ); + ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" ); +} ); -test("equalTo", function() { - var v = jQuery("#form").validate(), +test( "equalTo", function() { + var v = jQuery( "#form" ).validate(), method = $.validator.methods.equalTo, - e = $("#text1, #text2"); + e = $( "#text1, #text2" ); - ok( method.call( v, "Test", e[0], "#text1" ), "Text input" ); - ok( method.call( v, "T", e[1], "#text2" ), "Another one" ); -}); + ok( method.call( v, "Test", e[ 0 ], "#text1" ), "Text input" ); + ok( method.call( v, "T", e[ 1 ], "#text2" ), "Another one" ); +} ); -test("creditcard", function() { - var method = methodTest("creditcard"); +test( "creditcard", function() { + var method = methodTest( "creditcard" ); ok( method( "4111-1111-1111-1111" ), "Valid creditcard number" ); ok( method( "4111 1111 1111 1111" ), "Valid creditcard number" ); - ok(!method( "41111" ), "Invalid creditcard number" ); - ok(!method( "asdf" ), "Invalid creditcard number" ); -}); + ok( !method( "41111" ), "Invalid creditcard number" ); + ok( !method( "asdf" ), "Invalid creditcard number" ); +} ); -test("extension", function() { - var method = methodTest("extension"), +test( "extension", function() { + var method = methodTest( "extension" ), v; ok( method( "picture.gif" ), "Valid default accept type" ); ok( method( "picture.jpg" ), "Valid default accept type" ); ok( method( "picture.jpeg" ), "Valid default accept type" ); ok( method( "picture.png" ), "Valid default accept type" ); - ok(!method( "picture.pgn" ), "Invalid default accept type" ); + ok( !method( "picture.pgn" ), "Invalid default accept type" ); - v = jQuery("#form").validate(); - method = function(value, param) { - return $.validator.methods.extension.call(v, value, $("#text1")[0], param); + v = jQuery( "#form" ).validate(); + method = function( value, param ) { + return $.validator.methods.extension.call( v, value, $( "#text1" )[ 0 ], param ); }; ok( method( "picture.doc", "doc" ), "Valid custom accept type" ); ok( method( "picture.pdf", "doc|pdf" ), "Valid custom accept type" ); ok( method( "picture.pdf", "pdf|doc" ), "Valid custom accept type" ); - ok(!method( "picture.pdf", "doc" ), "Invalid custom accept type" ); - ok(!method( "picture.doc", "pdf" ), "Invalid custom accept type" ); + ok( !method( "picture.pdf", "doc" ), "Invalid custom accept type" ); + ok( !method( "picture.doc", "pdf" ), "Invalid custom accept type" ); ok( method( "picture.pdf", "doc,pdf" ), "Valid custom accept type, comma separated" ); ok( method( "picture.pdf", "pdf,doc" ), "Valid custom accept type, comma separated" ); - ok(!method( "picture.pdf", "gop,top" ), "Invalid custom accept type, comma separated" ); -}); + ok( !method( "picture.pdf", "gop,top" ), "Invalid custom accept type, comma separated" ); +} ); -asyncTest("remote", function() { - expect(7); - var e = $("#username"), - v = $("#userForm").validate({ +asyncTest( "remote", function() { + expect( 7 ); + var e = $( "#username" ), + v = $( "#userForm" ).validate( { rules: { username: { required: true, @@ -379,45 +379,45 @@ asyncTest("remote", function() { messages: { username: { required: "Please", - remote: jQuery.validator.format("{0} in use") + remote: jQuery.validator.format( "{0} in use" ) } }, submitHandler: function() { - ok( false, "submitHandler may never be called when validating only elements"); + ok( false, "submitHandler may never be called when validating only elements" ); } - }); + } ); - $(document).ajaxStop(function() { - $(document).unbind("ajaxStop"); - equal( 1, v.size(), "There must be one error" ); - equal( "Peter in use", v.errorList[0].message ); + $( document ).ajaxStop( function() { + $( document ).unbind( "ajaxStop" ); + equal( v.size(), 1, "There must be one error" ); + equal( v.errorList[ 0 ].message, "Peter in use" ); - $(document).ajaxStop(function() { - $(document).unbind("ajaxStop"); - equal( 1, v.size(), "There must be one error" ); - equal( "Peter2 in use", v.errorList[0].message ); + $( document ).ajaxStop( function() { + $( document ).unbind( "ajaxStop" ); + equal( v.size(), 1, "There must be one error" ); + equal( v.errorList[ 0 ].message, "Peter2 in use" ); start(); - }); - e.val("Peter2"); - strictEqual( v.element(e), true, "new value, new request; dependency-mismatch considered as valid though" ); - }); - strictEqual( v.element(e), false, "invalid element, nothing entered yet" ); - e.val("Peter"); - strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" ); -}); + } ); + e.val( "Peter2" ); + strictEqual( v.element( e ), true, "new value, new request; dependency-mismatch considered as valid though" ); + } ); + strictEqual( v.element( e ), false, "invalid element, nothing entered yet" ); + e.val( "Peter" ); + strictEqual( v.element( e ), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" ); +} ); -asyncTest("remote, customized ajax options", function() { - expect(2); - $("#userForm").validate({ +asyncTest( "remote, customized ajax options", function() { + expect( 2 ); + $( "#userForm" ).validate( { rules: { username: { required: true, remote: { url: "users.php", type: "POST", - beforeSend: function(request, settings) { - deepEqual(settings.type, "POST"); - deepEqual(settings.data, "username=asdf&email=email.com"); + beforeSend: function( request, settings ) { + deepEqual( settings.type, "POST" ); + deepEqual( settings.data, "username=asdf&email=email.com" ); }, data: { email: function() { @@ -430,15 +430,15 @@ asyncTest("remote, customized ajax options", function() { } } } - }); - $("#username").val("asdf"); - $("#userForm").valid(); -}); + } ); + $( "#username" ).val( "asdf" ); + $( "#userForm" ).valid(); +} ); -asyncTest("remote extensions", function() { - expect(5); - var e = $("#username"), - v = $("#userForm").validate({ +asyncTest( "remote extensions", function() { + expect( 5 ); + var e = $( "#username" ), + v = $( "#userForm" ).validate( { rules: { username: { required: true, @@ -451,34 +451,34 @@ asyncTest("remote extensions", function() { } }, submitHandler: function() { - ok( false, "submitHandler may never be called when validating only elements"); + ok( false, "submitHandler may never be called when validating only elements" ); } - }); + } ); - $(document).ajaxStop(function() { - $(document).unbind("ajaxStop"); + $( document ).ajaxStop( function() { + $( document ).unbind( "ajaxStop" ); if ( v.size() !== 0 ) { ok( "There must be one error" ); - equal( v.errorList[0].message, "asdf is already taken, please try something else" ); - v.element(e); - equal( v.errorList[0].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" ); + equal( v.errorList[ 0 ].message, "asdf is already taken, please try something else" ); + v.element( e ); + equal( v.errorList[ 0 ].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" ); } start(); - }); - strictEqual( v.element(e), false, "invalid element, nothing entered yet" ); - e.val("asdf"); - strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" ); -}); + } ); + strictEqual( v.element( e ), false, "invalid element, nothing entered yet" ); + e.val( "asdf" ); + strictEqual( v.element( e ), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" ); +} ); -test("remote, data previous querystring", function( assert ) { - expect(4); +test( "remote, data previous querystring", function( assert ) { + expect( 4 ); var succeeded = 0, - $f = $("#firstnamec"), - $l = $("#lastnamec"), + $f = $( "#firstnamec" ), + $l = $( "#lastnamec" ), done1 = assert.async(), done2 = assert.async(), done3 = assert.async(), - v = $("#testForm1clean").validate({ + v = $( "#testForm1clean" ).validate( { rules: { lastname: { remote: { @@ -495,44 +495,44 @@ test("remote, data previous querystring", function( assert ) { } } } - }); - $f.val("first-name"); - $l.val("last-name"); + } ); + $f.val( "first-name" ); + $l.val( "last-name" ); strictEqual( succeeded, 0, "no valid call means no successful validation" ); v.element( $l ); - setTimeout(function() { + setTimeout( function() { strictEqual( succeeded, 1, "first valid check should submit given first name" ); done1(); v.element( $l ); - setTimeout(function() { + setTimeout( function() { strictEqual( succeeded, 1, "second valid check should not resubmit given same first name" ); done2(); - $f.val("different-first-name"); + $f.val( "different-first-name" ); v.element( $l ); - setTimeout(function() { + setTimeout( function() { strictEqual( succeeded, 2, "third valid check should resubmit given different first name" ); done3(); - }); - }); - }); -}); + } ); + } ); + } ); +} ); -module("additional methods"); +module( "additional methods" ); -test("phone (us)", function() { - var method = methodTest("phoneUS"); +test( "phone (us)", function() { + var method = methodTest( "phoneUS" ); ok( method( "1(212)-999-2345" ), "Valid US phone number" ); ok( method( "212 999 2344" ), "Valid US phone number" ); ok( method( "212-999-0983" ), "Valid US phone number" ); - ok(!method( "111-123-5434" ), "Invalid US phone number. Area Code cannot start with 1" ); - ok(!method( "212 123 4567" ), "Invalid US phone number. NXX cannot start with 1" ); - ok(!method( "234-911-5678" ), "Invalid US phone number, because the exchange code cannot be in the form N11" ); - ok(!method( "911-333-5678" ), "Invalid US phone number, because the area code cannot be in the form N11" ); - ok(method( "234-912-5678" ), "Valid US phone number" ); -}); + ok( !method( "111-123-5434" ), "Invalid US phone number. Area Code cannot start with 1" ); + ok( !method( "212 123 4567" ), "Invalid US phone number. NXX cannot start with 1" ); + ok( !method( "234-911-5678" ), "Invalid US phone number, because the exchange code cannot be in the form N11" ); + ok( !method( "911-333-5678" ), "Invalid US phone number, because the area code cannot be in the form N11" ); + ok( method( "234-912-5678" ), "Valid US phone number" ); +} ); -test("phoneUK", function() { - var method = methodTest("phoneUK"); +test( "phoneUK", function() { + var method = methodTest( "phoneUK" ); ok( method( "0117 333 5555" ), "Valid UK Phone Number" ); ok( method( "0121 555 5555" ), "Valid UK Phone Number" ); ok( method( "01633 555555" ), "Valid UK Phone Number" ); @@ -559,12 +559,12 @@ test("phoneUK", function() { ok( method( "+44 7122 555 555" ), "Valid UK Phone Number" ); ok( method( "+44 7222 555 555" ), "Valid UK Phone Number" ); ok( method( "+44 7322 555 555" ), "Valid UK Phone Number" ); - ok(!method( "7222 555555" ), "Invalid UK Phone Number" ); - ok(!method( "+44 07222 555555" ), "Invalid UK Phone Number" ); -}); + ok( !method( "7222 555555" ), "Invalid UK Phone Number" ); + ok( !method( "+44 07222 555555" ), "Invalid UK Phone Number" ); +} ); -test("mobileUK", function() { - var method = methodTest("mobileUK"); +test( "mobileUK", function() { + var method = methodTest( "mobileUK" ); ok( method( "07134234323" ), "Valid UK Mobile Number" ); ok( method( "07334234323" ), "Valid UK Mobile Number" ); ok( method( "07624234323" ), "Valid UK Mobile Number" ); @@ -573,28 +573,28 @@ test("mobileUK", function() { ok( method( "+447334234323" ), "Valid UK Mobile Number" ); ok( method( "+447624234323" ), "Valid UK Mobile Number" ); ok( method( "+447734234323" ), "Valid UK Mobile Number" ); - ok(!method( "07034234323" ), "Invalid UK Mobile Number" ); - ok(!method( "0753423432" ), "Invalid UK Mobile Number" ); - ok(!method( "07604234323" ), "Invalid UK Mobile Number" ); - ok(!method( "077342343234" ), "Invalid UK Mobile Number" ); - ok(!method( "044342343234" ), "Invalid UK Mobile Number" ); - ok(!method( "+44753423432" ), "Invalid UK Mobile Number" ); - ok(!method( "+447604234323" ), "Invalid UK Mobile Number" ); - ok(!method( "+4477342343234" ), "Invalid UK Mobile Number" ); - ok(!method( "+4444342343234" ), "Invalid UK Mobile Number" ); -}); + ok( !method( "07034234323" ), "Invalid UK Mobile Number" ); + ok( !method( "0753423432" ), "Invalid UK Mobile Number" ); + ok( !method( "07604234323" ), "Invalid UK Mobile Number" ); + ok( !method( "077342343234" ), "Invalid UK Mobile Number" ); + ok( !method( "044342343234" ), "Invalid UK Mobile Number" ); + ok( !method( "+44753423432" ), "Invalid UK Mobile Number" ); + ok( !method( "+447604234323" ), "Invalid UK Mobile Number" ); + ok( !method( "+4477342343234" ), "Invalid UK Mobile Number" ); + ok( !method( "+4444342343234" ), "Invalid UK Mobile Number" ); +} ); -test("dateITA", function() { - var method = methodTest("dateITA"); +test( "dateITA", function() { + var method = methodTest( "dateITA" ); ok( method( "01/01/1900" ), "Valid date ITA" ); ok( method( "17/10/2010" ), "Valid date ITA" ); - ok(!method( "01/13/1990" ), "Invalid date ITA" ); - ok(!method( "01.01.1900" ), "Invalid date ITA" ); - ok(!method( "01/01/199" ), "Invalid date ITA" ); -}); + ok( !method( "01/13/1990" ), "Invalid date ITA" ); + ok( !method( "01.01.1900" ), "Invalid date ITA" ); + ok( !method( "01/01/199" ), "Invalid date ITA" ); +} ); -test("dateFA", function() { - var method = methodTest("dateFA"); +test( "dateFA", function() { + var method = methodTest( "dateFA" ); ok( method( "1342/12/29" ), "Valid date FA" ); ok( method( "1342/12/30" ), "Valid date FA" ); @@ -607,94 +607,94 @@ test("dateFA", function() { ok( method( "1020/03/03" ), "Valid date FA" ); ok( method( "1001/7/30" ), "Valid date FA" ); - ok(!method( "1000/1/32" ), "Invalid date FA" ); - ok(!method( "1323/12/31" ), "Invalid date FA" ); - ok(!method( "1361/0/11" ), "Invalid date FA" ); - ok(!method( "63/4/4" ), "Invalid date FA" ); - ok(!method( "15/6/1361" ), "Invalid date FA" ); -}); + ok( !method( "1000/1/32" ), "Invalid date FA" ); + ok( !method( "1323/12/31" ), "Invalid date FA" ); + ok( !method( "1361/0/11" ), "Invalid date FA" ); + ok( !method( "63/4/4" ), "Invalid date FA" ); + ok( !method( "15/6/1361" ), "Invalid date FA" ); +} ); -test("iban", function() { - var method = methodTest("iban"); - ok( method( "NL20INGB0001234567"), "Valid IBAN"); - ok( method( "DE68 2105 0170 0012 3456 78"), "Valid IBAN"); - ok( method( "NL20 INGB0001234567"), "Valid IBAN: invalid spacing"); - ok( method( "NL20 INGB 00 0123 4567"), "Valid IBAN: invalid spacing"); - ok( method( "XX40INGB000123456712341234"), "Valid (more or less) IBAN: unknown country, but checksum OK"); +test( "iban", function() { + var method = methodTest( "iban" ); + ok( method( "NL20INGB0001234567" ), "Valid IBAN" ); + ok( method( "DE68 2105 0170 0012 3456 78" ), "Valid IBAN" ); + ok( method( "NL20 INGB0001234567" ), "Valid IBAN: invalid spacing" ); + ok( method( "NL20 INGB 00 0123 4567" ), "Valid IBAN: invalid spacing" ); + ok( method( "XX40INGB000123456712341234" ), "Valid (more or less) IBAN: unknown country, but checksum OK" ); - ok(!method( "NL20INGB000123456"), "Invalid IBAN: too short"); - ok(!method( "NL20INGB00012345678"), "Invalid IBAN: too long"); - ok(!method( "NL20INGB0001234566"), "Invalid IBAN: checksum incorrect"); - ok(!method( "DE68 2105 0170 0012 3456 7"), "Invalid IBAN: too short"); - ok(!method( "DE68 2105 0170 0012 3456 789"), "Invalid IBAN: too long"); - ok(!method( "DE68 2105 0170 0012 3456 79"), "Invalid IBAN: checksum incorrect"); + ok( !method( "NL20INGB000123456" ), "Invalid IBAN: too short" ); + ok( !method( "NL20INGB00012345678" ), "Invalid IBAN: too long" ); + ok( !method( "NL20INGB0001234566" ), "Invalid IBAN: checksum incorrect" ); + ok( !method( "DE68 2105 0170 0012 3456 7" ), "Invalid IBAN: too short" ); + ok( !method( "DE68 2105 0170 0012 3456 789" ), "Invalid IBAN: too long" ); + ok( !method( "DE68 2105 0170 0012 3456 79" ), "Invalid IBAN: checksum incorrect" ); - ok(!method( "NL54INGB00012345671234"), "Invalid IBAN too long, BUT CORRECT CHECKSUM"); - ok(!method( "XX00INGB000123456712341234"), "Invalid IBAN: unknown country and checksum incorrect"); + ok( !method( "NL54INGB00012345671234" ), "Invalid IBAN too long, BUT CORRECT CHECKSUM" ); + ok( !method( "XX00INGB000123456712341234" ), "Invalid IBAN: unknown country and checksum incorrect" ); // sample IBANs for different countries - ok( method( "AL47 2121 1009 0000 0002 3569 8741"), "Valid IBAN - AL"); - ok( method( "AD12 0001 2030 2003 5910 0100"), "Valid IBAN - AD"); - ok( method( "AT61 1904 3002 3457 3201"), "Valid IBAN - AT"); - ok( method( "AZ21 NABZ 0000 0000 1370 1000 1944"), "Valid IBAN - AZ"); - ok( method( "BH67 BMAG 0000 1299 1234 56"), "Valid IBAN - BH"); - ok( method( "BE62 5100 0754 7061"), "Valid IBAN - BE"); - ok( method( "BA39 1290 0794 0102 8494"), "Valid IBAN - BA"); - ok( method( "BG80 BNBG 9661 1020 3456 78"), "Valid IBAN - BG"); - ok( method( "HR12 1001 0051 8630 0016 0"), "Valid IBAN - HR"); - ok( method( "CH93 0076 2011 6238 5295 7"), "Valid IBAN - CH"); - ok( method( "CY17 0020 0128 0000 0012 0052 7600"), "Valid IBAN - CY"); - ok( method( "CZ65 0800 0000 1920 0014 5399"), "Valid IBAN - CZ"); - ok( method( "DK50 0040 0440 1162 43"), "Valid IBAN - DK"); - ok( method( "EE38 2200 2210 2014 5685"), "Valid IBAN - EE"); - ok( method( "FO97 5432 0388 8999 44"), "Valid IBAN - FO"); - ok( method( "FI21 1234 5600 0007 85"), "Valid IBAN - FI"); - ok( method( "FR14 2004 1010 0505 0001 3M02 606"), "Valid IBAN - FR"); - ok( method( "GE29 NB00 0000 0101 9049 17"), "Valid IBAN - GE"); - ok( method( "DE89 3704 0044 0532 0130 00"), "Valid IBAN - DE"); - ok( method( "GI75 NWBK 0000 0000 7099 453"), "Valid IBAN - GI"); - ok( method( "GR16 0110 1250 0000 0001 2300 695"), "Valid IBAN - GR"); - ok( method( "GL56 0444 9876 5432 10"), "Valid IBAN - GL"); - ok( method( "HU42 1177 3016 1111 1018 0000 0000"), "Valid IBAN - HU"); - ok( method( "IS14 0159 2600 7654 5510 7303 39"), "Valid IBAN - IS"); - ok( method( "IE29 AIBK 9311 5212 3456 78"), "Valid IBAN - IE"); - ok( method( "IL62 0108 0000 0009 9999 999"), "Valid IBAN - IL"); - ok( method( "IT40 S054 2811 1010 0000 0123 456"), "Valid IBAN - IT"); - ok( method( "LV80 BANK 0000 4351 9500 1"), "Valid IBAN - LV"); - ok( method( "LB62 0999 0000 0001 0019 0122 9114"), "Valid IBAN - LB"); - ok( method( "LI21 0881 0000 2324 013A A"), "Valid IBAN - LI"); - ok( method( "LT12 1000 0111 0100 1000"), "Valid IBAN - LT"); - ok( method( "LU28 0019 4006 4475 0000"), "Valid IBAN - LU"); - ok( method( "MK07 2501 2000 0058 984"), "Valid IBAN - MK"); - ok( method( "MT84 MALT 0110 0001 2345 MTLC AST0 01S"), "Valid IBAN - MT"); - ok( method( "MU17 BOMM 0101 1010 3030 0200 000M UR"), "Valid IBAN - MU"); - ok( method( "MD24 AG00 0225 1000 1310 4168"), "Valid IBAN - MD"); - ok( method( "MC93 2005 2222 1001 1223 3M44 555"), "Valid IBAN - MC"); - ok( method( "ME25 5050 0001 2345 6789 51"), "Valid IBAN - ME"); - ok( method( "NL39 RABO 0300 0652 64"), "Valid IBAN - NL"); - ok( method( "NO93 8601 1117 947"), "Valid IBAN - NO"); - ok( method( "PK36 SCBL 0000 0011 2345 6702"), "Valid IBAN - PK"); - ok( method( "PL60 1020 1026 0000 0422 7020 1111"), "Valid IBAN - PL"); - ok( method( "PT50 0002 0123 1234 5678 9015 4"), "Valid IBAN - PT"); - ok( method( "RO49 AAAA 1B31 0075 9384 0000"), "Valid IBAN - RO"); - ok( method( "SM86 U032 2509 8000 0000 0270 100"), "Valid IBAN - SM"); - ok( method( "SA03 8000 0000 6080 1016 7519"), "Valid IBAN - SA"); - ok( method( "RS35 2600 0560 1001 6113 79"), "Valid IBAN - RS"); - ok( method( "SK31 1200 0000 1987 4263 7541"), "Valid IBAN - SK"); - ok( method( "SI56 1910 0000 0123 438"), "Valid IBAN - SI"); - ok( method( "ES80 2310 0001 1800 0001 2345"), "Valid IBAN - ES"); - ok( method( "SE35 5000 0000 0549 1000 0003"), "Valid IBAN - SE"); - ok( method( "CH93 0076 2011 6238 5295 7"), "Valid IBAN - CH"); - ok( method( "TN59 1000 6035 1835 9847 8831"), "Valid IBAN - TN"); - ok( method( "TR33 0006 1005 1978 6457 8413 26"), "Valid IBAN - TR"); - ok( method( "AE07 0331 2345 6789 0123 456"), "Valid IBAN - AE"); - ok( method( "GB29 NWBK 6016 1331 9268 19"), "Valid IBAN - GB"); -}); + ok( method( "AL47 2121 1009 0000 0002 3569 8741" ), "Valid IBAN - AL" ); + ok( method( "AD12 0001 2030 2003 5910 0100" ), "Valid IBAN - AD" ); + ok( method( "AT61 1904 3002 3457 3201" ), "Valid IBAN - AT" ); + ok( method( "AZ21 NABZ 0000 0000 1370 1000 1944" ), "Valid IBAN - AZ" ); + ok( method( "BH67 BMAG 0000 1299 1234 56" ), "Valid IBAN - BH" ); + ok( method( "BE62 5100 0754 7061" ), "Valid IBAN - BE" ); + ok( method( "BA39 1290 0794 0102 8494" ), "Valid IBAN - BA" ); + ok( method( "BG80 BNBG 9661 1020 3456 78" ), "Valid IBAN - BG" ); + ok( method( "HR12 1001 0051 8630 0016 0" ), "Valid IBAN - HR" ); + ok( method( "CH93 0076 2011 6238 5295 7" ), "Valid IBAN - CH" ); + ok( method( "CY17 0020 0128 0000 0012 0052 7600" ), "Valid IBAN - CY" ); + ok( method( "CZ65 0800 0000 1920 0014 5399" ), "Valid IBAN - CZ" ); + ok( method( "DK50 0040 0440 1162 43" ), "Valid IBAN - DK" ); + ok( method( "EE38 2200 2210 2014 5685" ), "Valid IBAN - EE" ); + ok( method( "FO97 5432 0388 8999 44" ), "Valid IBAN - FO" ); + ok( method( "FI21 1234 5600 0007 85" ), "Valid IBAN - FI" ); + ok( method( "FR14 2004 1010 0505 0001 3M02 606" ), "Valid IBAN - FR" ); + ok( method( "GE29 NB00 0000 0101 9049 17" ), "Valid IBAN - GE" ); + ok( method( "DE89 3704 0044 0532 0130 00" ), "Valid IBAN - DE" ); + ok( method( "GI75 NWBK 0000 0000 7099 453" ), "Valid IBAN - GI" ); + ok( method( "GR16 0110 1250 0000 0001 2300 695" ), "Valid IBAN - GR" ); + ok( method( "GL56 0444 9876 5432 10" ), "Valid IBAN - GL" ); + ok( method( "HU42 1177 3016 1111 1018 0000 0000" ), "Valid IBAN - HU" ); + ok( method( "IS14 0159 2600 7654 5510 7303 39" ), "Valid IBAN - IS" ); + ok( method( "IE29 AIBK 9311 5212 3456 78" ), "Valid IBAN - IE" ); + ok( method( "IL62 0108 0000 0009 9999 999" ), "Valid IBAN - IL" ); + ok( method( "IT40 S054 2811 1010 0000 0123 456" ), "Valid IBAN - IT" ); + ok( method( "LV80 BANK 0000 4351 9500 1" ), "Valid IBAN - LV" ); + ok( method( "LB62 0999 0000 0001 0019 0122 9114" ), "Valid IBAN - LB" ); + ok( method( "LI21 0881 0000 2324 013A A" ), "Valid IBAN - LI" ); + ok( method( "LT12 1000 0111 0100 1000" ), "Valid IBAN - LT" ); + ok( method( "LU28 0019 4006 4475 0000" ), "Valid IBAN - LU" ); + ok( method( "MK07 2501 2000 0058 984" ), "Valid IBAN - MK" ); + ok( method( "MT84 MALT 0110 0001 2345 MTLC AST0 01S" ), "Valid IBAN - MT" ); + ok( method( "MU17 BOMM 0101 1010 3030 0200 000M UR" ), "Valid IBAN - MU" ); + ok( method( "MD24 AG00 0225 1000 1310 4168" ), "Valid IBAN - MD" ); + ok( method( "MC93 2005 2222 1001 1223 3M44 555" ), "Valid IBAN - MC" ); + ok( method( "ME25 5050 0001 2345 6789 51" ), "Valid IBAN - ME" ); + ok( method( "NL39 RABO 0300 0652 64" ), "Valid IBAN - NL" ); + ok( method( "NO93 8601 1117 947" ), "Valid IBAN - NO" ); + ok( method( "PK36 SCBL 0000 0011 2345 6702" ), "Valid IBAN - PK" ); + ok( method( "PL60 1020 1026 0000 0422 7020 1111" ), "Valid IBAN - PL" ); + ok( method( "PT50 0002 0123 1234 5678 9015 4" ), "Valid IBAN - PT" ); + ok( method( "RO49 AAAA 1B31 0075 9384 0000" ), "Valid IBAN - RO" ); + ok( method( "SM86 U032 2509 8000 0000 0270 100" ), "Valid IBAN - SM" ); + ok( method( "SA03 8000 0000 6080 1016 7519" ), "Valid IBAN - SA" ); + ok( method( "RS35 2600 0560 1001 6113 79" ), "Valid IBAN - RS" ); + ok( method( "SK31 1200 0000 1987 4263 7541" ), "Valid IBAN - SK" ); + ok( method( "SI56 1910 0000 0123 438" ), "Valid IBAN - SI" ); + ok( method( "ES80 2310 0001 1800 0001 2345" ), "Valid IBAN - ES" ); + ok( method( "SE35 5000 0000 0549 1000 0003" ), "Valid IBAN - SE" ); + ok( method( "CH93 0076 2011 6238 5295 7" ), "Valid IBAN - CH" ); + ok( method( "TN59 1000 6035 1835 9847 8831" ), "Valid IBAN - TN" ); + ok( method( "TR33 0006 1005 1978 6457 8413 26" ), "Valid IBAN - TR" ); + ok( method( "AE07 0331 2345 6789 0123 456" ), "Valid IBAN - AE" ); + ok( method( "GB29 NWBK 6016 1331 9268 19" ), "Valid IBAN - GB" ); +} ); /** * BIC tests (For BIC definition take a look on the implementation itself) */ -test("bic", function() { +test( "bic", function() { var method = methodTest( "bic" ); ok( !method( "PBNKDEF" ), "Invalid BIC: too short" ); @@ -717,10 +717,10 @@ test("bic", function() { ok( method( "AAFFFRP1" ), "Valid BIC" ); ok( method( "DEUTDEFFAB1" ), "Valid BIC" ); ok( method( "DEUTDEFFAXX" ), "Valid BIC" ); -}); +} ); -test("postcodeUK", function() { - var method = methodTest("postcodeUK"); +test( "postcodeUK", function() { + var method = methodTest( "postcodeUK" ); ok( method( "AA9A 9AA" ), "Valid postcode" ); ok( method( "A9A 9AA" ), "Valid postcode" ); ok( method( "A9 9AA" ), "Valid postcode" ); @@ -729,128 +729,128 @@ test("postcodeUK", function() { ok( method( "AA99 9AA" ), "Valid postcode" ); // Channel Island - ok(!method( "AAAA 9AA" ), "Invalid postcode" ); - ok(!method( "AA-2640" ), "Invalid postcode" ); + ok( !method( "AAAA 9AA" ), "Invalid postcode" ); + ok( !method( "AA-2640" ), "Invalid postcode" ); - ok(!method( "AAA AAA" ), "Invalid postcode" ); - ok(!method( "AA AAAA" ), "Invalid postcode" ); - ok(!method( "A AAAA" ), "Invalid postcode" ); - ok(!method( "AAAAA" ), "Invalid postcode" ); - ok(!method( "999 999" ), "Invalid postcode" ); - ok(!method( "99 9999" ), "Invalid postcode" ); - ok(!method( "9 9999" ), "Invalid postcode" ); - ok(!method( "99999" ), "Invalid postcode" ); -}); + ok( !method( "AAA AAA" ), "Invalid postcode" ); + ok( !method( "AA AAAA" ), "Invalid postcode" ); + ok( !method( "A AAAA" ), "Invalid postcode" ); + ok( !method( "AAAAA" ), "Invalid postcode" ); + ok( !method( "999 999" ), "Invalid postcode" ); + ok( !method( "99 9999" ), "Invalid postcode" ); + ok( !method( "9 9999" ), "Invalid postcode" ); + ok( !method( "99999" ), "Invalid postcode" ); +} ); -test("dateNL", function() { - var method = methodTest("dateNL"); +test( "dateNL", function() { + var method = methodTest( "dateNL" ); ok( method( "01-01-1900" ), "Valid date NL" ); ok( method( "01.01.1900" ), "Valid date NL" ); ok( method( "01/01/1900" ), "Valid date NL" ); ok( method( "01-01-00" ), "Valid date NL" ); ok( method( "1-01-1900" ), "Valid date NL" ); ok( method( "10-10-1900" ), "Valid date NL" ); - ok(!method( "0-01-1900" ), "Invalid date NL" ); - ok(!method( "00-01-1900" ), "Invalid date NL" ); - ok(!method( "35-01-1990" ), "Invalid date NL" ); - ok(!method( "01.01.190" ), "Invalid date NL" ); -}); + ok( !method( "0-01-1900" ), "Invalid date NL" ); + ok( !method( "00-01-1900" ), "Invalid date NL" ); + ok( !method( "35-01-1990" ), "Invalid date NL" ); + ok( !method( "01.01.190" ), "Invalid date NL" ); +} ); -test("phoneNL", function() { - var method = methodTest("phoneNL"); - ok( method( "0701234567"), "Valid phone NL"); - ok( method( "0687654321"), "Valid phone NL"); - ok( method( "020-1234567"), "Valid phone NL"); - ok( method( "020 - 12 34 567"), "Valid phone NL"); - ok( method( "010-2345678"), "Valid phone NL"); - ok( method( "+3120-1234567"), "Valid phone NL"); - ok( method( "+31(0)10-2345678"), "Valid phone NL"); - ok(!method( "020-123456"), "Invalid phone NL: too short"); - ok(!method( "020-12345678"), "Invalid phone NL: too long"); - ok(!method( "-0201234567"), "Invalid phone NL"); - ok(!method( "+310201234567"), "Invalid phone NL: no 0 after +31 allowed"); -}); +test( "phoneNL", function() { + var method = methodTest( "phoneNL" ); + ok( method( "0701234567" ), "Valid phone NL" ); + ok( method( "0687654321" ), "Valid phone NL" ); + ok( method( "020-1234567" ), "Valid phone NL" ); + ok( method( "020 - 12 34 567" ), "Valid phone NL" ); + ok( method( "010-2345678" ), "Valid phone NL" ); + ok( method( "+3120-1234567" ), "Valid phone NL" ); + ok( method( "+31(0)10-2345678" ), "Valid phone NL" ); + ok( !method( "020-123456" ), "Invalid phone NL: too short" ); + ok( !method( "020-12345678" ), "Invalid phone NL: too long" ); + ok( !method( "-0201234567" ), "Invalid phone NL" ); + ok( !method( "+310201234567" ), "Invalid phone NL: no 0 after +31 allowed" ); +} ); -test("mobileNL", function() { - var method = methodTest("mobileNL"); - ok( method( "0612345678"), "Valid NL Mobile Number"); - ok( method( "06-12345678"), "Valid NL Mobile Number"); - ok( method( "06-12 345 678"), "Valid NL Mobile Number"); - ok( method( "+316-12345678"), "Valid NL Mobile Number"); - ok( method( "+31(0)6-12345678"), "Valid NL Mobile Number"); - ok(!method( "abcdefghij"), "Invalid NL Mobile Number: text"); - ok(!method( "0123456789"), "Invalid NL Mobile Number: should start with 06"); - ok(!method( "0823456789"), "Invalid NL Mobile Number: should start with 06"); - ok(!method( "06-1234567"), "Invalid NL Mobile Number: too short"); - ok(!method( "06-123456789"), "Invalid NL Mobile Number: too long"); - ok(!method( "-0612345678"), "Invalid NL Mobile Number"); - ok(!method( "+310612345678"), "Invalid NL Mobile Number: no 0 after +31 allowed"); -}); +test( "mobileNL", function() { + var method = methodTest( "mobileNL" ); + ok( method( "0612345678" ), "Valid NL Mobile Number" ); + ok( method( "06-12345678" ), "Valid NL Mobile Number" ); + ok( method( "06-12 345 678" ), "Valid NL Mobile Number" ); + ok( method( "+316-12345678" ), "Valid NL Mobile Number" ); + ok( method( "+31(0)6-12345678" ), "Valid NL Mobile Number" ); + ok( !method( "abcdefghij" ), "Invalid NL Mobile Number: text" ); + ok( !method( "0123456789" ), "Invalid NL Mobile Number: should start with 06" ); + ok( !method( "0823456789" ), "Invalid NL Mobile Number: should start with 06" ); + ok( !method( "06-1234567" ), "Invalid NL Mobile Number: too short" ); + ok( !method( "06-123456789" ), "Invalid NL Mobile Number: too long" ); + ok( !method( "-0612345678" ), "Invalid NL Mobile Number" ); + ok( !method( "+310612345678" ), "Invalid NL Mobile Number: no 0 after +31 allowed" ); +} ); -test("postalcodeNL", function() { - var method = methodTest("postalcodeNL"); - ok( method( "1234AB"), "Valid NL Postal Code"); - ok( method( "1234ab"), "Valid NL Postal Code"); - ok( method( "1234 AB"), "Valid NL Postal Code"); - ok( method( "6789YZ"), "Valid NL Postal Code"); - ok(!method( "123AA"), "Invalid NL Postal Code: not enough digits"); - ok(!method( "12345ZZ"), "Invalid NL Postal Code: too many digits"); - ok(!method( "1234 AA"), "Invalid NL Postal Code: too many spaces"); - ok(!method( "AA1234"), "Invalid NL Postal Code"); - ok(!method( "1234-AA"), "Invalid NL Postal Code"); -}); +test( "postalcodeNL", function() { + var method = methodTest( "postalcodeNL" ); + ok( method( "1234AB" ), "Valid NL Postal Code" ); + ok( method( "1234ab" ), "Valid NL Postal Code" ); + ok( method( "1234 AB" ), "Valid NL Postal Code" ); + ok( method( "6789YZ" ), "Valid NL Postal Code" ); + ok( !method( "123AA" ), "Invalid NL Postal Code: not enough digits" ); + ok( !method( "12345ZZ" ), "Invalid NL Postal Code: too many digits" ); + ok( !method( "1234 AA" ), "Invalid NL Postal Code: too many spaces" ); + ok( !method( "AA1234" ), "Invalid NL Postal Code" ); + ok( !method( "1234-AA" ), "Invalid NL Postal Code" ); +} ); -test("bankaccountNL", function() { - var method = methodTest("bankaccountNL"); - ok( method( "755490975"), "Valid NL bank account"); - ok( method( "75 54 90 975"), "Valid NL bank account"); - ok( method( "123456789"), "Valid NL bank account"); - ok( method( "12 34 56 789"), "Valid NL bank account"); - ok(!method( "12 3456789"), "Valid NL bank account: inconsistent spaces"); - ok(!method( "123 45 67 89"), "Valid NL bank account: incorrect spaces"); - ok(!method( "755490971"), "Invalid NL bank account"); - ok(!method( "755490973"), "Invalid NL bank account"); - ok(!method( "755490979"), "Invalid NL bank account"); - ok(!method( "123456781"), "Invalid NL bank account"); - ok(!method( "123456784"), "Invalid NL bank account"); - ok(!method( "123456788"), "Invalid NL bank account"); -}); +test( "bankaccountNL", function() { + var method = methodTest( "bankaccountNL" ); + ok( method( "755490975" ), "Valid NL bank account" ); + ok( method( "75 54 90 975" ), "Valid NL bank account" ); + ok( method( "123456789" ), "Valid NL bank account" ); + ok( method( "12 34 56 789" ), "Valid NL bank account" ); + ok( !method( "12 3456789" ), "Valid NL bank account: inconsistent spaces" ); + ok( !method( "123 45 67 89" ), "Valid NL bank account: incorrect spaces" ); + ok( !method( "755490971" ), "Invalid NL bank account" ); + ok( !method( "755490973" ), "Invalid NL bank account" ); + ok( !method( "755490979" ), "Invalid NL bank account" ); + ok( !method( "123456781" ), "Invalid NL bank account" ); + ok( !method( "123456784" ), "Invalid NL bank account" ); + ok( !method( "123456788" ), "Invalid NL bank account" ); +} ); -test("giroaccountNL", function() { - var method = methodTest("giroaccountNL"); - ok( method( "123"), "Valid NL giro account"); - ok( method( "1234567"), "Valid NL giro account"); - ok(!method( "123456788"), "Invalid NL giro account"); -}); +test( "giroaccountNL", function() { + var method = methodTest( "giroaccountNL" ); + ok( method( "123" ), "Valid NL giro account" ); + ok( method( "1234567" ), "Valid NL giro account" ); + ok( !method( "123456788" ), "Invalid NL giro account" ); +} ); -test("bankorgiroaccountNL", function() { - var method = methodTest("bankorgiroaccountNL"); - ok( method( "123"), "Valid NL giro account"); - ok( method( "1234567"), "Valid NL giro account"); - ok( method( "123456789"), "Valid NL bank account"); - ok(!method( "12345678"), "Invalid NL bank or giro account"); - ok(!method( "123456788"), "Invalid NL bank or giro account"); -}); +test( "bankorgiroaccountNL", function() { + var method = methodTest( "bankorgiroaccountNL" ); + ok( method( "123" ), "Valid NL giro account" ); + ok( method( "1234567" ), "Valid NL giro account" ); + ok( method( "123456789" ), "Valid NL bank account" ); + ok( !method( "12345678" ), "Invalid NL bank or giro account" ); + ok( !method( "123456788" ), "Invalid NL bank or giro account" ); +} ); -test("time", function() { - var method = methodTest("time"); +test( "time", function() { + var method = methodTest( "time" ); ok( method( "00:00" ), "Valid time, lower bound" ); ok( method( "23:59" ), "Valid time, upper bound" ); ok( method( "3:59" ), "Valid time, single digit hour" ); - ok(!method( "12" ), "Invalid time" ); - ok(!method( "29:59" ), "Invalid time" ); - ok(!method( "00:60" ), "Invalid time" ); - ok(!method( "24:60" ), "Invalid time" ); - ok(!method( "24:00" ), "Invalid time" ); - ok(!method( "30:00" ), "Invalid time" ); - ok(!method( "29:59" ), "Invalid time" ); - ok(!method( "120:00" ), "Invalid time" ); - ok(!method( "12:001" ), "Invalid time" ); - ok(!method( "12:00a" ), "Invalid time" ); -}); + ok( !method( "12" ), "Invalid time" ); + ok( !method( "29:59" ), "Invalid time" ); + ok( !method( "00:60" ), "Invalid time" ); + ok( !method( "24:60" ), "Invalid time" ); + ok( !method( "24:00" ), "Invalid time" ); + ok( !method( "30:00" ), "Invalid time" ); + ok( !method( "29:59" ), "Invalid time" ); + ok( !method( "120:00" ), "Invalid time" ); + ok( !method( "12:001" ), "Invalid time" ); + ok( !method( "12:00a" ), "Invalid time" ); +} ); -test("time12h", function() { - var method = methodTest("time12h"); +test( "time12h", function() { + var method = methodTest( "time12h" ); ok( method( "12:00 AM" ), "Valid time, lower bound, am" ); ok( method( "11:59 AM" ), "Valid time, upper bound, am" ); ok( method( "12:00AM" ), "Valid time, no space, am" ); @@ -861,65 +861,65 @@ test("time12h", function() { ok( method( "11:59 pm" ), "Valid time, also accept lowercase" ); ok( method( "1:59 pm" ), "Valid time, single hour, no leading 0" ); ok( method( "01:59 pm" ), "Valid time, single hour, leading 0" ); - ok(!method( "12:00" ), "Invalid time" ); - ok(!method( "9" ), "Invalid time" ); - ok(!method( "9 am"), "Invalid time" ); - ok(!method( "12:61 am" ), "Invalid time" ); - ok(!method( "13:00 am" ), "Invalid time" ); - ok(!method( "00:00 am" ), "Invalid time" ); -}); + ok( !method( "12:00" ), "Invalid time" ); + ok( !method( "9" ), "Invalid time" ); + ok( !method( "9 am" ), "Invalid time" ); + ok( !method( "12:61 am" ), "Invalid time" ); + ok( !method( "13:00 am" ), "Invalid time" ); + ok( !method( "00:00 am" ), "Invalid time" ); +} ); -test("minWords", function() { - var method = methodTest("minWords"); +test( "minWords", function() { + var method = methodTest( "minWords" ); ok( method( "hello worlds", 2 ), "plain text, valid" ); ok( method( "hello world", 2 ), "html, valid" ); - ok(!method( "hello", 2 ), "plain text, invalid" ); - ok(!method( "world", 2 ), "html, invalid" ); - ok(!method( "world
", 2 ), "html, invalid" ); -}); + ok( !method( "hello", 2 ), "plain text, invalid" ); + ok( !method( "world", 2 ), "html, invalid" ); + ok( !method( "world
", 2 ), "html, invalid" ); +} ); -test("maxWords", function() { - var method = methodTest("maxWords"); +test( "maxWords", function() { + var method = methodTest( "maxWords" ); ok( method( "hello", 2 ), "plain text, valid" ); ok( method( "world", 2 ), "html, valid" ); ok( method( "world
", 2 ), "html, valid" ); ok( method( "hello worlds", 2 ), "plain text, valid" ); ok( method( "hello world", 2 ), "html, valid" ); - ok(!method( "hello 123 world", 2 ), "plain text, invalid" ); - ok(!method( "hello 123 world", 2 ), "html, invalid" ); -}); + ok( !method( "hello 123 world", 2 ), "plain text, invalid" ); + ok( !method( "hello 123 world", 2 ), "html, invalid" ); +} ); -test("rangeWords", function() { - var method = methodTest("rangeWords"); +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( "hello world", [ 0, 2 ] ), "html, valid" ); - ok(!method( "hello worlds what is up", [ 0, 2 ] ), "plain text, invalid" ); - ok(!method( "Hello world hello", [ 0, 2 ] ), "html, invalid" ); -}); + ok( !method( "hello worlds what is up", [ 0, 2 ] ), "plain text, invalid" ); + ok( !method( "Hello world hello", [ 0, 2 ] ), "html, invalid" ); +} ); -test("pattern", function() { - var method = methodTest("pattern"); +test( "pattern", function() { + var method = methodTest( "pattern" ); ok( method( "AR1004", "AR\\d{4}" ), "Correct format for the given RegExp" ); ok( method( "AR1004", /^AR\d{4}$/ ), "Correct format for the given RegExp" ); - ok(!method( "BR1004", /^AR\d{4}$/ ), "Invalid format for the given RegExp" ); + ok( !method( "BR1004", /^AR\d{4}$/ ), "Invalid format for the given RegExp" ); ok( method( "1ABC", "[0-9][A-Z]{3}" ), "Correct format for the given RegExp" ); - ok(!method( "ABC", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" ); - ok(!method( "1ABC DEF", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" ); + ok( !method( "ABC", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" ); + ok( !method( "1ABC DEF", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" ); ok( method( "1ABCdef", "[a-zA-Z0-9]+" ), "Correct format for the given RegExp" ); - ok(!method( "1ABC def", "[a-zA-Z0-9]+" ), "Invalid format for the given RegExp" ); + ok( !method( "1ABC def", "[a-zA-Z0-9]+" ), "Invalid format for the given RegExp" ); ok( method( "2014-10-02", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Correct format for the given RegExp" ); - ok(!method( "02-10-2014", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Invalid format for the given RegExp" ); -}); + ok( !method( "02-10-2014", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Invalid format for the given RegExp" ); +} ); -function testCardTypeByNumber(number, cardname, expected) { - $("#cardnumber").val(number); - var actual = $("#ccform").valid(); - equal(actual, expected, $.validator.format("Expect card number {0} to validate to {1}, actually validated to ", number, expected)); +function testCardTypeByNumber( number, cardname, expected ) { + $( "#cardnumber" ).val( number ); + var actual = $( "#ccform" ).valid(); + equal( actual, expected, $.validator.format( "Expect card number {0} to validate to {1}, actually validated to ", number, expected ) ); } -test("creditcardtypes, all", function() { - $("#ccform").validate({ +test( "creditcardtypes, all", function() { + $( "#ccform" ).validate( { rules: { cardnumber: { creditcard: true, @@ -928,7 +928,7 @@ test("creditcardtypes, all", function() { } } } - }); + } ); testCardTypeByNumber( "4111-1111-1111-1111", "VISA", true ); testCardTypeByNumber( "5111-1111-1111-1118", "MasterCard", true ); @@ -939,10 +939,10 @@ test("creditcardtypes, all", function() { testCardTypeByNumber( "5432-1111-1111-1111", "MasterCard", false ); testCardTypeByNumber( "6611-6611-6611-6611", "Discover", false ); testCardTypeByNumber( "3777-7777-7777-7777", "AMEX", false ); -}); +} ); -test("creditcardtypes, visa", function() { - $("#ccform").validate({ +test( "creditcardtypes, visa", function() { + $( "#ccform" ).validate( { rules: { cardnumber: { creditcard: true, @@ -951,16 +951,16 @@ test("creditcardtypes, visa", function() { } } } - }); + } ); testCardTypeByNumber( "4111-1111-1111-1111", "VISA", true ); testCardTypeByNumber( "5111-1111-1111-1118", "MasterCard", false ); testCardTypeByNumber( "6111-1111-1111-1116", "Discover", false ); testCardTypeByNumber( "3400-0000-0000-009", "AMEX", false ); -}); +} ); -test("creditcardtypes, mastercard", function() { - $("#ccform").validate({ +test( "creditcardtypes, mastercard", function() { + $( "#ccform" ).validate( { rules: { cardnumber: { creditcard: true, @@ -969,13 +969,13 @@ test("creditcardtypes, mastercard", function() { } } } - }); + } ); testCardTypeByNumber( "5111-1111-1111-1118", "MasterCard", true ); testCardTypeByNumber( "6111-1111-1111-1116", "Discover", false ); testCardTypeByNumber( "3400-0000-0000-009", "AMEX", false ); testCardTypeByNumber( "4111-1111-1111-1111", "VISA", false ); -}); +} ); /* function fillFormWithValuesAndExpect(formSelector, inputValues, expected) { @@ -1060,20 +1060,20 @@ test("skip_or_fill_minimum preserve other rules", function() { }); */ -test("zipcodeUS", function() { - var method = methodTest("zipcodeUS"); +test( "zipcodeUS", function() { + var method = methodTest( "zipcodeUS" ); ok( method( "12345" ), "Valid zip" ); ok( method( "12345-2345" ), "Valid zip" ); ok( method( "90210-4567" ), "Valid zip" ); - ok(!method( "1" ), "Invalid zip" ); - ok(!method( "1234" ), "Invalid zip" ); - ok(!method( "123-23" ), "Invalid zip" ); - ok(!method( "12345-43" ), "Invalid zip" ); - ok(!method( "123456-7890" ), "Invalid zip" ); -}); + ok( !method( "1" ), "Invalid zip" ); + ok( !method( "1234" ), "Invalid zip" ); + ok( !method( "123-23" ), "Invalid zip" ); + ok( !method( "12345-43" ), "Invalid zip" ); + ok( !method( "123456-7890" ), "Invalid zip" ); +} ); -test("nifES", function() { - var method = methodTest("nifES"); +test( "nifES", function() { + var method = methodTest( "nifES" ); ok( method( "11441059P" ), "NIF valid" ); ok( method( "80054306T" ), "NIF valid" ); ok( method( "76048581R" ), "NIF valid" ); @@ -1086,23 +1086,23 @@ test("nifES", function() { ok( method( "15762034L" ), "NIF valid" ); ok( method( "05122654W" ), "NIF valid" ); ok( method( "05122654w" ), "NIF valid: lower case" ); - ok(!method( "1144105R" ), "NIF invalid: less than 8 digits without zero" ); - ok(!method( "11441059 R" ), "NIF invalid: white space" ); - ok(!method( "11441059" ), "NIF invalid: no letter" ); - ok(!method( "11441059PR" ), "NIF invalid: two letters" ); - ok(!method( "11440059R" ), "NIF invalid: wrong number" ); - ok(!method( "11441059S" ), "NIF invalid: wrong letter" ); - ok(!method( "114410598R" ), "NIF invalid: > 8 digits" ); - ok(!method( "11441059-R" ), "NIF invalid: dash" ); - ok(!method( "asdasdasd" ), "NIF invalid: all letters" ); - ok(!method( "11.144.059R" ), "NIF invalid: two dots" ); - ok(!method( "05.122.654R" ), "NIF invalid: starts with 0 and dots" ); - ok(!method( "5.122.654-R" ), "NIF invalid: dots and dash" ); - ok(!method( "05.122.654-R" ), "NIF invalid: starts with zero and dot and dash" ); -}); + ok( !method( "1144105R" ), "NIF invalid: less than 8 digits without zero" ); + ok( !method( "11441059 R" ), "NIF invalid: white space" ); + ok( !method( "11441059" ), "NIF invalid: no letter" ); + ok( !method( "11441059PR" ), "NIF invalid: two letters" ); + ok( !method( "11440059R" ), "NIF invalid: wrong number" ); + ok( !method( "11441059S" ), "NIF invalid: wrong letter" ); + ok( !method( "114410598R" ), "NIF invalid: > 8 digits" ); + ok( !method( "11441059-R" ), "NIF invalid: dash" ); + ok( !method( "asdasdasd" ), "NIF invalid: all letters" ); + ok( !method( "11.144.059R" ), "NIF invalid: two dots" ); + ok( !method( "05.122.654R" ), "NIF invalid: starts with 0 and dots" ); + ok( !method( "5.122.654-R" ), "NIF invalid: dots and dash" ); + ok( !method( "05.122.654-R" ), "NIF invalid: starts with zero and dot and dash" ); +} ); -test("nieES", function() { - var method = methodTest("nieES"); +test( "nieES", function() { + var method = methodTest( "nieES" ); ok( method( "X0093999K" ), "NIE valid" ); ok( method( "X1923000Q" ), "NIE valid" ); ok( method( "Z9669587R" ), "NIE valid" ); @@ -1115,23 +1115,23 @@ test("nieES", function() { ok( method( "X3744072V" ), "NIE valid" ); ok( method( "X7436800A" ), "NIE valid" ); ok( method( "y7875935j" ), "NIE valid: lower case" ); - ok(!method( "X0093999 K" ), "NIE inválido: white space" ); - ok(!method( "X 0093999 K" ), "NIE inválido: white space" ); - ok(!method( "11441059" ), "NIE inválido: no letter" ); - ok(!method( "11441059PR" ), "NIE inválido: two letters" ); - ok(!method( "11440059R" ), "NIE inválido: wrong number" ); - ok(!method( "11441059S" ), "NIE inválido: wrong letter" ); - ok(!method( "114410598R" ), "NIE inválido: > 8 digits" ); - ok(!method( "11441059-R" ), "NIE inválido: dash" ); - ok(!method( "asdasdasd" ), "NIE inválido: all letters" ); - ok(!method( "11.144.059R" ), "NIE inválido: two dots" ); - ok(!method( "05.122.654R" ), "NIE inválido: starts with 0 and dots" ); - ok(!method( "5.122.654-R" ), "NIE inválido: dots and dash" ); - ok(!method( "05.122.654-R" ), "NIE inválido: starts with zero and dot and dash" ); -}); + ok( !method( "X0093999 K" ), "NIE inválido: white space" ); + ok( !method( "X 0093999 K" ), "NIE inválido: white space" ); + ok( !method( "11441059" ), "NIE inválido: no letter" ); + ok( !method( "11441059PR" ), "NIE inválido: two letters" ); + ok( !method( "11440059R" ), "NIE inválido: wrong number" ); + ok( !method( "11441059S" ), "NIE inválido: wrong letter" ); + ok( !method( "114410598R" ), "NIE inválido: > 8 digits" ); + ok( !method( "11441059-R" ), "NIE inválido: dash" ); + ok( !method( "asdasdasd" ), "NIE inválido: all letters" ); + ok( !method( "11.144.059R" ), "NIE inválido: two dots" ); + ok( !method( "05.122.654R" ), "NIE inválido: starts with 0 and dots" ); + ok( !method( "5.122.654-R" ), "NIE inválido: dots and dash" ); + ok( !method( "05.122.654-R" ), "NIE inválido: starts with zero and dot and dash" ); +} ); -test("cifES", function() { - var method = methodTest("cifES"); +test( "cifES", function() { + var method = methodTest( "cifES" ); ok( method( "A79082244" ), "CIF valid" ); ok( method( "A60917978" ), "CIF valid" ); ok( method( "A39000013" ), "CIF valid" ); @@ -1146,131 +1146,131 @@ test("cifES", function() { ok( method( "C27827559" ), "CIF valid" ); ok( method( "E48911572" ), "CIF valid" ); ok( method( "s98038813" ), "CIF valid: lower case" ); - ok(!method( "K48911572" ), "CIF invalid: starts with K" ); - ok(!method( "L48911572" ), "CIF invalid: starts with L" ); - ok(!method( "M48911572" ), "CIF invalid: starts with M" ); - ok(!method( "X48911572" ), "CIF invalid: starts with X" ); - ok(!method( "Y48911572" ), "CIF invalid: starts with Y" ); - ok(!method( "Z48911572" ), "CIF invalid: starts with Z" ); - ok(!method( "M15661515" ), "CIF invalid" ); - ok(!method( "Z98038813" ), "CIF invalid: wrong letter" ); - ok(!method( "B 43522192" ), "CIF invalid: white spaces" ); - ok(!method( "43522192" ), "CIF invalid: missing letter" ); - ok(!method( "BB43522192" ), "CIF invalid: two letters" ); - ok(!method( "B53522192" ), "CIF invalid: wrong number" ); - ok(!method( "B433522192" ), "CIF invalid: > 8 digits" ); - ok(!method( "B3522192" ), "CIF invalid: < 8 digits" ); - ok(!method( "B-43522192" ), "CIF invalid: dash" ); - ok(!method( "Basdasdas" ), "CIF invalid: all letters" ); - ok(!method( "B43.522.192" ), "CIF invalid: dots" ); - ok(!method( "B-43.522.192" ), "CIF invalid: dots and dash" ); -}); + ok( !method( "K48911572" ), "CIF invalid: starts with K" ); + ok( !method( "L48911572" ), "CIF invalid: starts with L" ); + ok( !method( "M48911572" ), "CIF invalid: starts with M" ); + ok( !method( "X48911572" ), "CIF invalid: starts with X" ); + ok( !method( "Y48911572" ), "CIF invalid: starts with Y" ); + ok( !method( "Z48911572" ), "CIF invalid: starts with Z" ); + ok( !method( "M15661515" ), "CIF invalid" ); + ok( !method( "Z98038813" ), "CIF invalid: wrong letter" ); + ok( !method( "B 43522192" ), "CIF invalid: white spaces" ); + ok( !method( "43522192" ), "CIF invalid: missing letter" ); + ok( !method( "BB43522192" ), "CIF invalid: two letters" ); + ok( !method( "B53522192" ), "CIF invalid: wrong number" ); + ok( !method( "B433522192" ), "CIF invalid: > 8 digits" ); + ok( !method( "B3522192" ), "CIF invalid: < 8 digits" ); + ok( !method( "B-43522192" ), "CIF invalid: dash" ); + ok( !method( "Basdasdas" ), "CIF invalid: all letters" ); + ok( !method( "B43.522.192" ), "CIF invalid: dots" ); + ok( !method( "B-43.522.192" ), "CIF invalid: dots and dash" ); +} ); -test("maxWords", function() { - var method = methodTest("maxWords"), +test( "maxWords", function() { + var method = methodTest( "maxWords" ), maxWords = 6; - ok( method( "I am a sentence", maxWords), "Max Words"); - ok(!method( "I'm way too long for this sentence!", maxWords), "Too many words"); - ok(method( "Don’t “count” me as too long", maxWords), "Right amount of words with smartquotes"); - ok(!method( "But you can “count” me as too long", maxWords), "Too many words with smartquotes"); - ok(method( "
Don’t “count” me as too long
", maxWords), "Right amount of words with smartquotes w/ HTML"); - ok(!method( "
But you can “count” me as too long
", maxWords), "Too many words with smartquotes w/ HTML"); -}); + ok( method( "I am a sentence", maxWords ), "Max Words" ); + ok( !method( "I'm way too long for this sentence!", maxWords ), "Too many words" ); + ok( method( "Don’t “count” me as too long", maxWords ), "Right amount of words with smartquotes" ); + ok( !method( "But you can “count” me as too long", maxWords ), "Too many words with smartquotes" ); + ok( method( "
Don’t “count” me as too long
", maxWords ), "Right amount of words with smartquotes w/ HTML" ); + ok( !method( "
But you can “count” me as too long
", maxWords ), "Too many words with smartquotes w/ HTML" ); +} ); -test("minWords", function() { - var method = methodTest("minWords"), +test( "minWords", function() { + var method = methodTest( "minWords" ), minWords = 6; - ok(!method( "I am a short sentence", minWords), "Max Words"); - ok( method( "I'm way too long for this sentence!", minWords), "Too many words"); - ok(!method( "Don’t “count” me as short.", minWords), "Right amount of words with smartquotes"); - ok( method( "But you can “count” me as too short", minWords), "Too many words with smartquotes"); - ok(!method( "
“Count” me as too short.
", minWords), "Right amount of words with smartquotes w/ HTML"); - ok( method( "
But you can “count” me as too long
", minWords), "Too many words with smartquotes w/ HTML"); -}); + ok( !method( "I am a short sentence", minWords ), "Max Words" ); + ok( method( "I'm way too long for this sentence!", minWords ), "Too many words" ); + ok( !method( "Don’t “count” me as short.", minWords ), "Right amount of words with smartquotes" ); + ok( method( "But you can “count” me as too short", minWords ), "Too many words with smartquotes" ); + ok( !method( "
“Count” me as too short.
", minWords ), "Right amount of words with smartquotes w/ HTML" ); + ok( method( "
But you can “count” me as too long
", minWords ), "Too many words with smartquotes w/ HTML" ); +} ); -test("rangeWords", function() { - var method = methodTest("rangeWords"), +test( "rangeWords", function() { + var method = methodTest( "rangeWords" ), 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"); - ok( method( "Super short sentence’s.", rangeWords), "Low end"); - ok(!method( "I", rangeWords), "Too short"); - ok( method( "
“Count” me as perfect.
", rangeWords), "Right amount of words with smartquotes w/ HTML"); - ok(!method( "
But you can “count” me as too long
", rangeWords), "Too many words with smartquotes w/ HTML"); -}); + 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" ); + ok( method( "Super short sentence’s.", rangeWords ), "Low end" ); + ok( !method( "I", rangeWords ), "Too short" ); + ok( method( "
“Count” me as perfect.
", rangeWords ), "Right amount of words with smartquotes w/ HTML" ); + ok( !method( "
But you can “count” me as too long
", rangeWords ), "Too many words with smartquotes w/ HTML" ); +} ); -test("currency", function() { // Works with any symbol +test( "currency", function() { // Works with any symbol var method = methodTest( "currency" ); - ok( method( "£9", "£"), "Symbol no decimal" ); - ok( method( "£9.9", "£"), "£, one decimal" ); - ok( method( "£9.99", "£"), "£, two decimal" ); - ok( method( "£9.90", "£"), "Valid currency" ); - 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,", "£"), "Invalid currency" ); - ok(!method( "9,99.99", "£"), "Invalid currency" ); - ok(!method( "9,", "£"), "Invalid currency" ); - ok(!method( "9.999", "£"), "Invalid currency" ); - ok(!method( "9.999", "£"), "Invalid currency" ); - ok(!method( "9.99,9", "£"), "Invalid currency" ); -}); + ok( method( "£9", "£" ), "Symbol no decimal" ); + ok( method( "£9.9", "£" ), "£, one decimal" ); + ok( method( "£9.99", "£" ), "£, two decimal" ); + ok( method( "£9.90", "£" ), "Valid currency" ); + 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,", "£" ), "Invalid currency" ); + ok( !method( "9,99.99", "£" ), "Invalid currency" ); + ok( !method( "9,", "£" ), "Invalid currency" ); + ok( !method( "9.999", "£" ), "Invalid currency" ); + ok( !method( "9.999", "£" ), "Invalid currency" ); + ok( !method( "9.99,9", "£" ), "Invalid currency" ); +} ); -test("postalCodeCA", function() { - var method = methodTest("postalCodeCA"); - ok( method( "H0H0H0"), "Valid Canadian postal code: all upper case with no space" ); - ok( method( "H0H 0H0"), "Valid Canadian postal code: all upper case with one space" ); - ok( method( "H0H 0H0"), "Valid Canadian postal code: all upper case with multiple spaces" ); - ok( method( "h0h 0h0"), "Valid Canadian postal code: all lower case with space" ); +test( "postalCodeCA", function() { + var method = methodTest( "postalCodeCA" ); + ok( method( "H0H0H0" ), "Valid Canadian postal code: all upper case with no space" ); + ok( method( "H0H 0H0" ), "Valid Canadian postal code: all upper case with one space" ); + ok( method( "H0H 0H0" ), "Valid Canadian postal code: all upper case with multiple spaces" ); + ok( method( "h0h 0h0" ), "Valid Canadian postal code: all lower case with space" ); ok( method( "h0h0h0" ), "Valid Canadian postal code: all lower case with no space" ); - ok( !method( "H0H-0H0"), "Invalid Canadian postal code: dash used as separator" ); - ok( !method( "H0H 0H"), "Invalid Canadian postal code: too short" ); - ok( !method( "Z0H 0H0"), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVXY' are valid first characters for the Forward Sorting Area" ); - ok( !method( "H0D 0H0"), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid third characters for the Forward Sorting Area" ); - ok( !method( "H0H 0D0"), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid second characters for the Local Delivery Unit" ); -}); + ok( !method( "H0H-0H0" ), "Invalid Canadian postal code: dash used as separator" ); + ok( !method( "H0H 0H" ), "Invalid Canadian postal code: too short" ); + ok( !method( "Z0H 0H0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVXY' are valid first characters for the Forward Sorting Area" ); + ok( !method( "H0D 0H0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid third characters for the Forward Sorting Area" ); + ok( !method( "H0H 0D0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid second characters for the Local Delivery Unit" ); +} ); -test("stateUS", function() { - var method = methodTest("stateUS"); +test( "stateUS", function() { + var method = methodTest( "stateUS" ); ok( method( "AZ" ), "Valid US state" ); ok( method( "OH" ), "Valid US state" ); ok( method( "DC" ), "Valid US state" ); ok( method( "PR", { includeTerritories: true } ), "Valid US territory" ); ok( method( "AA", { includeMilitary: true } ), "Valid US military zone" ); ok( method( "me", { caseSensitive: false } ), "Valid US state" ); - ok(!method( "az", { caseSensitive: true } ), "Must be capital letters" ); - ok(!method( "mp", { caseSensitive: false, includeTerritories: false } ), "US territories not allowed" ); -}); + ok( !method( "az", { caseSensitive: true } ), "Must be capital letters" ); + ok( !method( "mp", { caseSensitive: false, includeTerritories: false } ), "US territories not allowed" ); +} ); -test("postalcodeBR", function() { - var method = methodTest("postalcodeBR"); - ok( method( "99999-999"), "Valid BR Postal Code"); - ok( method( "99999999"), "Valid BR Postal Code"); - ok( method( "99.999-999"), "Valid BR Postal Code"); - ok( !method( "99.999999"), "Invalid BR Postal Code"); -}); +test( "postalcodeBR", function() { + var method = methodTest( "postalcodeBR" ); + ok( method( "99999-999" ), "Valid BR Postal Code" ); + ok( method( "99999999" ), "Valid BR Postal Code" ); + ok( method( "99.999-999" ), "Valid BR Postal Code" ); + ok( !method( "99.999999" ), "Invalid BR Postal Code" ); +} ); -test("cpfBR", function() { - var method = methodTest("cpfBR"); - ok( method( "11144477735"), "Valid CPF Number"); - ok( method( "263.946.533-30"), "Valid CPF Number"); - ok( method( "325 861 044 47"), "Valid CPF Number"); - ok( method( "859-684-732-40"), "Valid CPF Number"); - ok( !method( "99999999999"), "Invalid CPF Number: dump data"); - ok( !method( "1114447773"), "Invalid CPF Number: < 11 digits"); - ok( !method( "111444777355"), "Invalid CPF Number: > 11 digits"); - ok( !method( "11144477715"), "Invalid CPF Number: 1st check number failed"); - ok( !method( "11144477737"), "Invalid CPF Number: 2nd check number failed"); -}); +test( "cpfBR", function() { + var method = methodTest( "cpfBR" ); + ok( method( "11144477735" ), "Valid CPF Number" ); + ok( method( "263.946.533-30" ), "Valid CPF Number" ); + ok( method( "325 861 044 47" ), "Valid CPF Number" ); + ok( method( "859-684-732-40" ), "Valid CPF Number" ); + ok( !method( "99999999999" ), "Invalid CPF Number: dump data" ); + ok( !method( "1114447773" ), "Invalid CPF Number: < 11 digits" ); + ok( !method( "111444777355" ), "Invalid CPF Number: > 11 digits" ); + ok( !method( "11144477715" ), "Invalid CPF Number: 1st check number failed" ); + ok( !method( "11144477737" ), "Invalid CPF Number: 2nd check number failed" ); +} ); -})(jQuery); +} )( jQuery ); diff --git a/test/rules.js b/test/rules.js index f19a870..5a3ea06 100644 --- a/test/rules.js +++ b/test/rules.js @@ -1,87 +1,87 @@ -module("rules"); +module( "rules" ); -test("rules() - internal - input", function() { - var element = $("#firstname"); +test( "rules() - internal - input", function() { + var element = $( "#firstname" ); - $("#testForm1").validate(); + $( "#testForm1" ).validate(); deepEqual( element.rules(), { required: true, minlength: 2 } ); -}); +} ); -test("rules(), ignore method:false", function() { - var element = $("#firstnamec"); +test( "rules(), ignore method:false", function() { + var element = $( "#firstnamec" ); - $("#testForm1clean").validate({ + $( "#testForm1clean" ).validate( { rules: { firstnamec: { required: false, minlength: 2 } } - }); + } ); deepEqual( element.rules(), { minlength: 2 } ); -}); +} ); -test("rules() HTML5 required (no value)", function() { - var element = $("#testForm11text1"); +test( "rules() HTML5 required (no value)", function() { + var element = $( "#testForm11text1" ); - $("#testForm11").validate(); + $( "#testForm11" ).validate(); deepEqual( element.rules(), { required: true } ); -}); +} ); -test("rules() - internal - select", function() { - var element = $("#meal"); +test( "rules() - internal - select", function() { + var element = $( "#meal" ); - $("#testForm3").validate(); + $( "#testForm3" ).validate(); deepEqual( element.rules(), { required: true } ); -}); +} ); -test("rules() - external", function() { - var element = $("#text1"); +test( "rules() - external", function() { + var element = $( "#text1" ); - $("#form").validate({ + $( "#form" ).validate( { rules: { action: { date: true, min: 5 } } - }); + } ); deepEqual( element.rules(), { date: true, min: 5 } ); -}); +} ); -test("rules() - external - complete form", function() { - expect(1); +test( "rules() - external - complete form", function() { + expect( 1 ); - var methods = $.extend({}, $.validator.methods), - messages = $.extend({}, $.validator.messages), + var methods = $.extend( {}, $.validator.methods ), + messages = $.extend( {}, $.validator.messages ), v; - $.validator.addMethod("verifyTest", function() { + $.validator.addMethod( "verifyTest", function() { ok( true, "method executed" ); return true; - }); - v = $("#form").validate({ + } ); + v = $( "#form" ).validate( { rules: { action: { verifyTest: true } } - }); + } ); v.form(); $.validator.methods = methods; $.validator.messages = messages; -}); +} ); -test("rules() - internal - input", function() { - var element = $("#form8input"); +test( "rules() - internal - input", function() { + var element = $( "#form8input" ); - $("#testForm8").validate(); + $( "#testForm8" ).validate(); deepEqual( element.rules(), { required: true, number: true, rangelength: [ 2, 8 ] } ); -}); +} ); -test("rules(), merge min/max to range, minlength/maxlength to rangelength", function() { +test( "rules(), merge min/max to range, minlength/maxlength to rangelength", function() { jQuery.validator.autoCreateRanges = true; - $("#testForm1clean").validate({ + $( "#testForm1clean" ).validate( { rules: { firstnamec: { min: -15, @@ -92,69 +92,69 @@ test("rules(), merge min/max to range, minlength/maxlength to rangelength", func maxlength: 10 } } - }); + } ); - deepEqual( $("#firstnamec").rules(), { range: [ -15, 0 ] } ); - deepEqual( $("#lastnamec").rules(), { rangelength: [ 0, 10 ] } ); + deepEqual( $( "#firstnamec" ).rules(), { range: [ -15, 0 ] } ); + deepEqual( $( "#lastnamec" ).rules(), { rangelength: [ 0, 10 ] } ); jQuery.validator.autoCreateRanges = false; -}); +} ); -test("rules(), guarantee that required is at front", function() { - $("#testForm1").validate(); - var v = $("#v2").validate(); - $("#subformRequired").validate(); - function flatRules(element) { +test( "rules(), guarantee that required is at front", function() { + $( "#testForm1" ).validate(); + var v = $( "#v2" ).validate(); + $( "#subformRequired" ).validate(); + function flatRules( element ) { var result = []; - jQuery.each($(element).rules(), function(key) { result.push(key); }); - return result.join(" "); + jQuery.each( $( element ).rules(), function( key ) { result.push( key ); } ); + return result.join( " " ); } - equal( "required minlength", flatRules("#firstname") ); - equal( "required minlength maxlength", flatRules("#v2-i6") ); - equal( "required maxlength", flatRules("#co_name") ); + equal( flatRules( "#firstname" ), "required minlength" ); + equal( flatRules( "#v2-i6" ), "required minlength maxlength" ); + equal( flatRules( "#co_name" ), "required maxlength" ); QUnit.reset(); jQuery.validator.autoCreateRanges = true; - v = $("#v2").validate(); - equal( "required rangelength", flatRules("#v2-i6") ); + v = $( "#v2" ).validate(); + equal( flatRules( "#v2-i6" ), "required rangelength" ); - $("#subformRequired").validate({ + $( "#subformRequired" ).validate( { rules: { co_name: "required" } - }); - $("#co_name").removeClass(); - equal( "required maxlength", flatRules("#co_name") ); + } ); + $( "#co_name" ).removeClass(); + equal( flatRules( "#co_name" ), "required maxlength" ); jQuery.validator.autoCreateRanges = false; -}); +} ); -test("rules(), evaluate dynamic parameters", function() { - expect(2); +test( "rules(), evaluate dynamic parameters", function() { + expect( 2 ); - $("#testForm1clean").validate({ + $( "#testForm1clean" ).validate( { rules: { firstnamec: { - min: function(element) { - equal( $("#firstnamec")[0], element ); + min: function( element ) { + equal( $( "#firstnamec" )[ 0 ], element ); return 12; } } } - }); + } ); - deepEqual( $("#firstnamec").rules(), { min: 12 }); -}); + deepEqual( $( "#firstnamec" ).rules(), { min: 12 } ); +} ); -test("rules(), class and attribute combinations", function() { +test( "rules(), class and attribute combinations", function() { - $.validator.addMethod("customMethod1", function() { + $.validator.addMethod( "customMethod1", function() { return false; - }, ""); - $.validator.addMethod("customMethod2", function() { + }, "" ); + $.validator.addMethod( "customMethod2", function() { return false; - }, ""); + }, "" ); - $("#v2").validate({ + $( "#v2" ).validate( { rules: { "v2-i7": { required: true, @@ -162,33 +162,33 @@ test("rules(), class and attribute combinations", function() { customMethod: true } } - }); + } ); - deepEqual( $("#v2-i1").rules(), { required: true }); - deepEqual( $("#v2-i2").rules(), { required: true, email: true }); - deepEqual( $("#v2-i3").rules(), { url: true }); - deepEqual( $("#v2-i4").rules(), { required: true, minlength: 2 }); - deepEqual( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" }); + deepEqual( $( "#v2-i1" ).rules(), { required: true } ); + deepEqual( $( "#v2-i2" ).rules(), { required: true, email: true } ); + deepEqual( $( "#v2-i3" ).rules(), { url: true } ); + 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 }); + deepEqual( $( "#v2-i7" ).rules(), { required: true, minlength: 2, customMethod: true } ); delete $.validator.methods.customMethod1; delete $.validator.messages.customMethod1; delete $.validator.methods.customMethod2; delete $.validator.messages.customMethod2; -}); +} ); -test("rules(), dependency checks", function() { - var v = $("#testForm1clean").validate({ +test( "rules(), dependency checks", function() { + var v = $( "#testForm1clean" ).validate( { rules: { firstnamec: { min: { param: 5, - depends: function(el) { - return (/^a/).test($(el).val()); + depends: function( el ) { + return ( /^a/ ).test( $( el ).val() ); } } }, @@ -201,107 +201,107 @@ test("rules(), dependency checks", function() { } } } - }), - rules = $("#firstnamec").rules(); + } ), + rules = $( "#firstnamec" ).rules(); - equal( 0, v.objectLength(rules) ); + equal( v.objectLength( rules ), 0 ); - $("#firstnamec").val("ab"); - deepEqual( $("#firstnamec").rules(), { min: 5 }); + $( "#firstnamec" ).val( "ab" ); + 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() { - $.validator.addMethod("customMethod1", function() { +test( "rules(), add and remove", function() { + $.validator.addMethod( "customMethod1", function() { return false; - }, ""); - $("#v2").validate(); - $("#v2-i5").removeClass("required").removeAttr("minlength maxlength"); - deepEqual( $("#v2-i5").rules(), { customMethod1: "123" }); + }, "" ); + $( "#v2" ).validate(); + $( "#v2-i5" ).removeClass( "required" ).removeAttr( "minlength maxlength" ); + deepEqual( $( "#v2-i5" ).rules(), { customMethod1: "123" } ); - $("#v2-i5").addClass("required").attr({ + $( "#v2-i5" ).addClass( "required" ).attr( { minlength: 2, maxlength: 5 - }); - deepEqual( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" }); + } ); + deepEqual( $( "#v2-i5" ).rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" } ); - $("#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" ).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").removeAttr("minlength maxlength customMethod1 min"); - deepEqual( $("#v2-i5").rules(), {}); + $( "#v2-i5" ).removeClass( "required email" ).removeAttr( "minlength maxlength customMethod1 min" ); + deepEqual( $( "#v2-i5" ).rules(), {} ); delete $.validator.methods.customMethod1; delete $.validator.messages.customMethod1; -}); +} ); -test("rules(), add and remove static rules", function() { +test( "rules(), add and remove static rules", function() { - $("#testForm1clean").validate({ + $( "#testForm1clean" ).validate( { rules: { firstnamec: "required date" } - }); + } ); - deepEqual( $("#firstnamec").rules(), { required: true, date: true } ); + deepEqual( $( "#firstnamec" ).rules(), { required: true, date: true } ); - $("#firstnamec").rules("remove", "date"); - deepEqual( $("#firstnamec").rules(), { required: true } ); - $("#firstnamec").rules("add", "email"); - deepEqual( $("#firstnamec").rules(), { required: true, email: true } ); + $( "#firstnamec" ).rules( "remove", "date" ); + deepEqual( $( "#firstnamec" ).rules(), { required: true } ); + $( "#firstnamec" ).rules( "add", "email" ); + deepEqual( $( "#firstnamec" ).rules(), { required: true, email: true } ); - $("#firstnamec").rules("remove", "required"); - deepEqual( $("#firstnamec").rules(), { email: true } ); + $( "#firstnamec" ).rules( "remove", "required" ); + deepEqual( $( "#firstnamec" ).rules(), { email: true } ); - deepEqual( $("#firstnamec").rules("remove"), { email: true } ); - deepEqual( $("#firstnamec").rules(), { } ); + deepEqual( $( "#firstnamec" ).rules( "remove" ), { email: true } ); + deepEqual( $( "#firstnamec" ).rules(), {} ); - $("#firstnamec").rules("add", "required email"); - deepEqual( $("#firstnamec").rules(), { required: true, email: true } ); + $( "#firstnamec" ).rules( "add", "required email" ); + deepEqual( $( "#firstnamec" ).rules(), { required: true, email: true } ); - deepEqual( $("#lastnamec").rules(), {} ); - $("#lastnamec").rules("add", "required"); - $("#lastnamec").rules("add", { + deepEqual( $( "#lastnamec" ).rules(), {} ); + $( "#lastnamec" ).rules( "add", "required" ); + $( "#lastnamec" ).rules( "add", { minlength: 2 - }); - deepEqual( $("#lastnamec").rules(), { required: true, minlength: 2 } ); + } ); + deepEqual( $( "#lastnamec" ).rules(), { required: true, minlength: 2 } ); - var removedRules = $("#lastnamec").rules("remove", "required email"); - deepEqual( $("#lastnamec").rules(), { minlength: 2 } ); - $("#lastnamec").rules("add", removedRules); - deepEqual( $("#lastnamec").rules(), { required: true, minlength: 2 } ); -}); + var removedRules = $( "#lastnamec" ).rules( "remove", "required email" ); + deepEqual( $( "#lastnamec" ).rules(), { minlength: 2 } ); + $( "#lastnamec" ).rules( "add", removedRules ); + deepEqual( $( "#lastnamec" ).rules(), { required: true, minlength: 2 } ); +} ); -test("rules(), add messages", function() { - $("#firstnamec").attr("title", null); - var v = $("#testForm1clean").validate({ +test( "rules(), add messages", function() { + $( "#firstnamec" ).attr( "title", null ); + var v = $( "#testForm1clean" ).validate( { rules: { firstnamec: "required" } - }); - $("#testForm1clean").valid(); - $("#firstnamec").valid(); + } ); + $( "#testForm1clean" ).valid(); + $( "#firstnamec" ).valid(); deepEqual( v.settings.messages.firstname, undefined ); - $("#firstnamec").rules("add", { + $( "#firstnamec" ).rules( "add", { messages: { required: "required" } - }); + } ); - $("#firstnamec").valid(); - deepEqual( v.errorList[0] && v.errorList[0].message, "required" ); + $( "#firstnamec" ).valid(); + deepEqual( v.errorList[ 0 ] && v.errorList[ 0 ].message, "required" ); - $("#firstnamec").val("test"); - $("#firstnamec").valid(); - equal(v.errorList.length, 0); -}); + $( "#firstnamec" ).val( "test" ); + $( "#firstnamec" ).valid(); + equal( v.errorList.length, 0 ); +} ); test( "rules(), rangelength attribute as array", function() { - $("#testForm13").validate(); - deepEqual( $("#cars-select").rules(), { + $( "#testForm13" ).validate(); + deepEqual( $( "#cars-select" ).rules(), { required: true, rangelength: [ 2, 3 ] - }); -}); + } ); +} ); diff --git a/test/test.js b/test/test.js index 712df97..94b2088 100644 --- a/test/test.js +++ b/test/test.js @@ -4,14 +4,14 @@ if ( window.sessionStorage ) { jQuery.validator.defaults.debug = true; $.mockjaxSettings.log = $.noop; -$.mockjax({ +$.mockjax( { url: "form.php?user=Peter&password=foobar", responseText: "Hi Peter, welcome back.", responseStatus: 200, responseTime: 1 -}); +} ); -$.mockjax({ +$.mockjax( { url: "users.php", data: { username: /Peter2?|asdf/ @@ -19,9 +19,9 @@ $.mockjax({ responseText: "false", responseStatus: 200, responseTime: 1 -}); +} ); -$.mockjax({ +$.mockjax( { url: "users2.php", data: { username: "asdf" @@ -29,15 +29,15 @@ $.mockjax({ responseText: "\"asdf is already taken, please try something else\"", responseStatus: 200, responseTime: 1 -}); +} ); -$.mockjax({ +$.mockjax( { url: "echo.php", response: function( data ) { this.responseText = JSON.stringify( data.data ); }, responseTime: 100 -}); +} ); // Asserts that there is a visible error with the given text for the specified element QUnit.assert.hasError = function( element, text, message ) { @@ -61,11 +61,11 @@ test( "Constructor", function() { 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", 0, function() { $( "#doesntexist" ).validate(); -}); +} ); test( "valid() plugin method", function() { var form = $( "#userForm" ), @@ -78,7 +78,7 @@ test( "valid() plugin method", function() { input.val( "Hello world" ); ok ( form.valid(), "Form is now valid" ); ok ( input.valid(), "Input is valid, too" ); -}); +} ); test( "valid() plugin method, multiple inputs", function() { var form = $( "#testForm1" ), @@ -91,7 +91,7 @@ test( "valid() plugin method, multiple inputs", function() { strictEqual( inputs.valid(), false, "just one invalid" ); inputs.val( "ok" ); strictEqual( inputs.valid(), true, "all valid" ); -}); +} ); test( "valid() plugin method, special handling for checkable groups", function() { // rule is defined on first checkbox, must apply to others, too @@ -103,7 +103,7 @@ test( "valid() plugin method, special handling for checkable groups", function() ok( !checkable.valid(), "invalid again" ); $( "#checkable3" ).attr( "checked", true ); ok( checkable.valid(), "valid, third box is checked" ); -}); +} ); test( "valid() ???", function() { expect( 4 ); @@ -120,25 +120,25 @@ test( "valid() ???", function() { v.errorList = errorList; ok( !v.valid(), "One error, must be invalid" ); QUnit.reset(); - v = $( "#testForm3" ).validate({ + 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" ); -}); +} ); test( "valid(), ignores ignored elements", function() { - $( "#testForm1clean" ).validate({ + $( "#testForm1clean" ).validate( { ignore: "#firstnamec", rules: { firstnamec: "required" } - }); + } ); ok( $( "#firstnamec" ).valid() ); -}); +} ); test( "addMethod", function() { expect( 3 ); @@ -151,28 +151,28 @@ test( "addMethod", function() { e.value = "hi"; ok( method( e.value, e ), "Invalid" ); ok( jQuery.validator.messages.hi === "hi me too", "Check custom message" ); -}); +} ); test( "addMethod2", function() { expect( 4 ); $.validator.addMethod( "complicatedPassword", function( value, element ) { return this.optional( element ) || /\D/.test( value ) && /\d/.test( value ); }, "Your password must contain at least one number and one letter" ); - var v = jQuery( "#form" ).validate({ + var v = jQuery( "#form" ).validate( { rules: { action: { complicatedPassword: true } } - }), + } ), e = $( "#text1" )[ 0 ]; e.value = ""; strictEqual( v.element( e ), true, "Rule is optional, valid" ); - equal( 0, v.size() ); + equal( v.size(), 0 ); e.value = "ko"; ok( !v.element( e ), "Invalid, doesn't contain one of the required characters" ); e.value = "ko1"; ok( v.element( e ) ); -}); +} ); test( "form(): simple", function() { expect( 2 ); @@ -183,7 +183,7 @@ test( "form(): simple", function() { $( "#firstname" ).val( "hi" ); $( "#lastname" ).val( "hi" ); ok( v.form(), "Valid form" ); -}); +} ); test( "form(): checkboxes: min/required", function() { expect( 3 ); @@ -195,27 +195,27 @@ test( "form(): checkboxes: min/required", function() { ok( !v.form(), "Invalid form" ); $( "#form6check2" ).attr( "checked", true ); ok( v.form(), "Valid form" ); -}); +} ); test( "form(): radio buttons: required", function() { expect( 6 ); var form = $( "#testForm10" )[ 0 ], - v = $( form ).validate({ + v = $( form ).validate( { rules: { testForm10Radio: "required" } - }); + } ); - ok(!v.form(), "Invalid Form" ); - equal($( "#testForm10Radio1" ).attr( "class" ), "error" ); - equal($( "#testForm10Radio2" ).attr( "class" ), "error" ); + ok( !v.form(), "Invalid Form" ); + equal( $( "#testForm10Radio1" ).attr( "class" ), "error" ); + equal( $( "#testForm10Radio2" ).attr( "class" ), "error" ); $( "#testForm10Radio2" ).attr( "checked", true ); ok( v.form(), "Valid form" ); - equal($( "#testForm10Radio1" ).attr( "class" ), "valid" ); - equal($( "#testForm10Radio2" ).attr( "class" ), "valid" ); -}); + equal( $( "#testForm10Radio1" ).attr( "class" ), "valid" ); + equal( $( "#testForm10Radio2" ).attr( "class" ), "valid" ); +} ); test( "form(): selects: min/required", function() { expect( 3 ); @@ -227,7 +227,7 @@ test( "form(): selects: min/required", function() { ok( !v.form(), "Invalid form" ); $( "#optionxb" ).attr( "selected", true ); ok( v.form(), "Valid form" ); -}); +} ); test( "form(): with equalTo", function() { expect( 2 ); @@ -237,24 +237,24 @@ test( "form(): with equalTo", function() { ok( !v.form(), "Invalid form" ); $( "#x1, #x2" ).val( "hi" ); ok( v.form(), "Valid form" ); -}); +} ); test( "form(): with equalTo and onfocusout=false", function() { expect( 4 ); var form = $( "#testForm5" )[ 0 ], - v = $( form ).validate({ + v = $( form ).validate( { onfocusout: false, showErrors: function() { ok( true, "showErrors should only be called twice" ); this.defaultShowErrors(); } - }); + } ); $( "#x1, #x2" ).val( "hi" ); ok( v.form(), "Valid form" ); $( "#x2" ).val( "not equal" ).blur(); ok( !v.form(), "Invalid form" ); -}); +} ); test( "check(): simple", function() { expect( 3 ); @@ -268,7 +268,7 @@ test( "check(): simple", function() { $( "#firstname" ).val( "hi" ); v.check( element ); ok( v.size() === 0, "No more errors" ); -}); +} ); test( "hide(): input", function() { expect( 3 ); @@ -283,7 +283,7 @@ test( "hide(): input", function() { ok( errorLabel.is( ":visible" ), "Error label visible before validation" ); ok( v.element( element ) ); ok( errorLabel.is( ":hidden" ), "Error label not visible after validation" ); -}); +} ); test( "hide(): radio", function() { expect( 2 ); @@ -292,13 +292,13 @@ test( "hide(): radio", function() { v; element.checked = true; - v = $( "#testForm2" ).validate({ errorClass: "xerror" }); + v = $( "#testForm2" ).validate( { errorClass: "xerror" } ); errorLabel.show(); ok( errorLabel.is( ":visible" ), "Error label visible after validation" ); v.element( element ); ok( errorLabel.is( ":hidden" ), "Error label not visible after hiding it" ); -}); +} ); test( "hide(): errorWrapper", function() { expect( 2 ); @@ -310,15 +310,15 @@ test( "hide(): errorWrapper", function() { errorLabel.show(); ok( errorLabel.is( ":visible" ), "Error label visible after validation" ); - v = $( "#testForm3" ).validate({ wrapper: "li", errorLabelContainer: $( "#errorContainer" ) }); + v = $( "#testForm3" ).validate( { wrapper: "li", errorLabelContainer: $( "#errorContainer" ) } ); v.element( element ); ok( errorLabel.is( ":hidden" ), "Error label not visible after hiding it" ); -}); +} ); test( "hide(): container", function() { expect( 4 ); var errorLabel = $( "#errorContainer" ), - v = $( "#testForm3" ).validate({ errorWrapper: "li", errorContainer: $( "#errorContainer" ) }); + v = $( "#testForm3" ).validate( { errorWrapper: "li", errorContainer: $( "#errorContainer" ) } ); v.form(); ok( errorLabel.is( ":visible" ), "Error label visible after validation" ); @@ -331,12 +331,12 @@ test( "hide(): container", function() { $( "#meal" )[ 0 ].selectedIndex = 1; v.element( "#meal" ); ok( errorLabel.is( ":hidden" ), "Error label not visible after hiding it" ); -}); +} ); test( "submitHandler keeps submitting button", function() { var button, event; - $( "#userForm" ).validate({ + $( "#userForm" ).validate( { debug: true, submitHandler: function( form ) { // dunno how to test this better; this tests the implementation that uses a hidden input @@ -344,20 +344,20 @@ test( "submitHandler keeps submitting button", function() { deepEqual( hidden.value, button.value ); deepEqual( hidden.name, button.name ); } - }); + } ); $( "#username" ).val( "bla" ); button = $( "#userForm :submit" )[ 0 ]; event = $.Event( "click" ); event.preventDefault(); $.event.trigger( event, null, button ); $( "#userForm" ).submit(); -}); +} ); -asyncTest("validation triggered on radio/checkbox when using keyboard", function() { +asyncTest( "validation triggered on radio/checkbox when using keyboard", function() { expect( 1 ); var input, i, events, triggeredEvents = 0; - $("#form").validate({ + $( "#form" ).validate( { onfocusin: function() { triggeredEvents++; }, @@ -367,61 +367,61 @@ asyncTest("validation triggered on radio/checkbox when using keyboard", function onkeyup: function() { triggeredEvents++; } - }); + } ); events = [ - $.Event("focusin"), - $.Event("focusout"), - $.Event("keyup") + $.Event( "focusin" ), + $.Event( "focusout" ), + $.Event( "keyup" ) ]; - input = $("#form :radio:first"); - for (i = 0; i < events.length; i++) { - input.trigger(events[i]); + input = $( "#form :radio:first" ); + for ( i = 0; i < events.length; i++ ) { + input.trigger( events[ i ] ); } - input = $("#form :checkbox:first"); + input = $( "#form :checkbox:first" ); for (i = 0; i < events.length; i++) { - input.trigger(events[i]); + input.trigger( events[ i ] ); } - setTimeout(function() { + setTimeout( function() { // assert all event handlers fired - equal(6, triggeredEvents); + equal( triggeredEvents, 6 ); start(); - }); -}); + } ); +} ); -asyncTest("validation triggered on radio/checkbox when using mouseclick", function() { +asyncTest( "validation triggered on radio/checkbox when using mouseclick", function() { expect( 1 ); var input, i, events, triggeredEvents = 0; - $("#form").validate({ + $( "#form" ).validate( { onclick: function() { triggeredEvents++; } - }); + } ); events = [ - $.Event("click") + $.Event( "click" ) ]; - input = $("#form :radio:first"); - for (i = 0; i < events.length; i++) { - input.trigger(events[i]); + input = $( "#form :radio:first" ); + for ( i = 0; i < events.length; i++ ) { + input.trigger( events[ i ] ); } - input = $("#form :checkbox:first"); - for (i = 0; i < events.length; i++) { - input.trigger(events[i]); + input = $( "#form :checkbox:first" ); + for ( i = 0; i < events.length; i++ ) { + input.trigger( events[ i ] ); } setTimeout(function() { // assert all event handlers fired - equal(2, triggeredEvents); + equal( triggeredEvents, 2 ); start(); - }); -}); + } ); +} ); test( "showErrors()", function() { expect( 4 ); @@ -429,14 +429,14 @@ test( "showErrors()", function() { v = $( "#testForm1" ).validate(); ok( errorLabel.is( ":hidden" ) ); - equal( 0, $( "#lastname" ).next( ".error:not(input)" ).length ); - v.showErrors({ "firstname": "required", "lastname": "bla" }); - equal( true, errorLabel.is( ":visible" ) ); - equal( true, $( "#lastname" ).next( ".error:not(input)" ).is( ":visible" ) ); -}); + equal( $( "#lastname" ).next( ".error:not(input)" ).length, 0 ); + v.showErrors( { "firstname": "required", "lastname": "bla" } ); + equal( errorLabel.is( ":visible" ), true ); + equal( $( "#lastname" ).next( ".error:not(input)" ).is( ":visible" ), true ); +} ); test( "showErrors(), allow empty string and null as default message", function() { - $( "#userForm" ).validate({ + $( "#userForm" ).validate( { rules: { username: { required: true, @@ -449,18 +449,18 @@ test( "showErrors(), allow empty string and null as default message", function() minlength: "too short" } } - }); + } ); ok( !$( "#username" ).valid() ); - equal( "", $( "#username" ).next( ".error:not(input)" ).text() ); + equal( $( "#username" ).next( ".error:not(input)" ).text(), "" ); $( "#username" ).val( "ab" ); ok( !$( "#username" ).valid() ); - equal( "too short", $( "#username" ).next( ".error:not(input)" ).text() ); + equal( $( "#username" ).next( ".error:not(input)" ).text(), "too short" ); $( "#username" ).val( "abc" ); ok( $( "#username" ).valid() ); ok( $( "#username" ).next( ".error:not(input)" ).is( ":hidden" ) ); -}); +} ); test( "showErrors() - external messages", function() { expect( 4 ); @@ -468,39 +468,39 @@ test( "showErrors() - external messages", function() { messages = $.extend( {}, $.validator.messages ), form, v; - $.validator.addMethod( "foo", function() { return false; }); - $.validator.addMethod( "bar", function() { return false; }); - equal( 0, $( "#testForm4 #f1" ).next( ".error:not(input)" ).length ); - equal( 0, $( "#testForm4 #f2" ).next( ".error:not(input)" ).length ); + $.validator.addMethod( "foo", function() { return false; } ); + $.validator.addMethod( "bar", function() { return false; } ); + equal( $( "#testForm4 #f1" ).next( ".error:not(input)" ).length, 0 ); + equal( $( "#testForm4 #f2" ).next( ".error:not(input)" ).length, 0 ); form = $( "#testForm4" )[ 0 ]; - v = $( form ).validate({ + v = $( form ).validate( { messages: { f1: "Please!", f2: "Wohoo!" } - }); + } ); v.form(); equal( $( "#testForm4 #f1" ).next( ".error:not(input)" ).text(), "Please!" ); equal( $( "#testForm4 #f2" ).next( ".error:not(input)" ).text(), "Wohoo!" ); $.validator.methods = methods; $.validator.messages = messages; -}); +} ); test( "showErrors() - custom handler", function() { expect( 5 ); - var v = $( "#testForm1" ).validate({ + var v = $( "#testForm1" ).validate( { showErrors: function( errorMap, errorList ) { equal( v, this ); equal( v.errorList, errorList ); equal( v.errorMap, errorMap ); - equal( "buga", errorMap.firstname ); - equal( "buga", errorMap.lastname ); + equal( errorMap.firstname, "buga" ); + equal( errorMap.lastname, "buga" ); } - }); + } ); v.form(); -}); +} ); test( "option: (un)highlight, default", function() { $( "#testForm1" ).validate(); @@ -513,31 +513,31 @@ test( "option: (un)highlight, default", function() { e.val( "hithere" ).valid(); ok( !e.hasClass( "error" ) ); ok( e.hasClass( "valid" ) ); -}); +} ); test( "option: (un)highlight, nothing", function() { expect( 3 ); - $( "#testForm1" ).validate({ + $( "#testForm1" ).validate( { highlight: false, unhighlight: false - }); + } ); var e = $( "#firstname" ); ok( !e.hasClass( "error" ) ); e.valid(); ok( !e.hasClass( "error" ) ); e.valid(); ok( !e.hasClass( "error" ) ); -}); +} ); test( "option: (un)highlight, custom", function() { expect( 5 ); - $( "#testForm1clean" ).validate({ + $( "#testForm1clean" ).validate( { highlight: function( element, errorClass ) { - equal( "invalid", errorClass ); + equal( errorClass, "invalid" ); $( element ).hide(); }, unhighlight: function( element, errorClass ) { - equal( "invalid", errorClass ); + equal( errorClass, "invalid" ); $( element ).show(); }, ignore: "", @@ -545,19 +545,19 @@ test( "option: (un)highlight, custom", function() { rules: { firstnamec: "required" } - }); + } ); var e = $( "#firstnamec" ); ok( e.is( ":visible" ) ); e.valid(); ok( !e.is( ":visible" ) ); e.val( "hithere" ).valid(); ok( e.is( ":visible" ) ); -}); +} ); test( "option: (un)highlight, custom2", function() { expect( 6 ); var e, l; - $( "#testForm1" ).validate({ + $( "#testForm1" ).validate( { highlight: function( element, errorClass ) { $( element ).addClass( errorClass ); $( element ).next( ".error:not(input)" ).addClass( errorClass ); @@ -567,7 +567,7 @@ test( "option: (un)highlight, custom2", function() { $( element ).next( ".error:not(input)" ).removeClass( errorClass ); }, errorClass: "invalid" - }); + } ); e = $( "#firstname" ); l = $( "#errorFirstname" ); @@ -580,7 +580,7 @@ test( "option: (un)highlight, custom2", function() { e.val( "hithere" ).valid(); ok( !e.is( ".invalid" ) ); ok( !l.is( ".invalid" ) ); -}); +} ); test( "option: focusCleanup default false", function() { var form = $( "#userForm" ); @@ -589,38 +589,38 @@ test( "option: focusCleanup default false", function() { ok( form.find( "#username" ).next( ".error:not(input)" ).is( ":visible" )); $( "#username" ).focus(); ok( form.find( "#username" ).next( ".error:not(input)" ).is( ":visible" )); -}); +} ); test( "option: focusCleanup true", function() { var form = $( "#userForm" ); - form.validate({ + form.validate( { focusCleanup: true - }); + } ); form.valid(); ok( form.find( "#username" ).next( ".error:not(input)" ).is( ":visible" ) ); $( "#username" ).focus().trigger( "focusin" ); ok( !form.find( "#username" ).next( ".error:not(input)" ).is( ":visible" ) ); -}); +} ); test( "option: focusCleanup with wrapper", function() { var form = $( "#userForm" ); - form.validate({ + form.validate( { focusCleanup: true, wrapper: "span" - }); + } ); form.valid(); ok( form.is( ":has(span:visible:has(.error#username-error))" ) ); $( "#username" ).focus().trigger( "focusin" ); ok( !form.is( ":has(span:visible:has(.error#username-error))" ) ); -}); +} ); test( "option: errorClass with multiple classes", function() { var form = $( "#userForm" ); - form.validate({ + form.validate( { focusCleanup: true, wrapper: "span", errorClass: "error error1 error2" - }); + } ); form.valid(); ok( form.is( ":has(span:visible:has(.error#username-error))" ) ); ok( form.is( ":has(span:visible:has(.error1#username-error))" ) ); @@ -629,28 +629,28 @@ test( "option: errorClass with multiple classes", function() { ok( !form.is( ":has(span:visible:has(.error#username-error))" ) ); ok( !form.is( ":has(span:visible:has(.error1#username-error))" ) ); ok( !form.is( ":has(span:visible:has(.error2#username-error))" ) ); -}); +} ); test( "defaultMessage(), empty title is ignored", function() { var v = $( "#userForm" ).validate(); - equal( "This field is required.", v.defaultMessage($( "#username" )[ 0 ], "required" ) ); -}); + equal( v.defaultMessage( $( "#username" )[ 0 ], "required" ), "This field is required." ); +} ); test( "formatAndAdd", function() { expect( 4 ); var v = $( "#form" ).validate(), fakeElement = { form: $( "#form" )[ 0 ], name: "bar" }; - 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: "maxlength", parameters: 2 } ); + equal( v.errorList[ 0 ].message, "Please enter no more than 2 characters." ); + equal( v.errorList[ 0 ].element.name, "bar" ); - 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( v.errorList[ 1 ].message, "Please enter a value between 2 and 4." ); - 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( v.errorList[ 2 ].message, "Please enter a value between 0 and 4." ); +} ); test( "formatAndAdd2", function() { expect( 3 ); @@ -658,16 +658,16 @@ test( "formatAndAdd2", function() { fakeElement = { form: $( "#form" )[ 0 ], name: "bar" }; jQuery.validator.messages.test1 = function( param, element ) { - equal( v, this ); - equal( 0, param ); + equal( this, v ); + equal( param, 0 ); return "element " + element.name + " is not valid"; }; - v.formatAndAdd( fakeElement, { method: "test1", parameters: 0 }); - equal( "element bar is not valid", v.errorList[ 0 ].message ); -}); + v.formatAndAdd( fakeElement, { method: "test1", parameters: 0 } ); + equal( v.errorList[ 0 ].message, "element bar is not valid" ); +} ); test( "formatAndAdd, auto detect substitution string", function() { - var v = $( "#testForm1clean" ).validate({ + var v = $( "#testForm1clean" ).validate( { rules: { firstnamec: { required: true, @@ -679,45 +679,45 @@ test( "formatAndAdd, auto detect substitution string", function() { rangelength: "at least ${0}, up to {1}" } } - }); + } ); $( "#firstnamec" ).val( "abc" ); v.form(); - equal( "at least 5, up to 10", v.errorList[ 0 ].message ); -}); + equal( v.errorList[ 0 ].message, "at least 5, up to 10" ); +} ); asyncTest( "option invalidHandler", function() { expect( 1 ); - $( "#testForm1clean" ).validate({ + $( "#testForm1clean" ).validate( { invalidHandler: function() { ok( true, "invalid-form event triggered called" ); start(); } - }); - $( "#usernamec" ).val( "asdf" ).rules( "add", { required: true, minlength: 5 }); + } ); + $( "#usernamec" ).val( "asdf" ).rules( "add", { required: true, minlength: 5 } ); $( "#testForm1clean" ).submit(); -}); +} ); test( "findByName()", function() { deepEqual( - new $.validator({}, document.getElementById( "form" )) + new $.validator( {}, document.getElementById( "form" )) .findByName( document.getElementById( "radio1" ).name ) .get(), $( "#form" ).find( "[name=radio1]" ).get() ); -}); +} ); test( "focusInvalid()", function() { // TODO when using custom focusin, this is triggered just once // TODO when using 1.4 focusin, triggered twice; fix once not testing against 1.3 anymore // expect( 1 ); var inputs = $( "#testForm1 input" ).focus(function() { - equal( inputs[ 0 ], this, "focused first element" ); - }), + equal( this, inputs[ 0 ], "focused first element" ); + } ), v = $( "#testForm1" ).validate(); v.form(); v.focusInvalid(); -}); +} ); test( "focusInvalid() after validate a custom set of inputs", function() { var form = $( "#testForm1" ), @@ -727,12 +727,12 @@ test( "focusInvalid() after validate a custom set of inputs", function() { $( "#firstname" ).val( "ok" ); - ok( !inputs.valid(), "just one invalid"); + ok( !inputs.valid(), "just one invalid" ); validator.focusInvalid(); - equal( form[ 0 ].ownerDocument.activeElement, $( "#lastname" )[0], "focused first element" ); -}); + equal( form[ 0 ].ownerDocument.activeElement, $( "#lastname" )[ 0 ], "focused first element" ); +} ); test( "findLastActive()", function() { expect( 3 ); @@ -746,14 +746,14 @@ test( "findLastActive()", function() { lastActive = $( "#lastname" ).trigger( "focus" ).trigger( "focusin" )[ 0 ]; equal( v.lastActive, lastActive ); -}); +} ); -test("elementValue() finds radios/checkboxes only within the current form", function() { - expect(1); - var v = $("#userForm").validate(), foreignRadio = $("#radio2")[0]; +test( "elementValue() finds radios/checkboxes only within the current form", function() { + expect( 1 ); + var v = $( "#userForm" ).validate(), foreignRadio = $( "#radio2" )[ 0 ]; - ok( !v.elementValue(foreignRadio) ); -}); + ok( !v.elementValue( foreignRadio ) ); +} ); test( "validating multiple checkboxes with 'required'", function() { expect( 3 ); @@ -761,18 +761,18 @@ test( "validating multiple checkboxes with 'required'", function() { v; equal( checkboxes.length, 5 ); - v = $( "#form" ).validate({ + v = $( "#form" ).validate( { rules: { check3: "required" } - }); + } ); v.form(); equal( v.size(), 1 ); checkboxes.filter( ":last" ).prop( "checked", true ); v.form(); equal( v.size(), 0 ); -}); +} ); test( "dynamic form", function() { var counter = 0, @@ -781,7 +781,7 @@ test( "dynamic form", function() { $( "" ).appendTo( "#testForm2" ); } function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } v = $( "#testForm2" ).validate(); @@ -808,20 +808,20 @@ test( "dynamic form", function() { $( "#agb" ).attr( "disabled", false ); v.form(); errors( 1 ); -}); +} ); test( "idOrName()", function() { expect( 4 ); var v = $( "#testForm1" ).validate(); - 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 ] ) ); -}); + equal( v.idOrName( $( "#form8input" )[ 0 ] ), "form8input" ); + equal( v.idOrName( $( "#form6check1" )[ 0 ] ), "check" ); + equal( v.idOrName( $( "#agb" )[ 0 ] ), "agree" ); + equal( v.idOrName( $( "#form :button" )[ 0 ] ), "button" ); +} ); test( "resetForm()", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } var v = $( "#testForm1" ).validate(); v.form(); @@ -831,13 +831,13 @@ test( "resetForm()", function() { v.resetForm(); errors( 0 ); ok( !$( "#firstname" ).hasClass( "error" ) ); - equal( "", $( "#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( "resetForm() clean styles when custom highlight function is used", function() { var form = $( "#testForm1clean" ), e = $( "#firstnamec" ); - form.validate({ + form.validate( { highlight: function( element ) { $( element ).hide(); }, @@ -849,50 +849,50 @@ test( "resetForm() clean styles when custom highlight function is used", functio rules: { firstnamec: "required" } - }); + } ); e.valid(); ok( !e.is( ":visible" ) ); form.validate().resetForm(); ok( e.is( ":visible" ) ); -}); +} ); test( "message from title", function() { var v = $( "#withTitle" ).validate(); v.checkForm(); equal( v.errorList[ 0 ].message, "fromtitle", "title not used" ); -}); +} ); 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" ); -}); +} ); asyncTest( "ajaxSubmit", function() { expect( 1 ); $( "#user" ).val( "Peter" ); $( "#password" ).val( "foobar" ); - jQuery( "#signupForm" ).validate({ + jQuery( "#signupForm" ).validate( { submitHandler: function( form ) { - jQuery( form ).ajaxSubmit({ + jQuery( form ).ajaxSubmit( { success: function( response ) { - equal( "Hi Peter, welcome back.", response ); + equal( response, "Hi Peter, welcome back." ); start(); } - }); + } ); } - }); + } ); jQuery( "#signupForm" ).triggerHandler( "submit" ); -}); +} ); test( "validating groups settings parameter", function() { var form = $( "
" ), - validate = form.validate({ + validate = form.validate( { groups: { arrayGroup: [ "input one", "input-two", "input three" ], stringGroup: "input-four input-five input-six" } - }); + } ); equal( validate.groups[ "input one" ], "arrayGroup" ); equal( validate.groups[ "input-two" ], "arrayGroup" ); @@ -900,7 +900,7 @@ test( "validating groups settings parameter", function() { equal( validate.groups[ "input-four" ], "stringGroup" ); equal( validate.groups[ "input-five" ], "stringGroup" ); equal( validate.groups[ "input-six" ], "stringGroup" ); -}); +} ); test( "bypassing validation on form submission", function() { var form = $( "#bypassValidation" ), @@ -908,34 +908,34 @@ test( "bypassing validation on form submission", function() { bypassSubmitWithCancel = $( "form#bypassValidation :input[id=bypassSubmitWithCancel]" ), bypassSubmitWithNoValidate1 = $( "form#bypassValidation :input[id=bypassSubmitWithNoValidate1]" ), bypassSubmitWithNoValidate2 = $( "form#bypassValidation :input[id=bypassSubmitWithNoValidate2]" ), - $v = form.validate({ + $v = form.validate( { debug: true - }); + } ); bypassSubmitWithCancel.click(); - equal($v.numberOfInvalids(), 0, "Validation was bypassed using CSS 'cancel' class." ); + equal( $v.numberOfInvalids(), 0, "Validation was bypassed using CSS 'cancel' class." ); $v.resetForm(); bypassSubmitWithNoValidate1.click(); - equal($v.numberOfInvalids(), 0, "Validation was bypassed using blank 'formnovalidate' attribute." ); + equal( $v.numberOfInvalids(), 0, "Validation was bypassed using blank 'formnovalidate' attribute." ); $v.resetForm(); bypassSubmitWithNoValidate2.click(); - equal($v.numberOfInvalids(), 0, "Validation was bypassed using 'formnovalidate=\"formnovalidate\"' attribute." ); + equal( $v.numberOfInvalids(), 0, "Validation was bypassed using 'formnovalidate=\"formnovalidate\"' attribute." ); $v.resetForm(); normalSubmission.click(); - equal($v.numberOfInvalids(), 1, "Validation failed correctly" ); -}); + equal( $v.numberOfInvalids(), 1, "Validation failed correctly" ); +} ); module( "misc" ); test( "success option", function() { expect( 7 ); - equal( "", $( "#firstname" ).val() ); - var v = $( "#testForm1" ).validate({ + equal( $( "#firstname" ).val(), "" ); + var v = $( "#testForm1" ).validate( { success: "valid" - }), + } ), label = $( "#testForm1 .error:not(input)" ); ok( label.is( ".error" ) ); @@ -947,14 +947,14 @@ test( "success option", function() { v.form(); ok( label.is( ".error" ) ); ok( label.is( ".valid" ) ); -}); +} ); test( "success option2", function() { expect( 5 ); - equal( "", $( "#firstname" ).val() ); - var v = $( "#testForm1" ).validate({ + equal( $( "#firstname" ).val(), "" ); + var v = $( "#testForm1" ).validate( { success: "valid" - }), + } ), label = $( "#testForm1 .error:not(input)" ); ok( label.is( ".error" ) ); @@ -963,53 +963,53 @@ test( "success option2", function() { v.form(); ok( label.is( ".error" ) ); ok( label.is( ".valid" ) ); -}); +} ); test( "success option3", function() { expect( 5 ); - equal( "", $( "#firstname" ).val() ); + equal( $( "#firstname" ).val(), "" ); $( "#errorFirstname" ).remove(); - var v = $( "#testForm1" ).validate({ + var v = $( "#testForm1" ).validate( { success: "valid" - }), + } ), labels; - equal( 0, $( "#testForm1 .error:not(input)" ).length ); + equal( $( "#testForm1 .error:not(input)" ).length, 0 ); $( "#firstname" ).val( "hi" ); v.form(); labels = $( "#testForm1 .error:not(input)" ); - equal( 3, labels.length ); + equal( labels.length, 3 ); ok( labels.eq( 0 ).is( ".valid" ) ); ok( !labels.eq( 1 ).is( ".valid" ) ); -}); +} ); test( "successlist", function() { - var v = $( "#form" ).validate({ success: "xyz" }); + var v = $( "#form" ).validate( { success: "xyz" } ); v.form(); - equal( 0, v.successList.length ); -}); + equal( v.successList.length, 0 ); +} ); test( "success isn't called for optional elements with no other rules", function() { expect( 4 ); - equal( "", $( "#firstname" ).removeAttr( "data-rule-required" ).removeAttr( "data-rule-minlength" ).val() ); + equal( $( "#firstname" ).removeAttr( "data-rule-required" ).removeAttr( "data-rule-minlength" ).val(), "" ); $( "#something" ).remove(); $( "#lastname" ).remove(); $( "#errorFirstname" ).remove(); - var v = $( "#testForm1" ).validate({ + var v = $( "#testForm1" ).validate( { success: function() { ok( false, "don't call success for optional elements!" ); }, rules: { firstname: { required: false } } - }); - equal( 0, $( "#testForm1 .error:not(input)" ).length ); + } ); + equal( $( "#testForm1 .error:not(input)" ).length, 0 ); v.form(); - equal( 0, $( "#testForm1 .error:not(input)" ).length ); + equal( $( "#testForm1 .error:not(input)" ).length, 0 ); $( "#firstname" ).valid(); - equal( 0, $( "#testForm1 .error:not(input)" ).length ); -}); + equal( $( "#testForm1 .error:not(input)" ).length, 0 ); +} ); test( "success is called for optional elements with other rules", function() { expect( 1 ); @@ -1018,7 +1018,7 @@ test( "success is called for optional elements with other rules", function() { return true; }, "" ); - $( "#testForm1clean" ).validate({ + $( "#testForm1clean" ).validate( { success: function() { ok( true, "success called correctly!" ); }, @@ -1028,135 +1028,135 @@ test( "success is called for optional elements with other rules", function() { custom1: true } } - }); + } ); $( "#firstnamec" ).valid(); delete $.validator.methods.custom1; -}); +} ); test( "success callback with element", function() { expect( 1 ); - var v = $( "#userForm" ).validate({ + var v = $( "#userForm" ).validate( { success: function( label, element ) { equal( element, $( "#username" ).get( 0 ) ); } - }); + } ); $( "#username" ).val( "hi" ); v.form(); -}); +} ); test( "all rules are evaluated even if one returns a dependency-mistmatch", function() { expect( 6 ); - equal( "", $( "#firstname" ).removeAttr( "data-rule-required" ).removeAttr( "data-rule-minlength" ).val() ); + equal( $( "#firstname" ).removeAttr( "data-rule-required" ).removeAttr( "data-rule-minlength" ).val(), "" ); $( "#lastname" ).remove(); $( "#errorFirstname" ).remove(); $.validator.addMethod( "custom1", function() { ok( true, "custom method must be evaluated" ); return true; }, "" ); - var v = $( "#testForm1" ).validate({ + var v = $( "#testForm1" ).validate( { rules: { firstname: { email: true, custom1: true } } - }); - equal( 0, $( "#testForm1 .error:not(input)" ).length ); + } ); + equal( $( "#testForm1 .error:not(input)" ).length, 0 ); v.form(); - equal( 0, $( "#testForm1 .error:not(input)" ).length ); + equal( $( "#testForm1 .error:not(input)" ).length, 0 ); $( "#firstname" ).valid(); - equal( 0, $( "#testForm1 .error:not(input)" ).length ); + equal( $( "#testForm1 .error:not(input)" ).length, 0 ); delete $.validator.methods.custom1; delete $.validator.messages.custom1; -}); +} ); 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 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( m.maxlength( 0 ), "Please enter no more than 0 characters." ); + equal( m.minlength( 1 ), "Please enter at least 1 characters." ); + equal( m.rangelength( [ 1, 2 ] ), "Please enter a value between 1 and 2 characters long." ); + equal( m.max( 1 ), "Please enter a value less than or equal to 1." ); + equal( m.min( 0 ), "Please enter a value greater than or equal to 0." ); + equal( m.range( [ 1, 2 ] ), "Please enter a value between 1 and 2." ); +} ); test( "jQuery.validator.format", function() { equal( - "Please enter a value between 0 and 1.", - jQuery.validator.format( "Please enter a value between {0} and {1}.", 0, 1 ) + jQuery.validator.format( "Please enter a value between {0} and {1}.", 0, 1 ), + "Please enter a value between 0 and 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 ) + jQuery.validator.format( "{0} is too fast! Enter a value smaller then {0} and at least {1}", 0, -15 ), + "0 is too fast! Enter a value smaller then 0 and at least -15" ); var template = jQuery.validator.format( "{0} is too fast! Enter a value smaller then {0} and at least {1}" ); - equal( "0 is too fast! Enter a value smaller then 0 and at least -15", template( 0, -15 ) ); + equal( template( 0, -15 ), "0 is too fast! Enter a value smaller then 0 and at least -15" ); template = jQuery.validator.format( "Please enter a value between {0} and {1}." ); - equal( "Please enter a value between 1 and 2.", template( [ 1, 2 ] ) ); + equal( template( [ 1, 2 ] ), "Please enter a value between 1 and 2." ); equal( $.validator.format( "{0}", "$0" ), "$0" ); -}); +} ); test( "option: ignore", function() { - var v = $( "#testForm1" ).validate({ + var v = $( "#testForm1" ).validate( { ignore: "[name=lastname]" - }); + } ); v.form(); - equal( 1, v.size() ); -}); + equal( v.size(), 1 ); +} ); test( "option: subformRequired", function() { jQuery.validator.addMethod( "billingRequired", function( value, element ) { - if ($( "#bill_to_co" ).is( ":checked" )) { + if ( $( "#bill_to_co" ).is( ":checked" ) ) { return $( element ).parents( "#subform" ).length; } return !this.optional( element ); }, "" ); var v = $( "#subformRequired" ).validate(); v.form(); - equal( 1, v.size() ); + equal( v.size(), 1 ); $( "#bill_to_co" ).attr( "checked", false ); v.form(); - equal( 2, v.size() ); + equal( v.size(), 2 ); delete $.validator.methods.billingRequired; delete $.validator.messages.billingRequired; -}); +} ); module( "expressions" ); test( "expression: :blank", function() { var e = $( "#lastname" )[ 0 ]; - equal( 1, $( e ).filter( ":blank" ).length ); + equal( $( e ).filter( ":blank" ).length, 1 ); e.value = " "; - equal( 1, $( e ).filter( ":blank" ).length ); + equal( $( e ).filter( ":blank" ).length, 1 ); e.value = " "; - equal( 1, $( e ).filter( ":blank" ).length ); + equal( $( e ).filter( ":blank" ).length, 1 ); e.value = " a "; - equal( 0, $( e ).filter( ":blank" ).length ); -}); + equal( $( e ).filter( ":blank" ).length, 0 ); +} ); test( "expression: :filled", function() { var e = $( "#lastname" )[ 0 ]; - equal( 0, $( e ).filter( ":filled" ).length ); + equal( $( e ).filter( ":filled" ).length, 0 ); e.value = " "; - equal( 0, $( e ).filter( ":filled" ).length ); + equal( $( e ).filter( ":filled" ).length, 0 ); e.value = " "; - equal( 0, $( e ).filter( ":filled" ).length ); + equal( $( e ).filter( ":filled" ).length, 0 ); e.value = " a "; - equal( 1, $( e ).filter( ":filled" ).length ); -}); + equal( $( e ).filter( ":filled" ).length, 1 ); +} ); test( "expression: :unchecked", function() { var e = $( "#check2" )[ 0 ]; - equal( 1, $( e ).filter( ":unchecked" ).length ); + equal( $( e ).filter( ":unchecked" ).length, 1 ); e.checked = true; - equal( 0, $( e ).filter( ":unchecked" ).length ); + equal( $( e ).filter( ":unchecked" ).length, 0 ); e.checked = false; - equal( 1, $( e ).filter( ":unchecked" ).length ); -}); + equal( $( e ).filter( ":unchecked" ).length, 1 ); +} ); module( "events" ); @@ -1201,11 +1201,11 @@ test( "validate on blur", function() { blur( e ); errors( 0, "Both required and minlength are met, no errors left" ); labels( 2 ); -}); +} ); test( "validate on keyup", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } function keyup( target ) { target.trigger( "keyup" ); @@ -1232,16 +1232,16 @@ test( "validate on keyup", function() { e.val( "hh" ); keyup( e ); errors( 0, "Valid" ); -}); +} ); test( "validate on not keyup, only blur", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } var e = $( "#firstname" ), - v = $( "#testForm1" ).validate({ + v = $( "#testForm1" ).validate( { onkeyup: false - }); + } ); errors( 0 ); e.val( "a" ); @@ -1250,11 +1250,11 @@ test( "validate on not keyup, only blur", function() { errors( 0 ); e.trigger( "blur" ).trigger( "focusout" ); errors( 1 ); -}); +} ); test( "validate on keyup and blur", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } var e = $( "#firstname" ), v = $( "#testForm1" ).validate(); @@ -1265,11 +1265,11 @@ test( "validate on keyup and blur", function() { errors( 0 ); e.trigger( "blur" ).trigger( "focusout" ); errors( 1 ); -}); +} ); test( "validate email on keyup and blur", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } var e = $( "#firstname" ), v = $( "#testForm1" ).validate(); @@ -1282,11 +1282,11 @@ test( "validate email on keyup and blur", function() { e.val( "aa" ); e.trigger( "keyup" ); errors( 0 ); -}); +} ); test( "don't revalidate the field when pressing special characters", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } function triggerEvent( element, keycode ) { @@ -1326,13 +1326,13 @@ test( "don't revalidate the field when pressing special characters", function() $.each( excludedKeys, function( key, keyCode ) { triggerEvent( e, keyCode ); errors( 1, key + " key" ); - }); + } ); // Normal keyup e.val( "aaaaa" ); e.trigger( "keyup" ); errors( 0, "Normal keyup" ); -}); +} ); test( "#1508: Validation fails to trigger when next field is already filled out", function() { // The next field is already filled out. @@ -1365,7 +1365,7 @@ test( "#1508: Validation fails to trigger when next field is already filled out" test( "validate checkbox on click", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } function trigger( element ) { element.click(); @@ -1373,26 +1373,26 @@ test( "validate checkbox on click", function() { element.valid(); } var e = $( "#check2" ), - v = $( "#form" ).validate({ + v = $( "#form" ).validate( { rules: { check2: "required" } - }); + } ); trigger( e ); errors( 0 ); trigger( e ); - equal( false, v.form() ); + equal( v.form(), false ); errors( 1 ); trigger( e ); errors( 0 ); trigger( e ); errors( 1 ); -}); +} ); test( "validate multiple checkbox on click", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } function trigger( element ) { element.click(); @@ -1401,26 +1401,26 @@ test( "validate multiple checkbox on click", function() { } var e1 = $( "#check1" ).attr( "checked", false ), e2 = $( "#check1b" ), - v = $( "#form" ).validate({ + v = $( "#form" ).validate( { rules: { check: { required: true, minlength: 2 } } - }); + } ); trigger( e1 ); trigger( e2 ); errors( 0 ); trigger( e2 ); - equal( false, v.form() ); + equal( v.form(), false ); errors( 1 ); trigger( e2 ); errors( 0 ); trigger( e2 ); errors( 1 ); -}); +} ); test( "correct checkbox receives the error", function() { function trigger( element ) { @@ -1432,24 +1432,24 @@ test( "correct checkbox receives the error", function() { v; $( "#check1b" ).attr( "checked", false ); - v = $( "#form" ).find( "[type=checkbox]" ).attr( "checked", false ).end().validate({ + v = $( "#form" ).find( "[type=checkbox]" ).attr( "checked", false ).end().validate( { rules: { check: { required: true, minlength: 2 } } - }); + } ); - equal( false, v.form()); + equal( v.form(), false); trigger( e1 ); - equal( false, v.form()); + equal( v.form(), false); 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 ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } function trigger( element ) { element.click(); @@ -1458,24 +1458,24 @@ test( "validate radio on click", function() { } var e1 = $( "#radio1" ), e2 = $( "#radio1a" ), - v = $( "#form" ).validate({ + v = $( "#form" ).validate( { rules: { radio1: "required" } - }); + } ); errors( 0 ); - equal( false, v.form() ); + equal( v.form(), false ); errors( 1 ); trigger( e2 ); errors( 0 ); trigger( e1 ); errors( 0 ); -}); +} ); test( "validate input with no type attribute, defaulting to text", function() { function errors( expected, message ) { - equal( expected, v.size(), message ); + equal( v.size(), expected, message ); } var v = $( "#testForm12" ).validate(), e = $( "#testForm12text" ); @@ -1486,38 +1486,38 @@ test( "validate input with no type attribute, defaulting to text", function() { e.val( "test" ); e.trigger( "keyup" ); errors( 0 ); -}); +} ); module( "ignore hidden" ); test( "ignore hidden elements", function() { var form = $( "#userForm" ), - validate = form.validate({ + validate = form.validate( { rules: { "username": "required" } - }); + } ); form.get( 0 ).reset(); 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() { var form = $( "#userForm" ), - validate = form.validate({ + validate = form.validate( { rules: { "username": "required" } - }); + } ); form.get( 0 ).reset(); $( "#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" ); -}); +} ); module( "configuration with attributes " ); @@ -1533,7 +1533,7 @@ test( "Specify error messages through data attributes", function() { label = $( "#dataMessages .error:not(input)" ); equal( label.text(), "You must enter a value here", "Correct error label" ); -}); +} ); test( "Updates pre-existing label if has error class", function() { var form = $( "#updateLabel" ), @@ -1550,8 +1550,8 @@ test( "Updates pre-existing label if has error class", function() { // label was updated equal( label.text(), input.attr( "data-msg-required" ) ); // new label wasn't created - equal( labelsBefore, labelsAfter ); -}); + equal( labelsAfter, labelsBefore ); +} ); test( "Min date set by attribute", function() { var form = $( "#rangesMinDateInvalid" ), @@ -1564,7 +1564,7 @@ test( "Min date set by attribute", function() { label = $( "#rangesMinDateInvalid .error:not(input)" ); equal( label.text(), "Please enter a value greater than or equal to 2012-12-21.", "Correct error label" ); -}); +} ); test( "Max date set by attribute", function() { var form = $( "#ranges" ), @@ -1577,7 +1577,7 @@ test( "Max date set by attribute", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value less than or equal to 2012-12-21.", "Correct error label" ); -}); +} ); test( "Min and Max date set by attributes greater", function() { var form = $( "#ranges" ), @@ -1590,7 +1590,7 @@ test( "Min and Max date set by attributes greater", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value less than or equal to 2013-01-21.", "Correct error label" ); -}); +} ); test( "Min and Max date set by attributes less", function() { var form = $( "#ranges" ), @@ -1603,7 +1603,7 @@ test( "Min and Max date set by attributes less", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value greater than or equal to 2012-11-21.", "Correct error label" ); -}); +} ); test( "Min date set by attribute valid", function() { var form = $( "#rangeMinDateValid" ), @@ -1616,7 +1616,7 @@ test( "Min date set by attribute valid", function() { label = $( "#rangeMinDateValid .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Max date set by attribute valid", function() { var form = $( "#ranges" ), @@ -1629,7 +1629,7 @@ test( "Max date set by attribute valid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Min and Max date set by attributes valid", function() { var form = $( "#ranges" ), @@ -1642,7 +1642,7 @@ test( "Min and Max date set by attributes valid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Min and Max strings set by attributes greater", function() { var form = $( "#ranges" ), @@ -1655,7 +1655,7 @@ test( "Min and Max strings set by attributes greater", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value less than or equal to 200.", "Correct error label" ); -}); +} ); test( "Min and Max strings set by attributes less", function() { var form = $( "#ranges" ), @@ -1668,7 +1668,7 @@ test( "Min and Max strings set by attributes less", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value greater than or equal to 200.", "Correct error label" ); -}); +} ); test( "Min and Max strings set by attributes valid", function() { var form = $( "#ranges" ), @@ -1681,7 +1681,7 @@ test( "Min and Max strings set by attributes valid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Max set by data-rule, valid", function() { var form = $( "#ranges" ), @@ -1694,22 +1694,22 @@ test( "Max set by data-rule, valid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "calling blur on ignored element", function() { var form = $( "#ignoredElements" ); - form.validate({ + form.validate( { ignore: ".ignore", submitHandler: $.noop, invalidHandler: function() { $( "#ss1" ).blur(); } - }); + } ); form.trigger( "submit" ); equal( form.valid(), false, "valid() should return false" ); -}); +} ); test( "Min and Max type absent set by attributes greater", function() { var form = $( "#ranges" ), @@ -1722,7 +1722,7 @@ test( "Min and Max type absent set by attributes greater", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value less than or equal to 200.", "Correct error label" ); -}); +} ); test( "Min and Max type absent set by attributes less", function() { var form = $( "#ranges" ), @@ -1735,7 +1735,7 @@ test( "Min and Max type absent set by attributes less", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value greater than or equal to 200.", "Correct error label" ); -}); +} ); test( "Min and Max type absent set by attributes valid", function() { var form = $( "#ranges" ), @@ -1748,7 +1748,7 @@ test( "Min and Max type absent set by attributes valid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Min and Max range set by attributes valid", function() { // @@ -1768,7 +1768,7 @@ test( "Min and Max range set by attributes valid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Min and Max number set by attributes valid", function() { var form = $( "#ranges" ), @@ -1781,7 +1781,7 @@ test( "Min and Max number set by attributes valid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Min and Max number set by attributes greater", function() { var form = $( "#ranges" ), @@ -1794,7 +1794,7 @@ test( "Min and Max number set by attributes greater", function() { label = $( "#ranges .error:not(input)" ); 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" ), @@ -1807,7 +1807,7 @@ test( "Min and Max number set by attributes less", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value greater than or equal to 50.", "Correct error label" ); -}); +} ); test( "Rules allowed to have a value of zero invalid", function() { var form = $( "#ranges" ), @@ -1820,7 +1820,7 @@ test( "Rules allowed to have a value of zero invalid", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "Please enter a value greater than or equal to 0.", "Correct error label" ); -}); +} ); test( "Rules allowed to have a value of zero valid equal", function() { var form = $( "#ranges" ), @@ -1833,7 +1833,7 @@ test( "Rules allowed to have a value of zero valid equal", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Rules allowed to have a value of zero valid greater", function() { var form = $( "#ranges" ), @@ -1846,7 +1846,7 @@ test( "Rules allowed to have a value of zero valid greater", function() { label = $( "#ranges .error:not(input)" ); equal( label.text(), "", "Correct error label" ); -}); +} ); test( "Validation triggered on radio and checkbox via click", function() { expect( 2 ); @@ -1857,7 +1857,7 @@ test( "Validation triggered on radio and checkbox via click", function() { form.validate(); // validate so we have errors - ok( !form.valid(), "Form invalid"); + ok( !form.valid(), "Form invalid" ); // simulate native click on first checkbox to trigger change-event $( "#radiocheckbox-0-1" ).simulate( "click" ); @@ -1867,7 +1867,7 @@ test( "Validation triggered on radio and checkbox via click", function() { // test if there is no error anymore ok( form.find( "input.error" ).length === 0, "Form valid" ); -}); +} ); test( "destroy()", function() { expect( 2 ); @@ -1879,4 +1879,4 @@ test( "destroy()", function() { validate.destroy(); strictEqual( $( form ).data( "validator" ), undefined ); -}); +} );