Skip to content

Commit c243e8e

Browse files
committed
Update testsuite to use equal and deepEqual. Fix tests that the fix for jquery-validation#219 (732f5ff) broke. The element method now returns true for dependency-mismatch, that's fine.
1 parent ccca8f6 commit c243e8e

File tree

4 files changed

+184
-184
lines changed

4 files changed

+184
-184
lines changed

test/messages.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test("predefined message not overwritten by addMethod(a, b, undefined)", functio
44
var message = "my custom message";
55
$.validator.messages.custom = message;
66
$.validator.addMethod("custom", function() {});
7-
same(message, $.validator.messages.custom);
7+
deepEqual(message, $.validator.messages.custom);
88
delete $.validator.messages.custom;
99
delete $.validator.methods.custom;
1010
});
@@ -26,13 +26,13 @@ test("group error messages", function() {
2626
}
2727
});
2828
ok( !form.valid() );
29-
equals( 1, form.find(".errorContainer *").length );
30-
equals( "Please enter a valid date.", form.find(".errorContainer label.error").text() );
29+
equal( 1, form.find(".errorContainer *").length );
30+
equal( "Please enter a valid date.", form.find(".errorContainer label.error").text() );
3131

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

3737
$("#toDate").val("12/04/2006");
3838
ok( form.valid() );
@@ -44,9 +44,9 @@ test("read messages from metadata", function() {
4444
form.validate();
4545
var e = $("#testEmail9")
4646
e.valid();
47-
equals( form.find("label").text(), "required" );
47+
equal( form.find("label").text(), "required" );
4848
e.val("bla").valid();
49-
equals( form.find("label").text(), "email" );
49+
equal( form.find("label").text(), "email" );
5050
});
5151

5252

test/methods.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ test("accept", function() {
354354

355355
var v = jQuery("#form").validate(),
356356
method = function(value, param) {
357-
return $.validator.methods.accept.call(v, value, $('#text1')[0], param)
358-
};
357+
return $.validator.methods.accept.call(v, value, $('#text1')[0], param);
358+
};
359359
ok( method( "picture.doc", "doc"), "Valid custom accept type" );
360360
ok( method( "picture.pdf", "doc|pdf"), "Valid custom accept type" );
361361
ok( method( "picture.pdf", "pdf|doc"), "Valid custom accept type" );
@@ -390,21 +390,21 @@ test("remote", function() {
390390
});
391391
$(document).ajaxStop(function() {
392392
$(document).unbind("ajaxStop");
393-
equals( 1, v.size(), "There must be one error" );
394-
equals( "Peter in use", v.errorList[0].message );
393+
equal( 1, v.size(), "There must be one error" );
394+
equal( "Peter in use", v.errorList[0].message );
395395

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

410410
test("remote, customized ajax options", function() {
@@ -418,8 +418,8 @@ test("remote, customized ajax options", function() {
418418
url: "users.php",
419419
type: "POST",
420420
beforeSend: function(request, settings) {
421-
same(settings.type, "POST");
422-
same(settings.data, "username=asdf&email=email.com");
421+
deepEqual(settings.type, "POST");
422+
deepEqual(settings.data, "username=asdf&email=email.com");
423423
},
424424
data: {
425425
email: function() {
@@ -460,15 +460,15 @@ test("remote extensions", function() {
460460
});
461461
$(document).ajaxStop(function() {
462462
$(document).unbind("ajaxStop");
463-
equals( 1, v.size(), "There must be one error" );
464-
equals( v.errorList[0].message, "asdf is already taken, please try something else" );
463+
equal( 1, v.size(), "There must be one error" );
464+
equal( v.errorList[0].message, "asdf is already taken, please try something else" );
465465
v.element(e);
466-
equals( v.errorList[0].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" );
466+
equal( v.errorList[0].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" );
467467
start();
468468
});
469-
ok( !v.element(e), "invalid element, nothing entered yet" );
469+
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
470470
e.val("asdf");
471-
ok( !v.element(e), "still invalid, because remote validation must block until it returns" );
471+
strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
472472
});
473473

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

547547
test('creditcardtypes, all', function() {

test/rules.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module("rules");
33
test("rules() - internal - input", function() {
44
var element = $('#firstname');
55
var v = $('#testForm1').validate();
6-
same( element.rules(), { required: true, minlength: 2 } );
6+
deepEqual( element.rules(), { required: true, minlength: 2 } );
77
});
88

99
test("rules(), ignore method:false", function() {
@@ -13,19 +13,19 @@ test("rules(), ignore method:false", function() {
1313
firstname: { required: false, minlength: 2 }
1414
}
1515
});
16-
same( element.rules(), { minlength: 2 } );
16+
deepEqual( element.rules(), { minlength: 2 } );
1717
});
1818

1919
test("rules() HTML5 required (no value)", function() {
2020
var element = $('#testForm11text1');
2121
var v = $('#testForm11').validate();
22-
same( element.rules(), { required: true } );
22+
deepEqual( element.rules(), { required: true } );
2323
});
2424

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

3131
test("rules() - external", function() {
@@ -35,7 +35,7 @@ test("rules() - external", function() {
3535
action: {date: true, min: 5}
3636
}
3737
});
38-
same( element.rules(), {date: true, min: 5} );
38+
deepEqual( element.rules(), {date: true, min: 5} );
3939
});
4040

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

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

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

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

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

106106
$("#subformRequired").validate({
107107
rules: {
108108
co_name: "required"
109109
}
110110
});
111111
$("#co_name").removeClass();
112-
equals( "required maxlength", flatRules("#co_name") );
112+
equal( "required maxlength", flatRules("#co_name") );
113113
jQuery.validator.autoCreateRanges = false;
114114
});
115115

@@ -119,13 +119,13 @@ test("rules(), evaluate dynamic parameters", function() {
119119
rules: {
120120
firstname: {
121121
min: function(element) {
122-
equals( $("#firstnamec")[0], element );
122+
equal( $("#firstnamec")[0], element );
123123
return 12;
124124
}
125125
}
126126
}
127127
});
128-
same( $("#firstnamec").rules(), {min:12});
128+
deepEqual( $("#firstnamec").rules(), {min:12});
129129
});
130130

131131
test("rules(), class and attribute combinations", function() {
@@ -145,16 +145,16 @@ test("rules(), class and attribute combinations", function() {
145145
}
146146
}
147147
});
148-
same( $("#v2-i1").rules(), { required: true });
149-
same( $("#v2-i2").rules(), { required: true, email: true });
150-
same( $("#v2-i3").rules(), { url: true });
151-
same( $("#v2-i4").rules(), { required: true, minlength: 2 });
152-
same( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" });
148+
deepEqual( $("#v2-i1").rules(), { required: true });
149+
deepEqual( $("#v2-i2").rules(), { required: true, email: true });
150+
deepEqual( $("#v2-i3").rules(), { url: true });
151+
deepEqual( $("#v2-i4").rules(), { required: true, minlength: 2 });
152+
deepEqual( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" });
153153
jQuery.validator.autoCreateRanges = true;
154-
same( $("#v2-i5").rules(), { required: true, customMethod1: "123", rangelength: [2, 5] });
155-
same( $("#v2-i6").rules(), { required: true, customMethod2: true, rangelength: [2, 5] });
154+
deepEqual( $("#v2-i5").rules(), { required: true, customMethod1: "123", rangelength: [2, 5] });
155+
deepEqual( $("#v2-i6").rules(), { required: true, customMethod2: true, rangelength: [2, 5] });
156156
jQuery.validator.autoCreateRanges = false;
157-
same( $("#v2-i7").rules(), { required: true, minlength: 2, customMethod: true });
157+
deepEqual( $("#v2-i7").rules(), { required: true, minlength: 2, customMethod: true });
158158

159159
delete $.validator.methods.customMethod1;
160160
delete $.validator.messages.customMethod1;
@@ -185,12 +185,12 @@ test("rules(), dependency checks", function() {
185185
});
186186

187187
var rules = $("#firstnamec").rules();
188-
equals( 0, v.objectLength(rules) );
188+
equal( 0, v.objectLength(rules) );
189189

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

193-
same( $("#lastnamec").rules(), {max:12, email:true});
193+
deepEqual( $("#lastnamec").rules(), {max:12, email:true});
194194
});
195195

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

204204
$("#v2-i5").addClass("required").attr(removedAttrs);
205-
same( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" });
205+
deepEqual( $("#v2-i5").rules(), { required: true, minlength: 2, maxlength: 5, customMethod1: "123" });
206206

207207
$("#v2-i5").addClass("email").attr({min: 5});
208-
same( $("#v2-i5").rules(), { required: true, email: true, minlength: 2, maxlength: 5, min: 5, customMethod1: "123" });
208+
deepEqual( $("#v2-i5").rules(), { required: true, email: true, minlength: 2, maxlength: 5, min: 5, customMethod1: "123" });
209209

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

213213
delete $.validator.methods.customMethod1;
214214
delete $.validator.messages.customMethod1;
@@ -220,35 +220,35 @@ test("rules(), add and remove static rules", function() {
220220
firstname: "required date"
221221
}
222222
});
223-
same( $("#firstnamec").rules(), { required: true, date: true } );
223+
deepEqual( $("#firstnamec").rules(), { required: true, date: true } );
224224

225225
$("#firstnamec").rules("remove", "date")
226-
same( $("#firstnamec").rules(), { required: true } );
226+
deepEqual( $("#firstnamec").rules(), { required: true } );
227227
$("#firstnamec").rules("add", "email");
228-
same( $("#firstnamec").rules(), { required: true, email: true } );
228+
deepEqual( $("#firstnamec").rules(), { required: true, email: true } );
229229

230230
$("#firstnamec").rules("remove", "required");
231-
same( $("#firstnamec").rules(), { email: true } );
231+
deepEqual( $("#firstnamec").rules(), { email: true } );
232232

233-
same( $("#firstnamec").rules("remove"), { email: true } );
234-
same( $("#firstnamec").rules(), { } );
233+
deepEqual( $("#firstnamec").rules("remove"), { email: true } );
234+
deepEqual( $("#firstnamec").rules(), { } );
235235

236236
$("#firstnamec").rules("add", "required email");
237-
same( $("#firstnamec").rules(), { required: true, email: true } );
237+
deepEqual( $("#firstnamec").rules(), { required: true, email: true } );
238238

239239

240-
same( $("#lastnamec").rules(), {} );
240+
deepEqual( $("#lastnamec").rules(), {} );
241241
$("#lastnamec").rules("add", "required");
242242
$("#lastnamec").rules("add", {
243243
minlength: 2
244244
});
245-
same( $("#lastnamec").rules(), { required: true, minlength: 2 } );
245+
deepEqual( $("#lastnamec").rules(), { required: true, minlength: 2 } );
246246

247247

248248
var removedRules = $("#lastnamec").rules("remove", "required email");
249-
same( $("#lastnamec").rules(), { minlength: 2 } );
249+
deepEqual( $("#lastnamec").rules(), { minlength: 2 } );
250250
$("#lastnamec").rules("add", removedRules);
251-
same( $("#lastnamec").rules(), { required: true, minlength: 2 } );
251+
deepEqual( $("#lastnamec").rules(), { required: true, minlength: 2 } );
252252
});
253253

254254
test("rules(), add messages", function() {
@@ -260,7 +260,7 @@ test("rules(), add messages", function() {
260260
});
261261
$("#testForm1clean").valid();
262262
$("#firstnamec").valid();
263-
same( v.settings.messages.firstname, undefined );
263+
deepEqual( v.settings.messages.firstname, undefined );
264264

265265
$("#firstnamec").rules("add", {
266266
messages: {
@@ -269,5 +269,5 @@ test("rules(), add messages", function() {
269269
});
270270

271271
$("#firstnamec").valid();
272-
same( v.errorList[0] && v.errorList[0].message, "required" );
272+
deepEqual( v.errorList[0] && v.errorList[0].message, "required" );
273273
});

0 commit comments

Comments
 (0)