From 0fa52c11cbfe70780648b99717f1dd3502befaff Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Tue, 9 Apr 2013 11:45:09 -0400 Subject: Update jshintrc to conform to new style guide. Conform to onevar and unused in tests. Fixes #13755. --- test/unit/ajax.js | 37 +++---- test/unit/attributes.js | 133 +++++++++++++----------- test/unit/callbacks.js | 4 +- test/unit/core.js | 179 +++++++++++++++++--------------- test/unit/css.js | 91 ++++++++++------- test/unit/data.js | 51 ++++++---- test/unit/deferred.js | 28 +++-- test/unit/dimensions.js | 63 +++++++----- test/unit/effects.js | 160 +++++++++++++++-------------- test/unit/event.js | 255 ++++++++++++++++++++++++---------------------- test/unit/manipulation.js | 58 +++++------ test/unit/offset.js | 50 +++++---- test/unit/queue.js | 33 +++--- test/unit/serialize.js | 6 +- test/unit/traversing.js | 51 ++++++---- test/unit/wrap.js | 28 ++--- 16 files changed, 667 insertions(+), 560 deletions(-) (limited to 'test/unit') diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 226d70983..2dd74c384 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -503,10 +503,10 @@ module( "ajax", { ajaxTest( "jQuery.ajax() - beforeSend", 1, { url: url("data/name.html"), - beforeSend: function( xml ) { + beforeSend: function() { this.check = true; }, - success: function( data ) { + success: function() { ok( this.check, "check beforeSend was executed" ); } }); @@ -576,14 +576,14 @@ module( "ajax", { }); asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() { - var target = "data/name.html"; - var successCount = 0; - var errorCount = 0; - var errorEx = ""; - var success = function() { - successCount++; - }; - jQuery( document ).on( "ajaxError.passthru", function( e, xml, s, ex ) { + var target = "data/name.html", + successCount = 0, + errorCount = 0, + errorEx = "", + success = function() { + successCount++; + }; + jQuery( document ).on( "ajaxError.passthru", function( e, xml ) { errorCount++; errorEx += ": " + xml.status; }); @@ -847,7 +847,7 @@ module( "ajax", { }, url: window.location.href.replace( /[^\/]*$/, "" ) + "data/test.js", dataType: "script", - success: function( data ) { + success: function() { strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); } }); @@ -871,7 +871,7 @@ module( "ajax", { }, url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/test.js", dataType: "script", - success: function( data ) { + success: function() { strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); } }); @@ -1250,9 +1250,10 @@ module( "ajax", { }); test( "#7531 - jQuery.ajax() - Location object as url", 1, function () { - var success = false; + var xhr, + success = false; try { - var xhr = jQuery.ajax({ + xhr = jQuery.ajax({ url: window.location }); success = true; @@ -1268,7 +1269,7 @@ module( "ajax", { url: "data/jsonp.php", dataType: "jsonp", crossDomain: crossDomain, - beforeSend: function( jqXHR, s ) { + beforeSend: function() { strictEqual( this.cache, false, "cache must be false on JSON request" ); return false; }, @@ -1534,12 +1535,12 @@ module( "ajax", { var passed = 0, pass = function() { ok( passed++ < 2, "Error callback executed" ); - if ( passed == 2 ) { + if ( passed === 2 ) { jQuery( document ).off("ajaxError.setupTest"); start(); } }, - fail = function( a, b, c ) { + fail = function( a, b ) { ok( false, "Check for timeout failed " + a + " " + b ); start(); }; @@ -1662,7 +1663,7 @@ module( "ajax", { asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() { Globals.register("testBar"); - jQuery.getScript( url("data/test.js"), function( data, _, jqXHR ) { + jQuery.getScript( url("data/test.js"), function() { strictEqual( window["testBar"], "bar", "Check if script was evaluated" ); start(); }); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 335927b35..062dd504c 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -2,15 +2,15 @@ module( "attributes", { teardown: moduleTeardown }); -var bareObj = function( value ) { +function bareObj( value ) { return value; -}; +} -var functionReturningObj = function( value ) { - return (function() { +function functionReturningObj( value ) { + return function() { return value; - }); -}; + }; +} /* ======== local reference ======= @@ -52,6 +52,10 @@ test( "jQuery.propFix integrity test", function() { test( "attr(String)", function() { expect( 50 ); + var extras, body, $body, + select, optgroup, option, $img, styleElem, + $button, $form, $a; + equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" ); @@ -70,7 +74,7 @@ test( "attr(String)", function() { equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" ); // [7472] & [3113] (form contains an input with name="action" or name="id") - var extras = jQuery("").appendTo("#testForm"); + extras = jQuery("").appendTo("#testForm"); equal( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" ); equal( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" ); equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" ); @@ -100,7 +104,8 @@ test( "attr(String)", function() { equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" ); // Related to [5574] and [5683] - var body = document.body, $body = jQuery( body ); + body = document.body; + $body = jQuery( body ); strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" ); @@ -112,28 +117,28 @@ test( "attr(String)", function() { body.removeAttribute("foo"); // Cleanup - var select = document.createElement("select"), - optgroup = document.createElement("optgroup"), - option = document.createElement("option"); + select = document.createElement("select"); + optgroup = document.createElement("optgroup"); + option = document.createElement("option"); optgroup.appendChild( option ); select.appendChild( optgroup ); equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); - var $img = jQuery("").appendTo("body"); + $img = jQuery("").appendTo("body"); equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." ); equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." ); // Check for style support - var styleElem = jQuery("
").appendTo("#qunit-fixture").css({ + styleElem = jQuery("
").appendTo("#qunit-fixture").css({ background: "url(UPPERlower.gif)" }); ok( !!~styleElem.attr("style").indexOf("UPPERlower.gif"), "Check style attribute getter" ); ok( !!~styleElem.attr("style", "position:absolute;").attr("style").indexOf("absolute"), "Check style setter" ); // Check value on button element (#1954) - var $button = jQuery("").insertAfter("#button"); + $button = jQuery("").insertAfter("#button"); strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" ); equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" ); equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" ); @@ -142,10 +147,10 @@ test( "attr(String)", function() { equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); equal( jQuery("#table").attr( "test:attrib", "foobar" ).attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." ); - var $form = jQuery("
").appendTo("#qunit-fixture"); + $form = jQuery("
").appendTo("#qunit-fixture"); equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." ); - var $a = jQuery("Click").appendTo("#qunit-fixture"); + $a = jQuery("Click").appendTo("#qunit-fixture"); equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); ok( jQuery("
").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); @@ -218,7 +223,7 @@ test( "attr(Hash)", function() { "foo": "baz", "zoo": "ping" }).each(function() { - if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) { + if ( this.getAttribute("foo") !== "baz" && this.getAttribute("zoo") !== "ping" ) { pass = false; } }); @@ -248,7 +253,11 @@ test( "attr(Hash)", function() { test( "attr(String, Object)", function() { expect( 71 ); - var div = jQuery("div").attr("foo", "bar"), + var $input, $text, $details, + attributeNode, commentNode, textNode, obj, + table, td, j, type, + check, thrown, button, $radio, $radios, $svg, + div = jQuery("div").attr("foo", "bar"), i = 0, fail = false; @@ -273,7 +282,7 @@ test( "attr(String, Object)", function() { jQuery("#name").attr( "name", null ); equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" ); - var $input = jQuery( "", { + $input = jQuery( "", { name: "something", id: "specified" }); @@ -311,7 +320,7 @@ test( "attr(String, Object)", function() { $input = jQuery("#check2").attr( "checked", false ).attr( "checked", "checked" ); equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" ); - var $radios = jQuery("#checkedtest").find("input[type='radio']"); + $radios = jQuery("#checkedtest").find("input[type='radio']"); $radios.eq( 1 ).trigger("click"); equal( $radios.eq( 1 ).prop("checked"), true, "Second radio was checked when clicked" ); equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" ); @@ -329,7 +338,7 @@ test( "attr(String, Object)", function() { equal( $input[0].maxLength, 10, "Set maxlength (verified by native property)" ); // HTML5 boolean attributes - var $text = jQuery("#text1").attr({ + $text = jQuery("#text1").attr({ "autofocus": true, "required": true }); @@ -338,7 +347,7 @@ test( "attr(String, Object)", function() { equal( $text.attr("required"), "required", "Reading required attribute yields 'required'" ); equal( $text.attr( "required", false ).attr("required"), undefined, "Setting required attribute to false removes it" ); - var $details = jQuery("
").appendTo("#qunit-fixture"); + $details = jQuery("
").appendTo("#qunit-fixture"); equal( $details.attr("open"), "open", "open attribute presence indicates true" ); equal( $details.attr( "open", false ).attr("open"), undefined, "Setting open attribute to false removes it" ); @@ -354,10 +363,10 @@ test( "attr(String, Object)", function() { jQuery("#foo").attr("contenteditable", true); equal( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" ); - var attributeNode = document.createAttribute("irrelevant"), - commentNode = document.createComment("some comment"), - textNode = document.createTextNode("some text"), - obj = {}; + attributeNode = document.createAttribute("irrelevant"); + commentNode = document.createComment("some comment"); + textNode = document.createTextNode("some text"); + obj = {}; jQuery.each( [ commentNode, textNode, attributeNode ], function( i, elem ) { var $elem = jQuery( elem ); @@ -375,8 +384,8 @@ test( "attr(String, Object)", function() { elem.nonexisting = oldVal; }); - var table = jQuery("#table").append("cellcellcellcellcell"), - td = table.find("td").eq(0); + table = jQuery("#table").append("cellcellcellcellcell"); + td = table.find("td").eq(0); td.attr( "rowspan", "2" ); equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" ); td.attr( "colspan", "2" ); @@ -395,14 +404,14 @@ test( "attr(String, Object)", function() { equal( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" ); // using contents will get comments regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); + j = jQuery("#nonnodes").contents(); j.attr( "name", "attrvalue" ); equal( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" ); j.removeAttr("name"); // Type - var type = jQuery("#check2").attr("type"); + type = jQuery("#check2").attr("type"); try { jQuery("#check2").attr( "type", "hidden" ); ok( true, "No exception thrown on input type change" ); @@ -410,8 +419,8 @@ test( "attr(String, Object)", function() { ok( true, "Exception thrown on input type change: " + e ); } - var check = document.createElement("input"); - var thrown = true; + check = document.createElement("input"); + thrown = true; try { jQuery( check ).attr( "type", "checkbox" ); } catch( e ) { @@ -430,7 +439,7 @@ test( "attr(String, Object)", function() { ok( thrown, "Exception thrown when trying to change type property" ); equal( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" ); - var button = jQuery("#button"); + button = jQuery("#button"); try { button.attr( "type", "submit" ); ok( true, "No exception thrown on button type change" ); @@ -438,14 +447,14 @@ test( "attr(String, Object)", function() { ok( true, "Exception thrown on button type change: " + e ); } - var $radio = jQuery( "", { + $radio = jQuery( "", { "value": "sup", "type": "radio" }).appendTo("#testForm"); equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" ); // Setting attributes on svg elements (bug #3116) - var $svg = jQuery( + $svg = jQuery( "" + "" + @@ -463,8 +472,8 @@ test( "attr(String, Object)", function() { test( "attr(String, Object) - Loaded via XML document", function() { expect( 2 ); - var xml = createDashboardXML(); - var titles = []; + var xml = createDashboardXML(), + titles = []; jQuery( "tab", xml ).each(function() { titles.push( jQuery( this ).attr("title") ); }); @@ -607,7 +616,7 @@ test( "removeAttr(Multi String, variable space width)", function() { div.removeAttr( "id alt title rel " ); - jQuery.each( tests, function( key, val ) { + jQuery.each( tests, function( key ) { equal( div.attr( key ), undefined, "Attribute `" + key + "` was removed" ); }); }); @@ -643,7 +652,8 @@ test( "prop(String, Object)", function() { equal( jQuery("#table").prop("frameBorder"), 1, "Check setting and retrieving frameBorder" ); QUnit.reset(); - var body = document.body, + var select, optgroup, option, attributeNode, commentNode, textNode, obj, $form, + body = document.body, $body = jQuery( body ); ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" ); @@ -652,9 +662,9 @@ test( "prop(String, Object)", function() { body["foo"] = undefined; ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" ); - var select = document.createElement("select"), - optgroup = document.createElement("optgroup"), - option = document.createElement("option"); + select = document.createElement("select"); + optgroup = document.createElement("optgroup"); + option = document.createElement("option"); optgroup.appendChild( option ); select.appendChild( optgroup ); @@ -662,10 +672,10 @@ test( "prop(String, Object)", function() { equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); equal( jQuery( document ).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." ); - var attributeNode = document.createAttribute("irrelevant"), - commentNode = document.createComment("some comment"), - textNode = document.createTextNode("some text"), - obj = {}; + attributeNode = document.createAttribute("irrelevant"); + commentNode = document.createComment("some comment"); + textNode = document.createTextNode("some text"); + obj = {}; jQuery.each( [ document, attributeNode, commentNode, textNode, obj, "#firstp" ], function( i, ele ) { strictEqual( jQuery( ele ).prop("nonexisting"), undefined, "prop works correctly for non existing attributes (bug #7500)." ); }); @@ -678,7 +688,7 @@ test( "prop(String, Object)", function() { }); jQuery( document ).removeProp("nonexisting"); - var $form = jQuery("#form").prop( "enctype", "multipart/form-data" ); + $form = jQuery("#form").prop( "enctype", "multipart/form-data" ); equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); }); @@ -775,6 +785,8 @@ test( "removeProp(String)", function() { test( "val()", function() { expect( 21 + ( jQuery.fn.serialize ? 6 : 0 ) ); + var checks, $button; + document.getElementById("text1").value = "bla"; equal( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); @@ -823,7 +835,7 @@ test( "val()", function() { ); if ( jQuery.fn.serialize ) { - var checks = jQuery("").appendTo("#form"); + checks = jQuery("").appendTo("#form"); deepEqual( checks.serialize(), "", "Get unchecked values." ); @@ -844,7 +856,7 @@ test( "val()", function() { checks.remove(); } - var $button = jQuery("").insertAfter("#button"); + $button = jQuery("").insertAfter("#button"); equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" ); equal( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" ); @@ -907,7 +919,8 @@ var testVal = function( valueObj ) { jQuery("#text1").val( valueObj( null ) ); equal( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" ); - var $select1 = jQuery("#select1"); + var j, + $select1 = jQuery("#select1"); $select1.val( valueObj("3") ); equal( $select1.val(), "3", "Check for modified (via val(String)) value of select element" ); @@ -919,7 +932,7 @@ var testVal = function( valueObj ) { equal( $select1.val(), "4", "Should be possible to set the val() to a newly created option" ); // using contents will get comments regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); + j = jQuery("#nonnodes").contents(); j.val( valueObj( "asdf" ) ); equal( j.val(), "asdf", "Check node,textnode,comment with val()" ); j.removeAttr("value"); @@ -1019,10 +1032,11 @@ test( "val(select) after form.reset() (Bug #2551)", function() { var testAddClass = function( valueObj ) { expect( 9 ); - var div = jQuery("#qunit-fixture div"); + var pass, j, i, + div = jQuery("#qunit-fixture div"); div.addClass( valueObj("test") ); - var pass = true; - for ( var i = 0; i < div.length; i++ ) { + pass = true; + for ( i = 0; i < div.length; i++ ) { if ( !~div.get( i ).className.indexOf("test") ) { pass = false; } @@ -1030,7 +1044,7 @@ var testAddClass = function( valueObj ) { ok( pass, "Add Class" ); // using contents will get regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); + j = jQuery("#nonnodes").contents(); j.addClass( valueObj("asdf") ); ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" ); @@ -1071,7 +1085,8 @@ test( "addClass(Function)", function() { test( "addClass(Function) with incoming value", function() { expect( 52 ); - var div = jQuery("#qunit-fixture div"), + var pass, i, + div = jQuery("#qunit-fixture div"), old = div.map(function() { return jQuery(this).attr("class") || ""; }); @@ -1083,9 +1098,9 @@ test( "addClass(Function) with incoming value", function() { } }); - var pass = true; - for ( var i = 0; i < div.length; i++ ) { - if ( div.get(i).className.indexOf("test") == -1 ) { + pass = true; + for ( i = 0; i < div.length; i++ ) { + if ( div.get(i).className.indexOf("test") === -1 ) { pass = false; } } diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index 8962e5810..843c95849 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -56,7 +56,7 @@ jQuery.each( tests, function( strFlags, resultString ) { } }); - jQuery.each( filters, function( filterLabel, filter ) { + jQuery.each( filters, function( filterLabel ) { jQuery.each({ "string": strFlags, @@ -220,7 +220,7 @@ jQuery.each( tests, function( strFlags, resultString ) { // Callbacks are not iterated output = ""; - function handler( tmp ) { + function handler() { output += "X"; } handler.method = function() { diff --git a/test/unit/core.js b/test/unit/core.js index 0f08fb4af..60b8e7272 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -298,10 +298,10 @@ test("type", function() { equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" ); // Avoid Lint complaints - var MyString = String; - var MyNumber = Number; - var MyBoolean = Boolean; - var MyObject = Object; + var MyString = String, + MyNumber = Number, + MyBoolean = Boolean, + MyObject = Object; equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" ); equal( jQuery.type(new MyNumber(1)), "number", "Number" ); equal( jQuery.type(new MyString("a")), "string", "String" ); @@ -378,6 +378,8 @@ asyncTest("isPlainObject", function() { test("isFunction", function() { expect(19); + var mystr, myarr, myfunction, fn, obj, nodes, first, input, a; + // Make sure that false values return false ok( !jQuery.isFunction(), "No Value" ); ok( !jQuery.isFunction( null ), "null Value" ); @@ -393,22 +395,22 @@ test("isFunction", function() { ok( jQuery.isFunction(Function), "Function Function("+Function+")" ); // When stringified, this could be misinterpreted - var mystr = "function"; + mystr = "function"; ok( !jQuery.isFunction(mystr), "Function String" ); // When stringified, this could be misinterpreted - var myarr = [ "function" ]; + myarr = [ "function" ]; ok( !jQuery.isFunction(myarr), "Function Array" ); // When stringified, this could be misinterpreted - var myfunction = { "function": "test" }; + myfunction = { "function": "test" }; ok( !jQuery.isFunction(myfunction), "Function Object" ); // Make sure normal functions still work - var fn = function(){}; + fn = function(){}; ok( jQuery.isFunction(fn), "Normal Function" ); - var obj = document.createElement("object"); + obj = document.createElement("object"); // Firefox says this is a function ok( !jQuery.isFunction(obj), "Object Element" ); @@ -417,17 +419,17 @@ test("isFunction", function() { // Since 1.3, this isn't supported (#2968) //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); - var nodes = document.body.childNodes; + nodes = document.body.childNodes; // Safari says this is a function ok( !jQuery.isFunction(nodes), "childNodes Property" ); - var first = document.body.firstChild; + first = document.body.firstChild; // Normal elements are reported ok everywhere ok( !jQuery.isFunction(first), "A normal DOM Element" ); - var input = document.createElement("input"); + input = document.createElement("input"); input.type = "text"; document.body.appendChild( input ); @@ -437,7 +439,7 @@ test("isFunction", function() { document.body.removeChild( input ); - var a = document.createElement("a"); + a = document.createElement("a"); a.href = "some-function"; document.body.appendChild( a ); @@ -523,11 +525,12 @@ test("isXMLDoc - HTML", function() { ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" ); ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" ); - var iframe = document.createElement("iframe"); + var body, + iframe = document.createElement("iframe"); document.body.appendChild( iframe ); try { - var body = jQuery(iframe).contents()[0]; + body = jQuery(iframe).contents()[0]; try { ok( !jQuery.isXMLDoc( body ), "Iframe body element" ); @@ -590,16 +593,18 @@ test("isWindow", function() { test("jQuery('html')", function() { expect( 15 ); + var s, div, j; + QUnit.reset(); jQuery["foo"] = false; - var s = jQuery("")[0]; + s = jQuery("")[0]; ok( s, "Creating a script" ); ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" ); jQuery("body").append(""); ok( jQuery["foo"], "Executing a scripts contents in the right context" ); // Test multi-line HTML - var div = jQuery("
\r\nsome text\n

some p

\nmore text\r\n
")[0]; + div = jQuery("
\r\nsome text\n

some p

\nmore text\r\n
")[0]; equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." ); equal( div.firstChild.nodeType, 3, "Text node." ); equal( div.lastChild.nodeType, 3, "Text node." ); @@ -613,7 +618,7 @@ test("jQuery('html')", function() { ok( jQuery("").attr("type", "hidden"), "Create an input and set the type." ); - var j = jQuery("hi there "); + j = jQuery("hi there "); ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" ); ok( !jQuery("")[0].selected, "Make sure that options are auto-selected #2050" ); @@ -630,9 +635,10 @@ test("jQuery('html')", function() { test("jQuery('massive html #7990')", function() { expect( 3 ); - var i; - var li = "
  • very very very very large html string
  • "; - var html = ["
      "]; + var i, + li = "
    • very very very very large html string
    • ", + html = ["
        "]; + for ( i = 0; i < 30000; i += 1 ) { html[html.length] = li; } @@ -646,30 +652,30 @@ test("jQuery('massive html #7990')", function() { test("jQuery('html', context)", function() { expect(1); - var $div = jQuery("
        ")[0]; - var $span = jQuery("", $div); - equal($span.length, 1, "Verify a span created with a div context works, #1763"); + var $div = jQuery("
        ")[0], + $span = jQuery("", $div); + equal($span.length, 1, "verify a span created with a div context works, #1763"); }); -test("jQuery(selector, xml).text(str) - Loaded via XML document", function() { +test("jQuery(selector, xml).text(str) - loaded via xml document", function() { expect(2); - var xml = createDashboardXML(); - // tests for #1419 where IE was a problem - var tab = jQuery("tab", xml).eq(0); - equal( tab.text(), "blabla", "Verify initial text correct" ); + var xml = createDashboardXML(), + // tests for #1419 where ie was a problem + tab = jQuery("tab", xml).eq(0); + equal( tab.text(), "blabla", "verify initial text correct" ); tab.text("newtext"); - equal( tab.text(), "newtext", "Verify new text correct" ); + equal( tab.text(), "newtext", "verify new text correct" ); }); test("end()", function() { expect(3); - equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "Check for end" ); - ok( jQuery("#yahoo").end(), "Check for end with nothing to end" ); + equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "check for end" ); + ok( jQuery("#yahoo").end(), "check for end with nothing to end" ); var x = jQuery("#yahoo"); x.parent(); - equal( "Yahoo", jQuery("#yahoo").text(), "Check for non-destructive behaviour" ); + equal( "Yahoo", jQuery("#yahoo").text(), "check for non-destructive behaviour" ); }); test("length", function() { @@ -739,11 +745,13 @@ test("get(-Number)",function() { test("each(Function)", function() { expect(1); - var div = jQuery("div"); + var div, pass, i; + + div = jQuery("div"); div.each(function(){this.foo = "zoo";}); - var pass = true; - for ( var i = 0; i < div.length; i++ ) { - if ( div.get(i).foo != "zoo" ) { + pass = true; + for ( i = 0; i < div.length; i++ ) { + if ( div.get(i).foo !== "zoo" ) { pass = false; } } @@ -807,7 +815,7 @@ test("jQuery.map", function() { }); equal( result.join(""), "012", "Map the keys from an array" ); - result = jQuery.map( [ 3, 4, 5 ], function( v, k ) { + result = jQuery.map( [ 3, 4, 5 ], function( v ) { return v; }); equal( result.join(""), "345", "Map the values from an array" ); @@ -817,25 +825,25 @@ test("jQuery.map", function() { }); equal( result.join(""), "ab", "Map the keys from an object" ); - result = jQuery.map( { a: 1, b: 2 }, function( v, k ) { + result = jQuery.map( { a: 1, b: 2 }, function( v ) { return v; }); equal( result.join(""), "12", "Map the values from an object" ); - result = jQuery.map( [ "a", undefined, null, "b" ], function( v, k ) { + result = jQuery.map( [ "a", undefined, null, "b" ], function( v ) { return v; }); equal( result.join(""), "ab", "Array iteration does not include undefined/null results" ); - result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v, k ) { + result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v ) { return v; }); equal( result.join(""), "ab", "Object iteration does not include undefined/null results" ); result = { Zero: function() {}, - One: function( a ) {}, - Two: function( a, b ) {} + One: function( a ) { a = a; }, + Two: function( a, b ) { a = a; b = b; } }; callback = function( v, k ) { equal( k, "foo", label + "-argument function treated like object" ); @@ -883,13 +891,13 @@ test("jQuery.map", function() { } result = false; - jQuery.map( { length: 0 }, function( v, k ) { + jQuery.map( { length: 0 }, function() { result = true; }); ok( !result, "length: 0 plain object treated like array" ); result = false; - jQuery.map( document.getElementsByTagName("asdf"), function( v, k ) { + jQuery.map( document.getElementsByTagName("asdf"), function() { result = true; }); ok( !result, "empty NodeList treated like array" ); @@ -925,12 +933,15 @@ test("jQuery.merge()", function() { test("jQuery.extend(Object, Object)", function() { expect(28); - var settings = { "xnumber1": 5, "xnumber2": 7, "xstring1": "peter", "xstring2": "pan" }, + var empty, optionsWithLength, optionsWithDate, myKlass, + customObject, optionsWithCustomObject, MyNumber, ret, + nullUndef, target, recursive, obj, + defaults, defaultsCopy, options1, options1Copy, options2, options2Copy, merged2, + settings = { "xnumber1": 5, "xnumber2": 7, "xstring1": "peter", "xstring2": "pan" }, options = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" }, optionsCopy = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" }, merged = { "xnumber1": 5, "xnumber2": 1, "xstring1": "peter", "xstring2": "x", "xxx": "newstring" }, deep1 = { "foo": { "bar": true } }, - deep1copy = { "foo": { "bar": true } }, deep2 = { "foo": { "baz": true }, "foo2": document }, deep2copy = { "foo": { "baz": true }, "foo2": document }, deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document }, @@ -956,20 +967,20 @@ test("jQuery.extend(Object, Object)", function() { ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array have to be an Array" ); ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object have to be an plain object" ); - var empty = {}; - var optionsWithLength = { "foo": { "length": -1 } }; + empty = {}; + optionsWithLength = { "foo": { "length": -1 } }; jQuery.extend(true, empty, optionsWithLength); deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" ); empty = {}; - var optionsWithDate = { "foo": { "date": new Date() } }; + optionsWithDate = { "foo": { "date": new Date() } }; jQuery.extend(true, empty, optionsWithDate); deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" ); /** @constructor */ - var myKlass = function() {}; - var customObject = new myKlass(); - var optionsWithCustomObject = { "foo": { "date": customObject } }; + myKlass = function() {}; + customObject = new myKlass(); + optionsWithCustomObject = { "foo": { "date": customObject } }; empty = {}; jQuery.extend(true, empty, optionsWithCustomObject); ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" ); @@ -980,11 +991,12 @@ test("jQuery.extend(Object, Object)", function() { jQuery.extend(true, empty, optionsWithCustomObject); ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" ); - var MyNumber = Number; - var ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } ); - ok( ret.foo == 5, "Wrapped numbers copy correctly" ); + MyNumber = Number; + + ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } ); + ok( parseInt(ret.foo, 10) === 5, "Wrapped numbers copy correctly" ); - var nullUndef; + nullUndef; nullUndef = jQuery.extend({}, options, { "xnumber2": null }); ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied"); @@ -994,8 +1006,8 @@ test("jQuery.extend(Object, Object)", function() { nullUndef = jQuery.extend({}, options, { "xnumber0": null }); ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted"); - var target = {}; - var recursive = { foo:target, bar:5 }; + target = {}; + recursive = { foo:target, bar:5 }; jQuery.extend(true, target, recursive); deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" ); @@ -1003,12 +1015,12 @@ test("jQuery.extend(Object, Object)", function() { equal( ret.foo.length, 1, "Check to make sure a value with coercion 'false' copies over when necessary to fix #1907" ); ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } ); - ok( typeof ret.foo != "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" ); + ok( typeof ret.foo !== "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" ); ret = jQuery.extend(true, { foo:"bar" }, { foo:null } ); ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" ); - var obj = { foo:null }; + obj = { foo:null }; jQuery.extend(true, obj, { foo:"notnull" } ); equal( obj.foo, "notnull", "Make sure a null value can be overwritten" ); @@ -1016,13 +1028,13 @@ test("jQuery.extend(Object, Object)", function() { jQuery.extend(func, { key: "value" } ); equal( func.key, "value", "Verify a function can be extended" ); - var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, - defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, - options1 = { xnumber2: 1, xstring2: "x" }, - options1Copy = { xnumber2: 1, xstring2: "x" }, - options2 = { xstring2: "xx", xxx: "newstringx" }, - options2Copy = { xstring2: "xx", xxx: "newstringx" }, - merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; + defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }; + defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }; + options1 = { xnumber2: 1, xstring2: "x" }; + options1Copy = { xnumber2: 1, xstring2: "x" }; + options2 = { xstring2: "xx", xxx: "newstringx" }; + options2Copy = { xstring2: "xx", xxx: "newstringx" }; + merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; settings = jQuery.extend({}, defaults, options1, options2); deepEqual( settings, merged2, "Check if extended: settings must be extended" ); @@ -1087,10 +1099,10 @@ test("jQuery.each(Object,Function)", function() { seen = { Zero: function() {}, - One: function( a ) {}, - Two: function( a, b ) {} + One: function( a ) { a = a; }, + Two: function( a, b ) { a = a; b = b; } }; - callback = function( k, v ) { + callback = function( k ) { equal( k, "foo", label + "-argument function treated like object" ); }; for ( i in seen ) { @@ -1110,7 +1122,7 @@ test("jQuery.each(Object,Function)", function() { "negative": -1, "excess": 1 }; - callback = function( k, v ) { + callback = function( k ) { equal( k, "length", "Object with " + label + " length treated like object" ); }; for ( i in seen ) { @@ -1124,7 +1136,7 @@ test("jQuery.each(Object,Function)", function() { "length: 2 plain object": { length: 2, "0": true, "1": true }, NodeList: document.getElementsByTagName("html") }; - callback = function( k, v ) { + callback = function( k ) { if ( seen[ label ] ) { delete seen[ label ]; equal( k, "0", label + " treated like array" ); @@ -1137,13 +1149,13 @@ test("jQuery.each(Object,Function)", function() { } seen = false; - jQuery.each( { length: 0 }, function( k, v ) { + jQuery.each( { length: 0 }, function() { seen = true; }); ok( !seen, "length: 0 plain object treated like array" ); seen = false; - jQuery.each( document.getElementsByTagName("asdf"), function( k, v ) { + jQuery.each( document.getElementsByTagName("asdf"), function() { seen = true; }); ok( !seen, "empty NodeList treated like array" ); @@ -1162,7 +1174,7 @@ test("jQuery.makeArray", function(){ equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); - equal( (function(arg1, arg2){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); + equal( (function() { return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" ); @@ -1216,8 +1228,9 @@ test("jQuery.isEmptyObject", function(){ test("jQuery.proxy", function(){ expect( 9 ); - var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); }; - var thisObject = { foo: "bar", method: test }; + var test2, test3, test4, fn, cb, + test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); }, + thisObject = { foo: "bar", method: test }; // Make sure normal works test.call( thisObject ); @@ -1232,23 +1245,23 @@ test("jQuery.proxy", function(){ equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." ); // Partial application - var test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); }; + test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); }; jQuery.proxy( test2, null, "pre-applied" )(); // Partial application w/ normal arguments - var test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; + test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; jQuery.proxy( test3, null, "pre-applied" )( "normal" ); // Test old syntax - var test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } }; + test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } }; jQuery.proxy( test4, "meth" )( "boom" ); // jQuery 1.9 improved currying with `this` object - var fn = function() { + fn = function() { equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" ); equal( this.foo, "bar", "this-object passed" ); }; - var cb = jQuery.proxy( fn, null, "arg1", "arg2" ); + cb = jQuery.proxy( fn, null, "arg1", "arg2" ); cb.call( thisObject, "arg3" ); }); diff --git a/test/unit/css.js b/test/unit/css.js index f23c5dbe9..b48b52982 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -7,11 +7,13 @@ test("css(String|Hash)", function() { equal( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"" ); - var $child = jQuery("#nothiddendivchild").css({ "width": "20%", "height": "20%" }); + var $child, div, div2, width, height, child, prctval, checkval, old; + + $child = jQuery("#nothiddendivchild").css({ "width": "20%", "height": "20%" }); notEqual( $child.css("width"), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" ); notEqual( $child.css("height"), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" ); - var div = jQuery( "
        " ); + div = jQuery( "
        " ); // These should be "auto" (or some better value) // temporarily provide "0px" for backwards compat @@ -23,7 +25,7 @@ test("css(String|Hash)", function() { equal( div.css("width"), "4px", "Width on disconnected node." ); equal( div.css("height"), "4px", "Height on disconnected node." ); - var div2 = jQuery( "