Skip to content

Commit

Permalink
Update testsuite to use equal and deepEqual. Fix tests that the fix for
Browse files Browse the repository at this point in the history
jquery-validation#219 (732f5ff) broke. The element method now returns true for dependency-mismatch, that's fine.
  • Loading branch information
jzaefferer committed Feb 24, 2012
1 parent ccca8f6 commit c243e8e
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 184 deletions.
12 changes: 6 additions & 6 deletions test/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test("predefined message not overwritten by addMethod(a, b, undefined)", functio
var message = "my custom message";
$.validator.messages.custom = message;
$.validator.addMethod("custom", function() {});
same(message, $.validator.messages.custom);
deepEqual(message, $.validator.messages.custom);
delete $.validator.messages.custom;
delete $.validator.methods.custom;
});
Expand All @@ -26,13 +26,13 @@ test("group error messages", function() {
}
});
ok( !form.valid() );
equals( 1, form.find(".errorContainer *").length );
equals( "Please enter a valid date.", form.find(".errorContainer label.error").text() );
equal( 1, form.find(".errorContainer *").length );
equal( "Please enter a valid date.", form.find(".errorContainer label.error").text() );

$("#fromDate").val("12/03/2006");
$("#toDate").val("12/01/2006");
ok( !form.valid() );
equals( "Please specify a correct date range.", form.find(".errorContainer label.error").text() );
equal( "Please specify a correct date range.", form.find(".errorContainer label.error").text() );

$("#toDate").val("12/04/2006");
ok( form.valid() );
Expand All @@ -44,9 +44,9 @@ test("read messages from metadata", function() {
form.validate();
var e = $("#testEmail9")
e.valid();
equals( form.find("label").text(), "required" );
equal( form.find("label").text(), "required" );
e.val("bla").valid();
equals( form.find("label").text(), "email" );
equal( form.find("label").text(), "email" );
});


Expand Down
34 changes: 17 additions & 17 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ test("accept", function() {

var v = jQuery("#form").validate(),
method = function(value, param) {
return $.validator.methods.accept.call(v, value, $('#text1')[0], param)
};
return $.validator.methods.accept.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" );
Expand Down Expand Up @@ -390,21 +390,21 @@ test("remote", function() {
});
$(document).ajaxStop(function() {
$(document).unbind("ajaxStop");
equals( 1, v.size(), "There must be one error" );
equals( "Peter in use", v.errorList[0].message );
equal( 1, v.size(), "There must be one error" );
equal( "Peter in use", v.errorList[0].message );

$(document).ajaxStop(function() {
$(document).unbind("ajaxStop");
equals( 1, v.size(), "There must be one error" );
equals( "Peter2 in use", v.errorList[0].message );
equal( 1, v.size(), "There must be one error" );
equal( "Peter2 in use", v.errorList[0].message );
start();
});
e.val("Peter2");
ok( !v.element(e), "new value, new request" );
strictEqual( v.element(e), true, "new value, new request; dependency-mismatch considered as valid though" );
});
ok( !v.element(e), "invalid element, nothing entered yet" );
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
e.val("Peter");
ok( !v.element(e), "still invalid, because remote validation must block until it returns" );
strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
});

test("remote, customized ajax options", function() {
Expand All @@ -418,8 +418,8 @@ test("remote, customized ajax options", function() {
url: "users.php",
type: "POST",
beforeSend: function(request, settings) {
same(settings.type, "POST");
same(settings.data, "username=asdf&email=email.com");
deepEqual(settings.type, "POST");
deepEqual(settings.data, "username=asdf&email=email.com");
},
data: {
email: function() {
Expand Down Expand Up @@ -460,15 +460,15 @@ test("remote extensions", function() {
});
$(document).ajaxStop(function() {
$(document).unbind("ajaxStop");
equals( 1, v.size(), "There must be one error" );
equals( v.errorList[0].message, "asdf is already taken, please try something else" );
equal( 1, v.size(), "There must be one error" );
equal( v.errorList[0].message, "asdf is already taken, please try something else" );
v.element(e);
equals( 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", "message doesn't change on revalidation" );
start();
});
ok( !v.element(e), "invalid element, nothing entered yet" );
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
e.val("asdf");
ok( !v.element(e), "still invalid, because remote validation must block until it returns" );
strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
});

module("additional methods");
Expand Down Expand Up @@ -541,7 +541,7 @@ test("pattern", function() {
function testCardTypeByNumber(number, cardname, expected) {
$("#cardnumber").val(number);
var actual = $("#ccform").valid();
equals(actual, expected, $.format("Expect card number {0} to validate to {1}, actually validated to ", number, expected));
equal(actual, expected, $.format("Expect card number {0} to validate to {1}, actually validated to ", number, expected));
}

test('creditcardtypes, all', function() {
Expand Down
86 changes: 43 additions & 43 deletions test/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module("rules");
test("rules() - internal - input", function() {
var element = $('#firstname');
var v = $('#testForm1').validate();
same( element.rules(), { required: true, minlength: 2 } );
deepEqual( element.rules(), { required: true, minlength: 2 } );
});

test("rules(), ignore method:false", function() {
Expand All @@ -13,19 +13,19 @@ test("rules(), ignore method:false", function() {
firstname: { required: false, minlength: 2 }
}
});
same( element.rules(), { minlength: 2 } );
deepEqual( element.rules(), { minlength: 2 } );
});

test("rules() HTML5 required (no value)", function() {
var element = $('#testForm11text1');
var v = $('#testForm11').validate();
same( element.rules(), { required: true } );
deepEqual( element.rules(), { required: true } );
});

test("rules() - internal - select", function() {
var element = $('#meal');
var v = $('#testForm3').validate();
same( element.rules(), {required: true} );
deepEqual( element.rules(), {required: true} );
});

test("rules() - external", function() {
Expand All @@ -35,7 +35,7 @@ test("rules() - external", function() {
action: {date: true, min: 5}
}
});
same( element.rules(), {date: true, min: 5} );
deepEqual( element.rules(), {date: true, min: 5} );
});

test("rules() - external - complete form", function() {
Expand All @@ -62,7 +62,7 @@ test("rules() - external - complete form", function() {
test("rules() - internal - input", function() {
var element = $('#form8input');
var v = $('#testForm8').validate();
same( element.rules(), {required: true, number: true, rangelength: [2, 8]});
deepEqual( element.rules(), {required: true, number: true, rangelength: [2, 8]});
});

test("rules(), merge min/max to range, minlength/maxlength to rangelength", function() {
Expand All @@ -79,9 +79,9 @@ test("rules(), merge min/max to range, minlength/maxlength to rangelength", func
}
}
});
same( $("#firstnamec").rules(), {range: [5, 12]});
deepEqual( $("#firstnamec").rules(), {range: [5, 12]});

same( $("#lastnamec").rules(), {rangelength: [2, 8]} );
deepEqual( $("#lastnamec").rules(), {rangelength: [2, 8]} );
jQuery.validator.autoCreateRanges = false;
});

Expand All @@ -94,22 +94,22 @@ test("rules(), gurantee that required is at front", function() {
jQuery.each($(element).rules(), function(key, value) { result.push(key) });
return result.join(" ");
}
equals( "required minlength", flatRules("#firstname") );
equals( "required maxlength minlength", flatRules("#v2-i6") );
equals( "required maxlength", flatRules("#co_name") );
equal( "required minlength", flatRules("#firstname") );
equal( "required maxlength minlength", flatRules("#v2-i6") );
equal( "required maxlength", flatRules("#co_name") );

QUnit.reset();
jQuery.validator.autoCreateRanges = true;
v = $("#v2").validate();
equals( "required rangelength", flatRules("#v2-i6") );
equal( "required rangelength", flatRules("#v2-i6") );

$("#subformRequired").validate({
rules: {
co_name: "required"
}
});
$("#co_name").removeClass();
equals( "required maxlength", flatRules("#co_name") );
equal( "required maxlength", flatRules("#co_name") );
jQuery.validator.autoCreateRanges = false;
});

Expand All @@ -119,13 +119,13 @@ test("rules(), evaluate dynamic parameters", function() {
rules: {
firstname: {
min: function(element) {
equals( $("#firstnamec")[0], element );
equal( $("#firstnamec")[0], element );
return 12;
}
}
}
});
same( $("#firstnamec").rules(), {min:12});
deepEqual( $("#firstnamec").rules(), {min:12});
});

test("rules(), class and attribute combinations", function() {
Expand All @@ -145,16 +145,16 @@ test("rules(), class and attribute combinations", function() {
}
}
});
same( $("#v2-i1").rules(), { required: true });
same( $("#v2-i2").rules(), { required: true, email: true });
same( $("#v2-i3").rules(), { url: true });
same( $("#v2-i4").rules(), { required: true, minlength: 2 });
same( $("#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;
same( $("#v2-i5").rules(), { required: true, customMethod1: "123", rangelength: [2, 5] });
same( $("#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;
same( $("#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;
Expand Down Expand Up @@ -185,12 +185,12 @@ test("rules(), dependency checks", function() {
});

var rules = $("#firstnamec").rules();
equals( 0, v.objectLength(rules) );
equal( 0, v.objectLength(rules) );

$("#firstnamec").val('ab');
same( $("#firstnamec").rules(), {min:5});
deepEqual( $("#firstnamec").rules(), {min:5});

same( $("#lastnamec").rules(), {max:12, email:true});
deepEqual( $("#lastnamec").rules(), {max:12, email:true});
});

test("rules(), add and remove", function() {
Expand All @@ -199,16 +199,16 @@ test("rules(), add and remove", function() {
}, "");
$("#v2").validate();
var removedAttrs = $("#v2-i5").removeClass("required").removeAttrs("minlength maxlength");
same( $("#v2-i5").rules(), { customMethod1: "123" });
deepEqual( $("#v2-i5").rules(), { customMethod1: "123" });

$("#v2-i5").addClass("required").attr(removedAttrs);
same( $("#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});
same( $("#v2-i5").rules(), { required: true, email: true, minlength: 2, maxlength: 5, min: 5, customMethod1: "123" });
deepEqual( $("#v2-i5").rules(), { required: true, email: true, minlength: 2, maxlength: 5, min: 5, customMethod1: "123" });

$("#v2-i5").removeClass("required email").removeAttrs("minlength maxlength customMethod1 min");
same( $("#v2-i5").rules(), {});
deepEqual( $("#v2-i5").rules(), {});

delete $.validator.methods.customMethod1;
delete $.validator.messages.customMethod1;
Expand All @@ -220,35 +220,35 @@ test("rules(), add and remove static rules", function() {
firstname: "required date"
}
});
same( $("#firstnamec").rules(), { required: true, date: true } );
deepEqual( $("#firstnamec").rules(), { required: true, date: true } );

$("#firstnamec").rules("remove", "date")
same( $("#firstnamec").rules(), { required: true } );
deepEqual( $("#firstnamec").rules(), { required: true } );
$("#firstnamec").rules("add", "email");
same( $("#firstnamec").rules(), { required: true, email: true } );
deepEqual( $("#firstnamec").rules(), { required: true, email: true } );

$("#firstnamec").rules("remove", "required");
same( $("#firstnamec").rules(), { email: true } );
deepEqual( $("#firstnamec").rules(), { email: true } );

same( $("#firstnamec").rules("remove"), { email: true } );
same( $("#firstnamec").rules(), { } );
deepEqual( $("#firstnamec").rules("remove"), { email: true } );
deepEqual( $("#firstnamec").rules(), { } );

$("#firstnamec").rules("add", "required email");
same( $("#firstnamec").rules(), { required: true, email: true } );
deepEqual( $("#firstnamec").rules(), { required: true, email: true } );


same( $("#lastnamec").rules(), {} );
deepEqual( $("#lastnamec").rules(), {} );
$("#lastnamec").rules("add", "required");
$("#lastnamec").rules("add", {
minlength: 2
});
same( $("#lastnamec").rules(), { required: true, minlength: 2 } );
deepEqual( $("#lastnamec").rules(), { required: true, minlength: 2 } );


var removedRules = $("#lastnamec").rules("remove", "required email");
same( $("#lastnamec").rules(), { minlength: 2 } );
deepEqual( $("#lastnamec").rules(), { minlength: 2 } );
$("#lastnamec").rules("add", removedRules);
same( $("#lastnamec").rules(), { required: true, minlength: 2 } );
deepEqual( $("#lastnamec").rules(), { required: true, minlength: 2 } );
});

test("rules(), add messages", function() {
Expand All @@ -260,7 +260,7 @@ test("rules(), add messages", function() {
});
$("#testForm1clean").valid();
$("#firstnamec").valid();
same( v.settings.messages.firstname, undefined );
deepEqual( v.settings.messages.firstname, undefined );

$("#firstnamec").rules("add", {
messages: {
Expand All @@ -269,5 +269,5 @@ test("rules(), add messages", function() {
});

$("#firstnamec").valid();
same( v.errorList[0] && v.errorList[0].message, "required" );
deepEqual( v.errorList[0] && v.errorList[0].message, "required" );
});
Loading

0 comments on commit c243e8e

Please sign in to comment.