Skip to content
Permalink
Browse files

No ticket: Revise unit tests in anticipation of Sizzle-free builds

  • Loading branch information...
gibson042 committed Feb 19, 2013
1 parent 9338a69 commit 59f5adb622dd6bc3419bbaa9cc2d4acd7a0b08b9
@@ -172,11 +172,11 @@ var Globals = (function() {
// instead of asserting every time a test has leaked sometime in the past
var oldCacheLength = 0,
oldFragmentsLength = 0,
oldTimersLength = 0,
oldActive = 0,

expectedDataKeys = {},

splice = [].splice,
reset = QUnit.reset,
ajaxSettings = jQuery.ajaxSettings;

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

// Check for (and clean up, if possible) incomplete animations/requests/etc.
if ( jQuery.timers && jQuery.timers.length !== 0 ) {
equal( jQuery.timers.length, 0, "No timers are still running" );
splice.call( jQuery.timers, 0, jQuery.timers.length );
jQuery.fx.stop();
}
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
equal( jQuery.active, oldActive, "No AJAX requests are still active" );
if ( ajaxTest.abort ) {
ajaxTest.abort("active requests");
}
oldActive = jQuery.active;
}

// Allow QUnit.reset to clean up any attached elements before checking for leaks
QUnit.reset();

@@ -309,17 +323,6 @@ var Globals = (function() {
equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" );
oldFragmentsLength = fragmentsLength;
}
if ( jQuery.timers && jQuery.timers.length !== oldTimersLength ) {
equal( jQuery.timers.length, oldTimersLength, "No timers are still running" );
oldTimersLength = jQuery.timers.length;
}
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
equal( jQuery.active, 0, "No AJAX requests are still active" );
if ( ajaxTest.abort ) {
ajaxTest.abort("active requests");
}
oldActive = jQuery.active;
}
};

QUnit.done(function() {
@@ -376,7 +376,7 @@ test( "attr(String, Object)", function() {
});

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>"),
td = table.find("td:first");
td = table.find("td").eq(0);
td.attr( "rowspan", "2" );
equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" );
td.attr( "colspan", "2" );
@@ -28,13 +28,12 @@ test("jQuery()", function() {

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

deepEqual( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );

/*
// disabled since this test was doing nothing. i tried to fix it but i'm not sure
// what the expected behavior should even be. FF returns "\n" for the text node
@@ -154,6 +151,13 @@ test("jQuery()", function() {
}
});

test("jQuery(selector, context)", function() {
expect(3);
deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
});

test( "selector state", function() {
expect( 18 );

@@ -616,12 +616,12 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct
expect(4);

var $checkedtest = jQuery("#checkedtest");
// IE6 was clearing "checked" in jQuery.css(elem, "height");
jQuery.css($checkedtest[0], "height");
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );

ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
});

test("internal ref to elem.runtimeStyle (bug #7608)", function () {
@@ -296,8 +296,8 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {

test( "table dimensions", 2, function() {
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"),
tdElem = table.find("tr:eq(0) td:eq(0)"),
colElem = table.find("col:eq(1)").width( 300 );
tdElem = table.find("td").first(),
colElem = table.find("col").first().width( 300 );

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

@@ -1,6 +1,18 @@
if ( jQuery.fx ) {
(function() {

module("effects", { teardown: moduleTeardown });
// Can't test what ain't there
if ( !jQuery.fx ) {
return;
}

var off = jQuery.fx.off;

module("effects", {
teardown: function() {
jQuery.fx.off = off;
return moduleTeardown.apply( this, arguments );
}
});

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

var $checkedtest = jQuery("#checkedtest");
// IE6 was clearing "checked" in jQuery(elem).show("fast");
$checkedtest.hide().show("fast", function() {
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
start();
});
});
@@ -1485,7 +1496,7 @@ test( "animate should set display for disconnected nodes", function() {
});
});

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

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

} // if ( jQuery.fx )
})();
@@ -310,8 +310,10 @@ test("bind/one/unbind(Object)", function(){
test("on/off(Object), delegate/undelegate(String, Object)", function() {
expect(6);

var clickCounter = 0, mouseoverCounter = 0,
$p = jQuery("#firstp"), $a = $p.find("a:first");
var clickCounter = 0,
mouseoverCounter = 0,
$p = jQuery("#firstp"),
$a = $p.find("a").eq(0);

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

jQuery( document ).on( events, "#firstp a:first" );
jQuery( document ).on( events, "#firstp a" );
$p.delegate( "a", events, 2 );

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

jQuery( document ).off( events, "#firstp a:first" );
jQuery( document ).off( events, "#firstp a" );

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

var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
var lastClick,
$p = jQuery("#firstp"),
$a = $p.find("a").eq(0);

lastClick = "";
jQuery( document ).on( "click", "#firstp a:first", function(e) {
jQuery( document ).on( "click", "#firstp a", function(e) {
lastClick = "click1";
e.stopImmediatePropagation();
});
jQuery( document ).on( "click", "#firstp a:first", function(e) {
jQuery( document ).on( "click", "#firstp a", function(e) {
lastClick = "click2";
});
$a.trigger( "click" );
equal( lastClick, "click1", "on stopImmediatePropagation" );
jQuery( document ).off( "click", "#firstp a:first" );
jQuery( document ).off( "click", "#firstp a" );

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

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

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

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

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

test( "delegated event with delegateTarget-relative selector", function() {
expect(3);
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");
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");

// Non-positional selector (#12383)
markup.find("#ul0")
.on( "click", "div li a", function() {
ok( false, "div is ABOVE the delegation point!" );
})
.on( "click", "ul a", function() {
ok( false, "ul IS the delegation point!" );
})
.on( "click", "li.test a", function() {
ok( true, "li.test is below the delegation point." );
})
.find("#a0_0").trigger("click").end()
.off("click");

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

// Non-positional selector (#12383)
markup = markup.wrap("<div />").parent();
markup
.find("#ul0")
.on( "click", "div li a", function() {
ok( false, "div is ABOVE the delegation point!" );
})
.on( "click", "ul a", function() {
ok( false, "ul is the delegation point!" );
})
.on( "click", "li.test a", function() {
ok( true, "li.test is below the delegation point." );
})
.find("#a0_0").trigger("click");

markup.remove();
});

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

clone = fixture.clone( true );

clone.find("p:first").trigger( "click", true ); // 3 events should fire
clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
clone.find("#check1").trigger( "change", true ); // 3 events should fire
clone.remove();

clone = fixture.clone( true, true );
clone.find("p:first").trigger( "click", true ); // 3 events should fire
clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
clone.find("#check1").trigger( "change", true ); // 3 events should fire

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

clone.find("p:first").trigger( "click", true ); // 3 events should fire
clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
clone.find("#check1").trigger( "change", true ); // 3 events should fire
clone.remove();

clone.find("p:first").trigger("click"); // 0 should be fired
clone.find("p").eq(0).trigger("click"); // 0 should be fired
clone.find("#check1").trigger("change"); // 0 events should fire
});

0 comments on commit 59f5adb

Please sign in to comment.
You can’t perform that action at this time.