Skip to content

Commit 59f5adb

Browse files
committedFeb 23, 2013
No ticket: Revise unit tests in anticipation of Sizzle-free builds
1 parent 9338a69 commit 59f5adb

11 files changed

+208
-161
lines changed
 

‎test/data/testrunner.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ var Globals = (function() {
172172
// instead of asserting every time a test has leaked sometime in the past
173173
var oldCacheLength = 0,
174174
oldFragmentsLength = 0,
175-
oldTimersLength = 0,
176175
oldActive = 0,
177176

178177
expectedDataKeys = {},
179178

179+
splice = [].splice,
180180
reset = QUnit.reset,
181181
ajaxSettings = jQuery.ajaxSettings;
182182

@@ -286,6 +286,20 @@ var Globals = (function() {
286286
// Reset data register
287287
expectedDataKeys = {};
288288

289+
// Check for (and clean up, if possible) incomplete animations/requests/etc.
290+
if ( jQuery.timers && jQuery.timers.length !== 0 ) {
291+
equal( jQuery.timers.length, 0, "No timers are still running" );
292+
splice.call( jQuery.timers, 0, jQuery.timers.length );
293+
jQuery.fx.stop();
294+
}
295+
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
296+
equal( jQuery.active, oldActive, "No AJAX requests are still active" );
297+
if ( ajaxTest.abort ) {
298+
ajaxTest.abort("active requests");
299+
}
300+
oldActive = jQuery.active;
301+
}
302+
289303
// Allow QUnit.reset to clean up any attached elements before checking for leaks
290304
QUnit.reset();
291305

@@ -309,17 +323,6 @@ var Globals = (function() {
309323
equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" );
310324
oldFragmentsLength = fragmentsLength;
311325
}
312-
if ( jQuery.timers && jQuery.timers.length !== oldTimersLength ) {
313-
equal( jQuery.timers.length, oldTimersLength, "No timers are still running" );
314-
oldTimersLength = jQuery.timers.length;
315-
}
316-
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
317-
equal( jQuery.active, 0, "No AJAX requests are still active" );
318-
if ( ajaxTest.abort ) {
319-
ajaxTest.abort("active requests");
320-
}
321-
oldActive = jQuery.active;
322-
}
323326
};
324327

325328
QUnit.done(function() {

‎test/unit/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ test( "attr(String, Object)", function() {
376376
});
377377

378378
var table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"),
379-
td = table.find("td:first");
379+
td = table.find("td").eq(0);
380380
td.attr( "rowspan", "2" );
381381
equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" );
382382
td.attr( "colspan", "2" );

‎test/unit/core.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ test("jQuery()", function() {
2828

2929
var elem, i,
3030
obj = jQuery("div"),
31-
main = jQuery("#qunit-fixture"),
3231
code = jQuery("<code/>"),
3332
img = jQuery("<img/>"),
3433
div = jQuery("<div/><hr/><code/><b/>"),
3534
exec = false,
3635
lng = "",
37-
expected = 21,
36+
expected = 20,
3837
attrObj = {
3938
"text": "test",
4039
"class": "test2",
@@ -78,8 +77,6 @@ test("jQuery()", function() {
7877
// can actually yield more than one, when iframes are included, the window is an array as well
7978
equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
8079

81-
deepEqual( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
82-
8380
/*
8481
// disabled since this test was doing nothing. i tried to fix it but i'm not sure
8582
// what the expected behavior should even be. FF returns "\n" for the text node
@@ -154,6 +151,13 @@ test("jQuery()", function() {
154151
}
155152
});
156153

154+
test("jQuery(selector, context)", function() {
155+
expect(3);
156+
deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
157+
deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
158+
deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
159+
});
160+
157161
test( "selector state", function() {
158162
expect( 18 );
159163

‎test/unit/css.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,12 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct
616616
expect(4);
617617

618618
var $checkedtest = jQuery("#checkedtest");
619-
// IE6 was clearing "checked" in jQuery.css(elem, "height");
620619
jQuery.css($checkedtest[0], "height");
621-
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
622-
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
623-
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
624-
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
620+
621+
ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
622+
ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
623+
ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
624+
ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
625625
});
626626

627627
test("internal ref to elem.runtimeStyle (bug #7608)", function () {

‎test/unit/dimensions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {
296296

297297
test( "table dimensions", 2, function() {
298298
var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"),
299-
tdElem = table.find("tr:eq(0) td:eq(0)"),
300-
colElem = table.find("col:eq(1)").width( 300 );
299+
tdElem = table.find("td").first(),
300+
colElem = table.find("col").first().width( 300 );
301301

302302
table.find("td").css({ "margin": 0, "padding": 0 });
303303

‎test/unit/effects.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
if ( jQuery.fx ) {
1+
(function() {
22

3-
module("effects", { teardown: moduleTeardown });
3+
// Can't test what ain't there
4+
if ( !jQuery.fx ) {
5+
return;
6+
}
7+
8+
var off = jQuery.fx.off;
9+
10+
module("effects", {
11+
teardown: function() {
12+
jQuery.fx.off = off;
13+
return moduleTeardown.apply( this, arguments );
14+
}
15+
});
416

517
test("sanity check", function() {
618
expect(1);
@@ -1055,12 +1067,11 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()
10551067
stop();
10561068

10571069
var $checkedtest = jQuery("#checkedtest");
1058-
// IE6 was clearing "checked" in jQuery(elem).show("fast");
10591070
$checkedtest.hide().show("fast", function() {
1060-
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
1061-
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
1062-
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
1063-
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
1071+
ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
1072+
ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
1073+
ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
1074+
ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
10641075
start();
10651076
});
10661077
});
@@ -1485,7 +1496,7 @@ test( "animate should set display for disconnected nodes", function() {
14851496
});
14861497
});
14871498

1488-
asyncTest("Animation callback should not show animated element as animated (#7157)", 1, function() {
1499+
asyncTest("Animation callback should not show animated element as :animated (#7157)", 1, function() {
14891500
var foo = jQuery( "#foo" );
14901501

14911502
foo.animate({
@@ -2014,4 +2025,4 @@ test( ".finish() calls finish of custom queue functions", function() {
20142025
div.remove();
20152026
});
20162027

2017-
} // if ( jQuery.fx )
2028+
})();

‎test/unit/event.js

+35-32
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,10 @@ test("bind/one/unbind(Object)", function(){
310310
test("on/off(Object), delegate/undelegate(String, Object)", function() {
311311
expect(6);
312312

313-
var clickCounter = 0, mouseoverCounter = 0,
314-
$p = jQuery("#firstp"), $a = $p.find("a:first");
313+
var clickCounter = 0,
314+
mouseoverCounter = 0,
315+
$p = jQuery("#firstp"),
316+
$a = $p.find("a").eq(0);
315317

316318
var events = {
317319
"click": function( event ) {
@@ -326,7 +328,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
326328
$a.trigger("click").trigger("mouseover");
327329
}
328330

329-
jQuery( document ).on( events, "#firstp a:first" );
331+
jQuery( document ).on( events, "#firstp a" );
330332
$p.delegate( "a", events, 2 );
331333

332334
trigger();
@@ -339,7 +341,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
339341
equal( clickCounter, 4, "undelegate" );
340342
equal( mouseoverCounter, 4, "undelegate" );
341343

342-
jQuery( document ).off( events, "#firstp a:first" );
344+
jQuery( document ).off( events, "#firstp a" );
343345

344346
trigger();
345347
equal( clickCounter, 4, "off" );
@@ -349,19 +351,21 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
349351
test("on/delegate immediate propagation", function() {
350352
expect(2);
351353

352-
var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
354+
var lastClick,
355+
$p = jQuery("#firstp"),
356+
$a = $p.find("a").eq(0);
353357

354358
lastClick = "";
355-
jQuery( document ).on( "click", "#firstp a:first", function(e) {
359+
jQuery( document ).on( "click", "#firstp a", function(e) {
356360
lastClick = "click1";
357361
e.stopImmediatePropagation();
358362
});
359-
jQuery( document ).on( "click", "#firstp a:first", function(e) {
363+
jQuery( document ).on( "click", "#firstp a", function(e) {
360364
lastClick = "click2";
361365
});
362366
$a.trigger( "click" );
363367
equal( lastClick, "click1", "on stopImmediatePropagation" );
364-
jQuery( document ).off( "click", "#firstp a:first" );
368+
jQuery( document ).off( "click", "#firstp a" );
365369

366370
lastClick = "";
367371
$p.delegate( "a", "click", function(e) {
@@ -490,7 +494,7 @@ test("bind(), namespaced events, cloned events", 18, function() {
490494

491495
// Make sure events stick with appendTo'd elements (which are cloned) #2027
492496
jQuery("<a href='#fail' class='test'>test</a>").on( "click", function(){ return false; }).appendTo("#qunit-fixture");
493-
ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
497+
ok( jQuery("a.test").eq(0).triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
494498
});
495499

496500
test("bind(), multi-namespaced events", function() {
@@ -996,7 +1000,7 @@ test("trigger(type, [data], [fn])", function() {
9961000

9971001
var pass = true, elem2;
9981002
try {
999-
elem2 = jQuery("#form input:first");
1003+
elem2 = jQuery("#form input").eq(0);
10001004
elem2.get(0).style.display = "none";
10011005
elem2.trigger("focus");
10021006
} catch(e) {
@@ -1006,7 +1010,7 @@ test("trigger(type, [data], [fn])", function() {
10061010

10071011
pass = true;
10081012
try {
1009-
jQuery("#qunit-fixture table:first").bind("test:test", function(){}).trigger("test:test");
1013+
jQuery("#qunit-fixture table").eq(0).bind("test:test", function(){}).trigger("test:test");
10101014
} catch (e) {
10111015
pass = false;
10121016
}
@@ -1717,10 +1721,24 @@ test("jQuery.off using dispatched jQuery.Event", function() {
17171721

17181722
test( "delegated event with delegateTarget-relative selector", function() {
17191723
expect(3);
1720-
var markup = jQuery("<ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul>").appendTo("#qunit-fixture");
1724+
var markup = jQuery("<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>").appendTo("#qunit-fixture");
1725+
1726+
// Non-positional selector (#12383)
1727+
markup.find("#ul0")
1728+
.on( "click", "div li a", function() {
1729+
ok( false, "div is ABOVE the delegation point!" );
1730+
})
1731+
.on( "click", "ul a", function() {
1732+
ok( false, "ul IS the delegation point!" );
1733+
})
1734+
.on( "click", "li.test a", function() {
1735+
ok( true, "li.test is below the delegation point." );
1736+
})
1737+
.find("#a0_0").trigger("click").end()
1738+
.off("click");
17211739

17221740
// Positional selector (#11315)
1723-
markup
1741+
markup.find("ul").eq(0)
17241742
.on( "click", ">li>a", function() {
17251743
ok( this.id === "a0", "child li was clicked" );
17261744
})
@@ -1732,21 +1750,6 @@ test( "delegated event with delegateTarget-relative selector", function() {
17321750
.find("a").trigger("click").end()
17331751
.find("#ul0").off();
17341752

1735-
// Non-positional selector (#12383)
1736-
markup = markup.wrap("<div />").parent();
1737-
markup
1738-
.find("#ul0")
1739-
.on( "click", "div li a", function() {
1740-
ok( false, "div is ABOVE the delegation point!" );
1741-
})
1742-
.on( "click", "ul a", function() {
1743-
ok( false, "ul is the delegation point!" );
1744-
})
1745-
.on( "click", "li.test a", function() {
1746-
ok( true, "li.test is below the delegation point." );
1747-
})
1748-
.find("#a0_0").trigger("click");
1749-
17501753
markup.remove();
17511754
});
17521755

@@ -2558,12 +2561,12 @@ test( "make sure events cloned correctly", 18, function() {
25582561

25592562
clone = fixture.clone( true );
25602563

2561-
clone.find("p:first").trigger( "click", true ); // 3 events should fire
2564+
clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
25622565
clone.find("#check1").trigger( "change", true ); // 3 events should fire
25632566
clone.remove();
25642567

25652568
clone = fixture.clone( true, true );
2566-
clone.find("p:first").trigger( "click", true ); // 3 events should fire
2569+
clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
25672570
clone.find("#check1").trigger( "change", true ); // 3 events should fire
25682571

25692572
fixture.off();
@@ -2573,11 +2576,11 @@ test( "make sure events cloned correctly", 18, function() {
25732576
p.trigger("click"); // 0 should be fired
25742577
checkbox.trigger("change"); // 0 should be fired
25752578

2576-
clone.find("p:first").trigger( "click", true ); // 3 events should fire
2579+
clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
25772580
clone.find("#check1").trigger( "change", true ); // 3 events should fire
25782581
clone.remove();
25792582

2580-
clone.find("p:first").trigger("click"); // 0 should be fired
2583+
clone.find("p").eq(0).trigger("click"); // 0 should be fired
25812584
clone.find("#check1").trigger("change"); // 0 events should fire
25822585
});
25832586

0 commit comments

Comments
 (0)