aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/ajax.js37
-rw-r--r--test/unit/attributes.js133
-rw-r--r--test/unit/callbacks.js4
-rw-r--r--test/unit/core.js179
-rw-r--r--test/unit/css.js91
-rw-r--r--test/unit/data.js51
-rw-r--r--test/unit/deferred.js28
-rw-r--r--test/unit/dimensions.js63
-rw-r--r--test/unit/effects.js160
-rw-r--r--test/unit/event.js255
-rw-r--r--test/unit/manipulation.js58
-rw-r--r--test/unit/offset.js50
-rw-r--r--test/unit/queue.js33
-rw-r--r--test/unit/serialize.js6
-rw-r--r--test/unit/traversing.js51
-rw-r--r--test/unit/wrap.js28
16 files changed, 667 insertions, 560 deletions
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("<input id='id' name='id' /><input id='name' name='name' /><input id='target' name='target' />").appendTo("#testForm");
+ extras = jQuery("<input id='id' name='id' /><input id='name' name='name' /><input id='target' name='target' />").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("<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>").appendTo("body");
+ $img = jQuery("<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>").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("<div/>").appendTo("#qunit-fixture").css({
+ styleElem = jQuery("<div/>").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("<button>text</button>").insertAfter("#button");
+ $button = jQuery("<button>text</button>").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("<form class='something'></form>").appendTo("#qunit-fixture");
+ $form = jQuery("<form class='something'></form>").appendTo("#qunit-fixture");
equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." );
- var $a = jQuery("<a href='#' onclick='something()'>Click</a>").appendTo("#qunit-fixture");
+ $a = jQuery("<a href='#' onclick='something()'>Click</a>").appendTo("#qunit-fixture");
equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." );
ok( jQuery("<div/>").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>", {
+ $input = jQuery( "<input>", {
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("<details open></details>").appendTo("#qunit-fixture");
+ $details = jQuery("<details open></details>").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("<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").eq(0);
+ 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").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( "<input>", {
+ $radio = jQuery( "<input>", {
"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(
"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' baseProfile='full' width='200' height='200'>" +
"<circle cx='200' cy='200' r='150' />" +
@@ -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("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
+ checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
deepEqual( checks.serialize(), "", "Get unchecked values." );
@@ -844,7 +856,7 @@ test( "val()", function() {
checks.remove();
}
- var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
+ $button = jQuery("<button value='foobar'>text</button>").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("<script>jQuery.foo='test';</script>")[0];
+ s = jQuery("<script>jQuery.foo='test';</script>")[0];
ok( s, "Creating a script" );
ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" );
jQuery("body").append("<script>jQuery.foo='test';</script>");
ok( jQuery["foo"], "Executing a scripts contents in the right context" );
// Test multi-line HTML
- var div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0];
+ div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[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("<input/>").attr("type", "hidden"), "Create an input and set the type." );
- var j = jQuery("<span>hi</span> there <!-- mon ami -->");
+ j = jQuery("<span>hi</span> there <!-- mon ami -->");
ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
ok( !jQuery("<option>test</option>")[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 = "<li>very very very very large html string</li>";
- var html = ["<ul>"];
+ var i,
+ li = "<li>very very very very large html string</li>",
+ html = ["<ul>"];
+
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("<div/>")[0];
- var $span = jQuery("<span/>", $div);
- equal($span.length, 1, "Verify a span created with a div context works, #1763");
+ var $div = jQuery("<div/>")[0],
+ $span = jQuery("<span/>", $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>" );
+ div = jQuery( "<div>" );
// 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( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
+ div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
equal( div2.find("input").css("height"), "20px", "Height on hidden input." );
equal( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
@@ -34,7 +36,8 @@ test("css(String|Hash)", function() {
// handle negative numbers by setting to zero #11604
jQuery("#nothiddendiv").css( {"width": 1, "height": 1} );
- var width = parseFloat(jQuery("#nothiddendiv").css("width")), height = parseFloat(jQuery("#nothiddendiv").css("height"));
+ width = parseFloat(jQuery("#nothiddendiv").css("width"));
+ height = parseFloat(jQuery("#nothiddendiv").css("height"));
jQuery("#nothiddendiv").css({ "overflow":"hidden", "width": -1, "height": -1 });
equal( parseFloat(jQuery("#nothiddendiv").css("width")), 0, "Test negative width set to 0");
equal( parseFloat(jQuery("#nothiddendiv").css("height")), 0, "Test negative height set to 0");
@@ -60,7 +63,7 @@ test("css(String|Hash)", function() {
equal( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
div = jQuery("#nothiddendiv");
- var child = jQuery("#nothiddendivchild");
+ child = jQuery("#nothiddendivchild");
equal( parseInt(div.css("fontSize"), 10), 16, "Verify fontSize px set." );
equal( parseInt(div.css("font-size"), 10), 16, "Verify fontSize px set." );
@@ -76,7 +79,8 @@ test("css(String|Hash)", function() {
// Have to verify this as the result depends upon the browser's CSS
// support for font-size percentages
child.attr("class", "prct");
- var prctval = parseInt(child.css("fontSize"), 10), checkval = 0;
+ prctval = parseInt(child.css("fontSize"), 10);
+ checkval = 0;
if ( prctval === 16 || prctval === 24 ) {
checkval = prctval;
}
@@ -85,7 +89,7 @@ test("css(String|Hash)", function() {
equal( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
- var old = child[0].style.height;
+ old = child[0].style.height;
// Test NaN
child.css("height", parseFloat("zoo"));
@@ -196,6 +200,7 @@ test("css() explicit and relative values", function() {
test("css(String, Object)", function() {
expect( 19 );
+ var j, div, display, ret, success;
jQuery("#nothiddendiv").css("top", "-1em");
ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
@@ -215,22 +220,22 @@ test("css(String, Object)", function() {
equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
// using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
+ j = jQuery("#nonnodes").contents();
j.css("overflow", "visible");
equal( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
// opera sometimes doesn't update 'display' correctly, see #2037
jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML;
equal( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
- var div = jQuery("#nothiddendiv"),
- display = div.css("display"),
- ret = div.css("display", undefined);
+ div = jQuery("#nothiddendiv");
+ display = div.css("display");
+ ret = div.css("display", undefined);
equal( ret, div, "Make sure setting undefined returns the original set." );
equal( div.css("display"), display, "Make sure that the display wasn't changed." );
// Test for Bug #5509
- var success = true;
+ success = true;
try {
jQuery("#foo").css("backgroundColor", "rgba(0, 0, 0, 0.1)");
}
@@ -259,14 +264,15 @@ test( "css(Array)", function() {
test("css(String, Function)", function() {
expect(3);
- var sizes = ["10px", "20px", "30px"];
+ var index,
+ sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>")
.appendTo("body");
- var index = 0;
+ index = 0;
jQuery("#cssFunctionTest div").css("font-size", function() {
var size = sizes[index];
@@ -277,8 +283,8 @@ test("css(String, Function)", function() {
index = 0;
jQuery("#cssFunctionTest div").each(function() {
- var computedSize = jQuery(this).css("font-size");
- var expectedSize = sizes[index];
+ var computedSize = jQuery(this).css("font-size"),
+ expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
});
@@ -289,14 +295,15 @@ test("css(String, Function)", function() {
test("css(String, Function) with incoming value", function() {
expect(3);
- var sizes = ["10px", "20px", "30px"];
+ var index,
+ sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>")
.appendTo("body");
- var index = 0;
+ index = 0;
jQuery("#cssFunctionTest div").css("font-size", function() {
var size = sizes[index];
@@ -319,14 +326,15 @@ test("css(String, Function) with incoming value", function() {
test("css(Object) where values are Functions", function() {
expect(3);
- var sizes = ["10px", "20px", "30px"];
+ var index,
+ sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>")
.appendTo("body");
- var index = 0;
+ index = 0;
jQuery("#cssFunctionTest div").css({"fontSize": function() {
var size = sizes[index];
@@ -337,8 +345,8 @@ test("css(Object) where values are Functions", function() {
index = 0;
jQuery("#cssFunctionTest div").each(function() {
- var computedSize = jQuery(this).css("font-size");
- var expectedSize = sizes[index];
+ var computedSize = jQuery(this).css("font-size"),
+ expectedSize = sizes[index];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
});
@@ -349,14 +357,15 @@ test("css(Object) where values are Functions", function() {
test("css(Object) where values are Functions with incoming values", function() {
expect(3);
- var sizes = ["10px", "20px", "30px"];
+ var index,
+ sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>")
.appendTo("body");
- var index = 0;
+ index = 0;
jQuery("#cssFunctionTest div").css({"fontSize": function() {
var size = sizes[index];
@@ -379,13 +388,15 @@ test("css(Object) where values are Functions with incoming values", function() {
test("show(); hide()", function() {
expect(22);
- var hiddendiv = jQuery("div.hidden");
+ var hiddendiv, div, pass, old, test;
+
+ hiddendiv = jQuery("div.hidden");
hiddendiv.hide();
equal( hiddendiv.css("display"), "none", "Non-detached div hidden" );
hiddendiv.show();
equal( hiddendiv.css("display"), "block", "Pre-hidden div shown" );
- var div = jQuery("<div>").hide();
+ div = jQuery("<div>").hide();
equal( div.css("display"), "none", "Detached div hidden" );
div.appendTo("#qunit-fixture").show();
equal( div.css("display"), "block", "Pre-hidden div shown" );
@@ -404,10 +415,10 @@ test("show(); hide()", function() {
hiddendiv.css("display","");
- var pass = true;
+ pass = true;
div = jQuery("#qunit-fixture div");
div.show().each(function(){
- if ( this.style.display == "none" ) {
+ if ( this.style.display === "none" ) {
pass = false;
}
});
@@ -416,10 +427,10 @@ test("show(); hide()", function() {
// #show-tests * is set display: none in CSS
jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
- var old = jQuery("#test-table").show().css("display") !== "table";
+ old = jQuery("#test-table").show().css("display") !== "table";
jQuery("#test-table").remove();
- var test = {
+ test = {
"div" : "block",
"p" : "block",
"a" : "inline",
@@ -567,7 +578,7 @@ test("show() resolves correct default display when iframe display:none #12904",
test("toggle()", function() {
expect(9);
- var div,
+ var div, oldHide,
x = jQuery("#foo");
ok( x.is(":visible"), "is visible" );
@@ -589,7 +600,7 @@ test("toggle()", function() {
strictEqual( x.toggle().css( "display" ), "block", "is visible" );
// Ensure hide() is called when toggled (#12148)
- var oldHide = jQuery.fn.hide;
+ oldHide = jQuery.fn.hide;
jQuery.fn.hide = function() {
ok( true, name + " method called on toggle" );
return oldHide.apply( this, arguments );
@@ -709,10 +720,12 @@ test("widows & orphans #8936", function () {
test("can't get css for disconnected in IE<9, see #10254 and #8388", function() {
expect( 2 );
- var span = jQuery( "<span/>" ).css( "background-image", "url(data/1x1.jpg)" );
+ var span, div;
+
+ span = jQuery( "<span/>" ).css( "background-image", "url(data/1x1.jpg)" );
notEqual( span.css( "background-image" ), null, "can't get background-image in IE<9, see #10254" );
- var div = jQuery( "<div/>" ).css( "top", 10 );
+ div = jQuery( "<div/>" ).css( "top", 10 );
equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" );
});
@@ -844,9 +857,13 @@ test( "cssHooks - expand", function() {
test( "css opacity consistency across browsers (#12685)", function() {
expect( 4 );
- var fixture = jQuery("#qunit-fixture"),
- style = jQuery("<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>").appendTo(fixture),
- el = jQuery("<div class='opacityWithSpaces_t12685'></div>").appendTo(fixture);
+ var el,
+ fixture = jQuery("#qunit-fixture");
+
+ // Append style element
+ jQuery("<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>").appendTo( fixture );
+
+ el = jQuery("<div class='opacityWithSpaces_t12685'></div>").appendTo(fixture);
equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" );
el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685");
diff --git a/test/unit/data.js b/test/unit/data.js
index b01078da5..a0361504a 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -173,19 +173,21 @@ test("jQuery.data(object/flash)", 25, function() {
test(".data()", function() {
expect(5);
- var div = jQuery("#foo");
+ var div, dataObj, nodiv, obj;
+
+ div = jQuery("#foo");
strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
div.data("test", "success");
- var dataObj = div.data();
+ dataObj = div.data();
deepEqual( dataObj, {test: "success"}, "data() returns entire data object with expected properties" );
strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
- var nodiv = jQuery("#unfound");
+ nodiv = jQuery("#unfound");
equal( nodiv.data(), null, "data() on empty set returns null" );
- var obj = { foo: "bar" };
+ obj = { foo: "bar" };
jQuery(obj).data("foo", "baz");
dataObj = jQuery.extend(true, {}, jQuery(obj).data());
@@ -193,7 +195,7 @@ test(".data()", function() {
deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
});
-var testDataTypes = function( $obj ) {
+function testDataTypes( $obj ) {
jQuery.each({
"null": null,
"true": true,
@@ -211,7 +213,7 @@ var testDataTypes = function( $obj ) {
}, function( type, value ) {
strictEqual( $obj.data( "test", value ).data("test"), value, "Data set to " + type );
});
-};
+}
test("jQuery(Element).data(String, Object).data(String)", function() {
expect( 18 );
@@ -244,7 +246,9 @@ test("jQuery(plain Object).data(String, Object).data(String)", function() {
test("data-* attributes", function() {
expect(40);
- var div = jQuery("<div>"),
+ var prop, i, l, metadata, elem,
+ obj, obj2, check, num, num2,
+ div = jQuery("<div>"),
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
@@ -270,16 +274,15 @@ test("data-* attributes", function() {
child.data("ignored", "cache");
equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback");
- var prop,
- obj = child.data(),
- obj2 = dummy.data(),
- check = [ "myobj", "ignored", "other" ],
- num = 0,
- num2 = 0;
+ obj = child.data();
+ obj2 = dummy.data();
+ check = [ "myobj", "ignored", "other" ];
+ num = 0;
+ num2 = 0;
dummy.remove();
- for ( var i = 0, l = check.length; i < l; i++ ) {
+ for ( i = 0, l = check.length; i < l; i++ ) {
ok( obj[ check[i] ], "Make sure data- property exists when calling data-." );
ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
}
@@ -361,8 +364,8 @@ test("data-* attributes", function() {
}
}
- var metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>",
- elem = jQuery(metadata).appendTo("#qunit-fixture");
+ metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>";
+ elem = jQuery(metadata).appendTo("#qunit-fixture");
elem.find("li").each(testData);
elem.remove();
@@ -371,14 +374,16 @@ test("data-* attributes", function() {
test(".data(Object)", function() {
expect(4);
- var div = jQuery("<div/>");
+ var obj, jqobj,
+ div = jQuery("<div/>");
div.data({ "test": "in", "test2": "in2" });
equal( div.data("test"), "in", "Verify setting an object in data" );
equal( div.data("test2"), "in2", "Verify setting an object in data" );
- var obj = {test:"unset"},
- jqobj = jQuery(obj);
+ obj = {test:"unset"};
+ jqobj = jQuery(obj);
+
jqobj.data("test", "unset");
jqobj.data({ "test": "in", "test2": "in2" });
equal( jQuery.data(obj)["test"], "in", "Verify setting an object on an object extends the data object" );
@@ -390,7 +395,9 @@ test(".data(Object)", function() {
test("jQuery.removeData", function() {
expect(10);
- var div = jQuery("#foo")[0];
+
+ var obj,
+ div = jQuery("#foo")[0];
jQuery.data(div, "test", "testing");
jQuery.removeData(div, "test");
equal( jQuery.data(div, "test"), undefined, "Check removal of data" );
@@ -422,7 +429,7 @@ test("jQuery.removeData", function() {
ok( !jQuery.data(div, "test3 test4"), "Multiple delete with spaces deleted key with exact name" );
ok( jQuery.data(div, "test3"), "Left the partial matched key alone" );
- var obj = {};
+ obj = {};
jQuery.data(obj, "test", "testing");
equal( jQuery(obj).data("test"), "testing", "verify data on plain object");
jQuery.removeData(obj, "test");
@@ -594,7 +601,7 @@ test(".data supports interoperable removal of hyphenated/camelCase properties",
});
});
-test( ".removeData supports removal of hyphenated properties via array (#12786)", function( assert ) {
+test( ".removeData supports removal of hyphenated properties via array (#12786)", function() {
expect( 4 );
var div, plain, compare;
diff --git a/test/unit/deferred.js b/test/unit/deferred.js
index f9bc13a9c..4e545303d 100644
--- a/test/unit/deferred.js
+++ b/test/unit/deferred.js
@@ -47,7 +47,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
funcPromise = defer.promise( func );
strictEqual( defer.promise(), promise, "promise is always the same" );
strictEqual( funcPromise, func, "non objects get extended" );
- jQuery.each( promise, function( key, value ) {
+ jQuery.each( promise, function( key ) {
if ( !jQuery.isFunction( promise[ key ] ) ) {
ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
}
@@ -275,7 +275,8 @@ test( "jQuery.Deferred.then - context", function() {
expect( 7 );
- var context = {};
+ var defer, piped, defer2, piped2,
+ context = {};
jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
return value * 3;
@@ -290,10 +291,10 @@ test( "jQuery.Deferred.then - context", function() {
strictEqual( this, context, "custom context of returned deferred correctly propagated" );
});
- var defer = jQuery.Deferred(),
- piped = defer.then(function( value ) {
- return value * 3;
- });
+ defer = jQuery.Deferred();
+ piped = defer.then(function( value ) {
+ return value * 3;
+ });
defer.resolve( 2 );
@@ -302,8 +303,8 @@ test( "jQuery.Deferred.then - context", function() {
strictEqual( value, 6, "proper value received" );
});
- var defer2 = jQuery.Deferred(),
- piped2 = defer2.then();
+ defer2 = jQuery.Deferred();
+ piped2 = defer2.then();
defer2.resolve( 2 );
@@ -319,7 +320,6 @@ test( "jQuery.when", function() {
// Some other objects
jQuery.each({
-
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
@@ -329,9 +329,7 @@ test( "jQuery.when", function() {
"null": null,
"undefined": undefined,
"a plain object": {}
-
}, function( message, value ) {
-
ok(
jQuery.isFunction(
jQuery.when( value ).done(function( resolveValue ) {
@@ -341,8 +339,7 @@ test( "jQuery.when", function() {
),
"Test " + message + " triggers the creation of a new Promise"
);
-
- } );
+ });
ok(
jQuery.isFunction(
@@ -354,14 +351,13 @@ test( "jQuery.when", function() {
"Test calling when with no parameter triggers the creation of a new Promise"
);
- var context = {};
+ var cache,
+ context = {};
jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
strictEqual( this, context, "when( promise ) propagates context" );
});
- var cache;
-
jQuery.each([ 1, 2, 3 ], function( k, i ) {
jQuery.when( cache || jQuery.Deferred(function() {
diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js
index c7d1281f2..d5dcf8859 100644
--- a/test/unit/dimensions.js
+++ b/test/unit/dimensions.js
@@ -1,16 +1,20 @@
-if ( jQuery.fn.width ) {
+(function() {
+
+if ( !jQuery.fn.width ) {
+ return;
+}
module("dimensions", { teardown: moduleTeardown });
-var pass = function( val ) {
+function pass( val ) {
return val;
-};
+}
-var fn = function( val ) {
+function fn( val ) {
return function() {
return val;
};
-};
+}
/*
======== local reference =======
@@ -24,10 +28,11 @@ var fn = function( val ) {
Returns a function that returns the value
*/
-var testWidth = function( val ) {
+function testWidth( val ) {
expect(9);
+ var $div, blah;
- var $div = jQuery("#nothiddendiv");
+ $div = jQuery("#nothiddendiv");
$div.width( val(30) );
equal($div.width(), 30, "Test set to 30 correctly");
$div.hide();
@@ -46,14 +51,14 @@ var testWidth = function( val ) {
equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" });
- var blah = jQuery("blah");
+ blah = jQuery("blah");
equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
equal( blah.width(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" );
-};
+}
test("width()", function() {
testWidth( pass );
@@ -75,10 +80,12 @@ test("width(Function(args))", function() {
equal( $div.width(), 31, "Make sure value was modified correctly." );
});
-var testHeight = function( val ) {
+function testHeight( val ) {
expect(9);
- var $div = jQuery("#nothiddendiv");
+ var $div, blah;
+
+ $div = jQuery("#nothiddendiv");
$div.height( val(30) );
equal($div.height(), 30, "Test set to 30 correctly");
$div.hide();
@@ -97,14 +104,14 @@ var testHeight = function( val ) {
equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" });
- var blah = jQuery("blah");
+ blah = jQuery("blah");
equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
equal( blah.height(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" );
-};
+}
test("height()", function() {
testHeight( pass );
@@ -129,13 +136,14 @@ test("height(Function(args))", function() {
test("innerWidth()", function() {
expect(6);
- var winWidth = jQuery( window ).width(),
+ var $div, div,
+ winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width();
equal(jQuery(window).innerWidth(), winWidth, "Test on window");
equal(jQuery(document).innerWidth(), docWidth, "Test on document");
- var $div = jQuery("#nothiddendiv");
+ $div = jQuery("#nothiddendiv");
// set styles
$div.css({
"margin": 10,
@@ -152,7 +160,7 @@ test("innerWidth()", function() {
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
- var div = jQuery( "<div>" );
+ div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
@@ -164,13 +172,14 @@ test("innerWidth()", function() {
test("innerHeight()", function() {
expect(6);
- var winHeight = jQuery( window ).height(),
+ var $div, div,
+ winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height();
equal(jQuery(window).innerHeight(), winHeight, "Test on window");
equal(jQuery(document).innerHeight(), docHeight, "Test on document");
- var $div = jQuery("#nothiddendiv");
+ $div = jQuery("#nothiddendiv");
// set styles
$div.css({
"margin": 10,
@@ -187,7 +196,7 @@ test("innerHeight()", function() {
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
- var div = jQuery( "<div>" );
+ div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
@@ -199,7 +208,8 @@ test("innerHeight()", function() {
test("outerWidth()", function() {
expect(11);
- var winWidth = jQuery( window ).width(),
+ var $div, div,
+ winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width();
equal( jQuery( window ).outerWidth(), winWidth, "Test on window without margin option" );
@@ -207,7 +217,7 @@ test("outerWidth()", function() {
equal( jQuery( document ).outerWidth(), docWidth, "Test on document without margin option" );
equal( jQuery( document ).outerWidth( true ), docWidth, "Test on document with margin option" );
- var $div = jQuery("#nothiddendiv");
+ $div = jQuery("#nothiddendiv");
$div.css("width", 30);
equal($div.outerWidth(), 30, "Test with only width set");
@@ -225,7 +235,7 @@ test("outerWidth()", function() {
// reset styles
$div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" });
- var div = jQuery( "<div>" );
+ div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
@@ -345,7 +355,8 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
test("outerHeight()", function() {
expect(11);
- var winHeight = jQuery( window ).height(),
+ var $div, div,
+ winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height();
@@ -354,7 +365,7 @@ test("outerHeight()", function() {
equal( jQuery( document ).outerHeight(), docHeight, "Test on document without margin option" );
equal( jQuery( document ).outerHeight( true ), docHeight, "Test on document with margin option" );
- var $div = jQuery("#nothiddendiv");
+ $div = jQuery("#nothiddendiv");
$div.css("height", 30);
equal($div.outerHeight(), 30, "Test with only width set");
@@ -371,7 +382,7 @@ test("outerHeight()", function() {
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
- var div = jQuery( "<div>" );
+ div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
@@ -459,4 +470,4 @@ testIframe( "dimensions/documentLarge", "window vs. large document", function( j
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
});
-}
+})();
diff --git a/test/unit/effects.js b/test/unit/effects.js
index e6d0bbb06..b8e49ba45 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -38,7 +38,7 @@ test("show() basic", 2, function() {
});
test("show()", 27, function () {
- var div,
+ var div, speeds, old, test,
hiddendiv = jQuery("div.hidden");
equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
@@ -56,7 +56,7 @@ test("show()", 27, function () {
notEqual(this.style.display, "none", "don't change any <div> with display block");
});
- var speeds = {
+ speeds = {
"null speed": null,
"undefined speed": undefined,
"false speed": false
@@ -65,7 +65,7 @@ test("show()", 27, function () {
jQuery.each(speeds, function(name, speed) {
var pass = true;
div.hide().show(speed).each(function() {
- if ( this.style.display == "none" ) {
+ if ( this.style.display === "none" ) {
pass = false;
}
});
@@ -86,10 +86,10 @@ test("show()", 27, function () {
// #show-tests * is set display: none in CSS
jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
- var old = jQuery("#test-table").show().css("display") !== "table";
+ old = jQuery("#test-table").show().css("display") !== "table";
jQuery("#test-table").remove();
- var test = {
+ test = {
"div" : "block",
"p" : "block",
"a" : "inline",
@@ -126,11 +126,12 @@ test("show(Number) - other displays", function() {
// #show-tests * is set display: none in CSS
jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
- var old = jQuery("#test-table").show().css("display") !== "table",
+ var test,
+ old = jQuery("#test-table").show().css("display") !== "table",
num = 0;
jQuery("#test-table").remove();
- var test = {
+ test = {
"div" : "block",
"p" : "block",
"a" : "inline",
@@ -195,8 +196,8 @@ test("Persist correct display value", function() {
test("animate(Hash, Object, Function)", function() {
expect(1);
stop();
- var hash = {opacity: "show"};
- var hashCopy = jQuery.extend({}, hash);
+ var hash = {opacity: "show"},
+ hashCopy = jQuery.extend({}, hash);
jQuery("#foo").animate(hash, 0, function() {
equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
start();
@@ -310,13 +311,14 @@ test("animate table width/height", function() {
test("animate table-row width/height", function() {
expect(3);
stop();
- var tr = jQuery("#table")
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
- .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
- .find("tr");
+ var displayMode,
+ tr = jQuery("#table")
+ .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
+ .find("tr");
// IE<8 uses "block" instead of the correct display type
- var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
+ displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
tr.animate({ width: 10, height: 10 }, 100, function() {
equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
@@ -329,13 +331,14 @@ test("animate table-row width/height", function() {
test("animate table-cell width/height", function() {
expect(3);
stop();
- var td = jQuery("#table")
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
- .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
- .find("td");
+ var displayMode,
+ td = jQuery("#table")
+ .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
+ .find("td");
// IE<8 uses "block" instead of the correct display type
- var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
+ displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
td.animate({ width: 10, height: 10 }, 100, function() {
equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
@@ -445,7 +448,7 @@ asyncTest( "animate option { queue: 'name' }", function() {
equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
}
- }).queue( "name", function( next ) {
+ }).queue( "name", function() {
// last callback function
deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
@@ -466,7 +469,9 @@ asyncTest( "animate option { queue: 'name' }", function() {
test("animate with no properties", function() {
expect(2);
- var divs = jQuery("div"), count = 0;
+ var foo,
+ divs = jQuery("div"),
+ count = 0;
divs.animate({}, function(){
count++;
@@ -476,7 +481,7 @@ test("animate with no properties", function() {
stop();
- var foo = jQuery("#foo");
+ foo = jQuery("#foo");
foo.animate({});
foo.animate({top: 10}, 100, function(){
@@ -490,7 +495,9 @@ test("animate duration 0", function() {
stop();
- var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
+ var $elem,
+ $elems = jQuery([{ a:0 },{ a:0 }]),
+ counter = 0;
equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
@@ -522,7 +529,7 @@ test("animate duration 0", function() {
start();
});
- var $elem = jQuery("<div />");
+ $elem = jQuery("<div />");
$elem.show(0, function(){
ok(true, "Show callback with no duration");
});
@@ -562,7 +569,8 @@ test("stop()", function() {
expect( 4 );
stop();
- var $foo = jQuery("#foo"),
+ var $one, $two,
+ $foo = jQuery("#foo"),
tests = 2,
w = 0;
@@ -586,8 +594,8 @@ test("stop()", function() {
}, 100);
}, 100);
- var $one = jQuery("#fadein");
- var $two = jQuery("#show");
+ $one = jQuery("#fadein");
+ $two = jQuery("#show");
$one.fadeTo(100, 0, function() {
$one.stop();
});
@@ -640,8 +648,8 @@ test("stop(clearQueue)", function() {
expect(4);
stop();
- var $foo = jQuery("#foo");
- var w = 0;
+ var $foo = jQuery("#foo"),
+ w = 0;
$foo.hide().css( "width", 200 ).css("width");
$foo.animate({ "width": "show" }, 1000);
@@ -649,11 +657,11 @@ test("stop(clearQueue)", function() {
$foo.animate({ "width": "show" }, 1000);
setTimeout(function(){
var nw = $foo.css("width");
- ok( parseFloat( nw ) != w, "An animation occurred " + nw + " " + w + "px");
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
$foo.stop(true);
nw = $foo.css("width");
- ok( parseFloat( nw ) != w, "Stop didn't reset the animation " + nw + " " + w + "px");
+ ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
equal( $foo.queue().length, 0, "The animation queue was cleared" );
setTimeout(function(){
@@ -667,8 +675,8 @@ test("stop(clearQueue, gotoEnd)", function() {
expect(1);
stop();
- var $foo = jQuery("#foo");
- var w = 0;
+ var $foo = jQuery("#foo"),
+ w = 0;
$foo.hide().css( "width", 200 ).css("width");
$foo.animate({ width: "show" }, 1000);
@@ -677,7 +685,7 @@ test("stop(clearQueue, gotoEnd)", function() {
$foo.animate({ width: "hide" }, 1000);
setTimeout(function(){
var nw = $foo.css("width");
- ok( parseFloat( nw ) != w, "An animation occurred " + nw + " " + w + "px");
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
$foo.stop(false, true);
nw = $foo.css("width");
@@ -872,66 +880,67 @@ jQuery.each({
},
"100": function( elem, prop ) {
jQuery( elem ).addClass( "wide" + prop );
- return prop == "opacity" ? 1 : 100;
+ return prop === "opacity" ? 1 : 100;
},
"50": function( elem, prop ) {
- return prop == "opacity" ? 0.50 : 50;
+ return prop === "opacity" ? 0.50 : 50;
},
- "0": function( elem, prop ) {
+ "0": function( elem ) {
jQuery( elem ).addClass( "noback" );
return 0;
}
}, function( tn, t ) {
test(fn + " to " + tn, function() {
- var elem = jQuery.makeTest( fn + " to " + tn );
-
- var t_w = t( elem, "width" );
- var f_w = f( elem, "width" );
- var t_h = t( elem, "height" );
- var f_h = f( elem, "height" );
- var t_o = t( elem, "opacity" );
- var f_o = f( elem, "opacity" );
+ var num, anim,
+ elem = jQuery.makeTest( fn + " to " + tn ),
+ t_w = t( elem, "width" ),
+ f_w = f( elem, "width" ),
+ t_h = t( elem, "height" ),
+ f_h = f( elem, "height" ),
+ t_o = t( elem, "opacity" ),
+ f_o = f( elem, "opacity" );
if ( f_o === "" ) {
f_o = 1;
}
- var num = 0;
+ num = 0;
// TODO: uncrowd this
- if ( t_h == "show" ) {num++;}
- if ( t_w == "show" ) {num++;}
- if ( t_w == "hide" || t_w == "show" ) {num++;}
- if ( t_h == "hide" || t_h == "show" ) {num++;}
- if ( t_o == "hide" || t_o == "show" ) {num++;}
- if ( t_w == "hide" ) {num++;}
- if ( t_o.constructor == Number ) {num += 2;}
- if ( t_w.constructor == Number ) {num += 2;}
- if ( t_h.constructor == Number ) {num +=2;}
+ if ( t_h === "show" ) {num++;}
+ if ( t_w === "show" ) {num++;}
+ if ( t_w === "hide" || t_w === "show" ) {num++;}
+ if ( t_h === "hide" || t_h === "show" ) {num++;}
+ if ( t_o === "hide" || t_o === "show" ) {num++;}
+ if ( t_w === "hide" ) {num++;}
+ if ( t_o.constructor === Number ) {num += 2;}
+ if ( t_w.constructor === Number ) {num += 2;}
+ if ( t_h.constructor === Number ) {num +=2;}
expect( num );
stop();
- var anim = { width: t_w, height: t_h, opacity: t_o };
+ anim = { width: t_w, height: t_h, opacity: t_o };
elem.animate(anim, 50);
jQuery.when( elem ).done(function( elem ) {
+ var cur_o, cur_w, cur_h, old_h;
elem = elem[ 0 ];
- if ( t_w == "show" ) {
+ if ( t_w === "show" ) {
equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
}
- if ( t_w == "hide" || t_w == "show" ) {
+ if ( t_w === "hide" || t_w === "show" ) {
ok( f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf( f_w ) === 0, "Width must be reset to " + f_w + ": " + elem.style.width );
}
- if ( t_h == "hide" || t_h == "show" ) {
+ if ( t_h === "hide" || t_h === "show" ) {
ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height );
}
- var cur_o = jQuery.style(elem, "opacity");
+ cur_o = jQuery.style(elem, "opacity");
if ( f_o !== jQuery.css(elem, "opacity") ) {
f_o = f( elem, "opacity" );
@@ -947,38 +956,38 @@ jQuery.each({
cur_o = 1;
}
- if ( t_o == "hide" || t_o == "show" ) {
+ if ( t_o === "hide" || t_o === "show" ) {
equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
}
- if ( t_w == "hide" ) {
+ if ( t_w === "hide" ) {
equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
}
- if ( t_o.constructor == Number ) {
+ if ( t_o.constructor === Number ) {
equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
- ok( jQuery.css(elem, "opacity") !== "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
+ ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
}
- if ( t_w.constructor == Number ) {
+ if ( t_w.constructor === Number ) {
equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
- var cur_w = jQuery.css( elem,"width" );
+ cur_w = jQuery.css( elem,"width" );
- ok( elem.style.width !== "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
+ ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
}
- if ( t_h.constructor == Number ) {
+ if ( t_h.constructor === Number ) {
equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
- var cur_h = jQuery.css( elem,"height" );
+ cur_h = jQuery.css( elem,"height" );
- ok( elem.style.height !== "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
+ ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
}
- if ( t_h == "show" ) {
- var old_h = jQuery.css( elem, "height" );
+ if ( t_h === "show" ) {
+ old_h = jQuery.css( elem, "height" );
jQuery( elem ).append("<br/>Some more text<br/>and some more...");
if ( /Auto/.test( fn ) ) {
@@ -1364,7 +1373,8 @@ test("Do not append px to 'fill-opacity' #9548", 1, function() {
// Start 1.8 Animation tests
asyncTest( "jQuery.Animation( object, props, opts )", 4, function() {
- var testObject = {
+ var animation,
+ testObject = {
"foo": 0,
"bar": 1,
"width": 100
@@ -1375,7 +1385,7 @@ asyncTest( "jQuery.Animation( object, props, opts )", 4, function() {
"width": 200
};
- var animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
+ animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
animation.done(function() {
for ( var prop in testDest ) {
equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
@@ -2008,7 +2018,7 @@ test( ".finish( \"custom\" ) - custom queue animations", function() {
});
test( ".finish() calls finish of custom queue functions", function() {
- function queueTester( next ) {
+ function queueTester() {
}
var div = jQuery( "<div>" );
diff --git a/test/unit/event.js b/test/unit/event.js
index 1a1a5652e..9ea75fb81 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -6,12 +6,12 @@ test("null or undefined handler", function() {
try {
jQuery("#firstp").on( "click", null );
ok(true, "Passing a null handler will not throw an exception");
- } catch (e) {}
+ } catch ( e ) {}
try {
jQuery("#firstp").on( "click", undefined );
ok(true, "Passing an undefined handler will not throw an exception");
- } catch (e) {}
+ } catch ( e ) {}
});
test("on() with non-null,defined data", function() {
@@ -41,7 +41,7 @@ test("Handler changes and .trigger() order", function() {
path = "";
markup
- .find( "*" ).addBack().on( "click", function( e ) {
+ .find( "*" ).addBack().on( "click", function() {
path += this.nodeName.toLowerCase() + " ";
})
.filter( "b" ).on( "click", function( e ) {
@@ -60,7 +60,9 @@ test("Handler changes and .trigger() order", function() {
test("on(), with data", function() {
expect(4);
- var handler = function(event) {
+ var test, handler, handler2;
+
+ handler = function(event) {
ok( event.data, "on() with data, check passed data exists" );
equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
};
@@ -68,8 +70,8 @@ test("on(), with data", function() {
ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
- var test = function(){};
- var handler2 = function(event) {
+ test = function(){};
+ handler2 = function(event) {
equal( event.data, test, "on() with function data, Check value of passed data" );
};
jQuery("#firstp").on("click", test, handler2).trigger("click").off("click", handler2);
@@ -99,17 +101,18 @@ test("on(), with data, trigger with data", function() {
test("on(), multiple events at once", function() {
expect(2);
- var clickCounter = 0,
+ var handler,
+ clickCounter = 0,
mouseoverCounter = 0;
- var handler = function(event) {
- if (event.type == "click") {
+ handler = function(event) {
+ if (event.type === "click") {
clickCounter += 1;
}
- else if (event.type == "mouseover") {
+ else if (event.type === "mouseover") {
mouseoverCounter += 1;
}
-
};
+
jQuery("#firstp").on("click mouseover", handler).trigger("click").trigger("mouseover");
equal( clickCounter, 1, "on() with multiple events at once" );
equal( mouseoverCounter, 1, "on() with multiple events at once" );
@@ -119,7 +122,7 @@ test("on(), five events at once", function() {
expect(1);
var count = 0,
- handler = function(event) {
+ handler = function() {
count++;
};
@@ -134,9 +137,10 @@ test("on(), five events at once", function() {
test("on(), multiple events at once and namespaces", function() {
expect(7);
- var cur, obj = {};
+ var cur, div,
+ obj = {};
- var div = jQuery("<div/>").on("focusin.a", function(e) {
+ div = jQuery("<div/>").on("focusin.a", function(e) {
equal( e.type, cur, "Verify right single event was fired." );
});
@@ -178,7 +182,7 @@ test("on(), namespace with special add", function() {
expect(27);
var i = 0,
- div = jQuery("<div/>").appendTo("#qunit-fixture").on( "test", function(e) {
+ div = jQuery("<div/>").appendTo("#qunit-fixture").on( "test", function() {
ok( true, "Test event fired." );
});
@@ -227,7 +231,7 @@ test("on(), namespace with special add", function() {
// Should trigger 4
div.off("test");
- div = jQuery("<div/>").on( "test", function( e ) {
+ div = jQuery("<div/>").on( "test", function() {
ok( true, "Test event fired." );
});
@@ -248,23 +252,22 @@ test("on(), no data", function() {
test("on/one/off(Object)", function(){
expect(6);
- var clickCounter = 0, mouseoverCounter = 0;
- function handler(event) {
- if (event.type == "click") {
+ var $elem,
+ clickCounter = 0,
+ mouseoverCounter = 0;
+ function handler(event) {
+ if (event.type === "click") {
clickCounter++;
- }
- else if (event.type == "mouseover") {
+ } else if (event.type === "mouseover") {
mouseoverCounter++;
}
-
}
function handlerWithData(event) {
- if (event.type == "click") {
+ if (event.type === "click") {
clickCounter += event.data;
- }
- else if (event.type == "mouseover") {
+ } else if (event.type === "mouseover") {
mouseoverCounter += event.data;
}
}
@@ -273,7 +276,7 @@ test("on/one/off(Object)", function(){
$elem.trigger("click").trigger("mouseover");
}
- var $elem = jQuery("#firstp")
+ $elem = jQuery("#firstp")
// Regular bind
.on({
"click":handler,
@@ -307,12 +310,13 @@ test("on/one/off(Object)", function(){
test("on/off(Object), on/off(Object, String)", function() {
expect(6);
- var clickCounter = 0,
+ var events,
+ clickCounter = 0,
mouseoverCounter = 0,
$p = jQuery("#firstp"),
$a = $p.find("a").eq(0);
- var events = {
+ events = {
"click": function( event ) {
clickCounter += ( event.data || 1 );
},
@@ -357,7 +361,7 @@ test("on immediate propagation", function() {
lastClick = "click1";
e.stopImmediatePropagation();
});
- jQuery( document ).on( "click", "#firstp a", function(e) {
+ jQuery( document ).on( "click", "#firstp a", function() {
lastClick = "click2";
});
$a.trigger( "click" );
@@ -369,7 +373,7 @@ test("on immediate propagation", function() {
lastClick = "click1";
e.stopImmediatePropagation();
});
- $p.on( "click", "a", function(e) {
+ $p.on( "click", "a", function() {
lastClick = "click2";
});
$a.trigger( "click" );
@@ -409,7 +413,7 @@ test("on bubbling, isDefaultPrevented", function() {
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
- $anchor2.on( "click", function(e) {
+ $anchor2.on( "click", function() {
// Let the default action occur
});
$main.on("click", "#foo", function(e) {
@@ -445,7 +449,7 @@ test("on(), trigger change on select", function() {
test("on(), namespaced events, cloned events", 18, function() {
var firstp = jQuery( "#firstp" );
- firstp.on("custom.test",function(e){
+ firstp.on("custom.test",function(){
ok(false, "Custom event triggered");
});
@@ -507,22 +511,22 @@ test("on(), multi-namespaced events", function() {
];
function check(name, msg){
- deepEqual(name, order.shift(), msg);
+ deepEqual( name, order.shift(), msg );
}
- jQuery("#firstp").on("custom.test",function(e){
+ jQuery("#firstp").on("custom.test",function() {
check("custom.test", "Custom event triggered");
});
- jQuery("#firstp").on("custom.test2",function(e){
+ jQuery("#firstp").on("custom.test2",function() {
check("custom.test2", "Custom event triggered");
});
- jQuery("#firstp").on("click.test",function(e){
+ jQuery("#firstp").on("click.test",function() {
check("click.test", "Normal click triggered");
});
- jQuery("#firstp").on("click.test.abc",function(e){
+ jQuery("#firstp").on("click.test.abc",function() {
check("click.test.abc", "Namespaced click triggered");
});
@@ -611,7 +615,7 @@ test("on(), with different this object", function() {
expect(4);
var thisObject = { myThis: true },
data = { myData: true },
- handler1 = function( event ) {
+ handler1 = function() {
equal( this, thisObject, "on() with different this object" );
},
handler2 = function( event ) {
@@ -630,7 +634,7 @@ test("on(name, false), off(name, false)", function() {
expect(3);
var main = 0;
- jQuery("#qunit-fixture").on("click", function(e){ main++; });
+ jQuery("#qunit-fixture").on("click", function(){ main++; });
jQuery("#ap").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
@@ -653,7 +657,7 @@ test("on(name, selector, false), off(name, selector, false)", function() {
var main = 0;
- jQuery("#qunit-fixture").on("click", "#ap", function(e){ main++; });
+ jQuery("#qunit-fixture").on("click", "#ap", function(){ main++; });
jQuery("#ap").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
@@ -672,7 +676,8 @@ test("on(name, selector, false), off(name, selector, false)", function() {
test("on()/trigger()/off() on plain object", function() {
expect( 7 );
- var obj = {};
+ var events,
+ obj = {};
// Make sure it doesn't complain when no events are found
jQuery(obj).trigger("test");
@@ -689,7 +694,7 @@ test("on()/trigger()/off() on plain object", function() {
}
});
- var events = jQuery._data(obj, "events");
+ events = jQuery._data(obj, "events");
ok( events, "Object has events bound." );
equal( obj["events"], undefined, "Events object on plain objects is not events" );
equal( obj["test"], undefined, "Make sure that test event is not on the plain object." );
@@ -716,8 +721,8 @@ test("on()/trigger()/off() on plain object", function() {
test("off(type)", function() {
expect( 1 );
- var $elem = jQuery("#firstp"),
- message;
+ var message, func,
+ $elem = jQuery("#firstp");
function error(){
ok( false, message );
@@ -751,7 +756,7 @@ test("off(type)", function() {
jQuery( document ).on( "click", function(){
ok( true, "called handler after selective removal");
});
- var func = function(){ };
+ func = function() {};
jQuery( document )
.on( "click", func )
.off( "click", func )
@@ -800,8 +805,8 @@ if ( jQuery.fn.hover ) {
expect(1);
var times = 0,
- handler1 = function( event ) { ++times; },
- handler2 = function( event ) { ++times; };
+ handler1 = function() { ++times; },
+ handler2 = function() { ++times; };
jQuery("#firstp")
.hover(handler1, handler2)
@@ -876,7 +881,8 @@ if ( jQuery.fn.click ) {
test("trigger() shortcuts", function() {
expect(6);
- var elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
+ var counter, clickCounter,
+ elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
elem.find("a").on("click", function() {
var close = jQuery("spanx", this); // same with jQuery(this).find("span");
equal( close.length, 0, "Context element does not exist, length must be zero" );
@@ -891,15 +897,15 @@ if ( jQuery.fn.click ) {
ok( true, "click event handler for checkbox gets fired twice, see #815" );
}).click();
- var counter = 0;
- jQuery("#firstp")[0].onclick = function(event) {
+ counter = 0;
+ jQuery("#firstp")[0].onclick = function() {
counter++;
};
jQuery("#firstp").click();
equal( counter, 1, "Check that click, triggers onclick event handler also" );
- var clickCounter = 0;
- jQuery("#simon1")[0].onclick = function(event) {
+ clickCounter = 0;
+ jQuery("#simon1")[0].onclick = function() {
clickCounter++;
};
jQuery("#simon1").click();
@@ -925,11 +931,11 @@ test("trigger() bubbling", function() {
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
- jQuery(window).on("click", function(e){ win++; });
- jQuery(document).on("click", function(e){ if ( e.target !== document) { doc++; } });
- jQuery("html").on("click", function(e){ html++; });
- jQuery("body").on("click", function(e){ body++; });
- jQuery("#qunit-fixture").on("click", function(e){ main++; });
+ jQuery(window).on("click", function(){ win++; });
+ jQuery(document).on("click", function( e ){ if ( e.target !== document) { doc++; } });
+ jQuery("html").on("click", function(){ html++; });
+ jQuery("body").on("click", function(){ body++; });
+ jQuery("#qunit-fixture").on("click", function(){ main++; });
jQuery("#ap").on("click", function(){ ap++; return false; });
jQuery("html").trigger("click");
@@ -968,7 +974,8 @@ test("trigger() bubbling", function() {
test("trigger(type, [data], [fn])", function() {
expect(16);
- var handler = function(event, a, b, c) {
+ var $elem, pass, form, elem2,
+ handler = function(event, a, b, c) {
equal( event.type, "click", "check passed data" );
equal( a, 1, "check passed data" );
equal( b, "2", "check passed data" );
@@ -976,7 +983,7 @@ test("trigger(type, [data], [fn])", function() {
return "test";
};
- var $elem = jQuery("#firstp");
+ $elem = jQuery("#firstp");
// Simulate a "native" click
$elem[0].click = function(){
@@ -1011,12 +1018,12 @@ test("trigger(type, [data], [fn])", function() {
// Triggers 5
equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
- var pass = true, elem2;
+ pass = true;
try {
elem2 = jQuery("#form input").eq(0);
elem2.get(0).style.display = "none";
elem2.trigger("focus");
- } catch(e) {
+ } catch( e ) {
pass = false;
}
ok( pass, "Trigger focus on hidden element" );
@@ -1024,12 +1031,12 @@ test("trigger(type, [data], [fn])", function() {
pass = true;
try {
jQuery("#qunit-fixture table").eq(0).on("test:test", function(){}).trigger("test:test");
- } catch (e) {
+ } catch ( e ) {
pass = false;
}
ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
- var form = jQuery("<form action=''></form>").appendTo("body");
+ form = jQuery("<form action=''></form>").appendTo("body");
// Make sure it can be prevented locally
form.on( "submit", function(){
@@ -1126,13 +1133,14 @@ test( "change event bubbles on copied forms (#11796)", function(){
test("trigger(eventObject, [data], [fn])", function() {
expect(28);
- var $parent = jQuery("<div id='par' />").appendTo("body"),
+ var event,
+ $parent = jQuery("<div id='par' />").appendTo("body"),
$child = jQuery("<p id='child'>foo</p>").appendTo( $parent );
$parent.get( 0 ).style.display = "none";
- var event = jQuery.Event("noNew");
- ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
+ event = jQuery.Event("noNew");
+ ok( event !== window, "Instantiate jQuery.Event without the 'new' keyword" );
equal( event.type, "noNew", "Verify its type" );
equal( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
@@ -1149,7 +1157,7 @@ test("trigger(eventObject, [data], [fn])", function() {
equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
- $parent.on("foo",function(e){
+ $parent.on("foo",function( e ) {
// Tries bubbling
equal( e.type, "foo", "Verify event type when passed passing an event object" );
equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
@@ -1470,7 +1478,8 @@ test("jQuery.Event properties", function(){
test(".on()/.off()", function() {
expect(65);
- var submit = 0, div = 0, livea = 0, liveb = 0;
+ var event, clicked, hash, called, livec, lived, livee,
+ submit = 0, div = 0, livea = 0, liveb = 0;
jQuery("#body").on("submit", "#qunit-fixture div", function(){ submit++; return false; });
jQuery("#body").on("click", "#qunit-fixture div", function(){ div++; });
@@ -1535,7 +1544,7 @@ test(".on()/.off()", function() {
// Make sure that stopPropagation doesn't stop live events
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("#body").on("click", "div#nothiddendivchild", function(e){ liveb++; e.stopPropagation(); });
+ jQuery("#body").on("click", "div#nothiddendivchild", function( e ){ liveb++; e.stopPropagation(); });
jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "stopPropagation Click on inner div" );
equal( div, 1, "stopPropagation Click on inner div" );
@@ -1544,7 +1553,7 @@ test(".on()/.off()", function() {
// Make sure click events only fire with primary click
submit = 0; div = 0; livea = 0; liveb = 0;
- var event = jQuery.Event("click");
+ event = jQuery.Event("click");
event.button = 1;
jQuery("div#nothiddendiv").trigger(event);
@@ -1556,8 +1565,8 @@ test(".on()/.off()", function() {
jQuery("#body").off("submit", "#qunit-fixture div");
// Test binding with a different context
- var clicked = 0;
- jQuery("#qunit-fixture").on("click", "#foo", function(e){ clicked++; });
+ clicked = 0;
+ jQuery("#qunit-fixture").on("click", "#foo", function(){ clicked++; });
jQuery("#qunit-fixture div").trigger("click");
jQuery("#foo").trigger("click");
jQuery("#qunit-fixture").trigger("click");
@@ -1570,7 +1579,7 @@ test(".on()/.off()", function() {
equal( clicked, 2, "off with a context");
// Test binding with event data
- jQuery("#body").on("click", "#foo", true, function(e){ equal( e.data, true, "on with event data" ); });
+ jQuery("#body").on("click", "#foo", true, function( e ){ equal( e.data, true, "on with event data" ); });
jQuery("#foo").trigger("click");
jQuery("#body").off("click", "#foo");
@@ -1580,7 +1589,7 @@ test(".on()/.off()", function() {
jQuery("#body").off("click", "#foo");
// Test binding with different this object
- jQuery("#body").on("click", "#foo", jQuery.proxy(function(e){ equal( this["foo"], "bar", "on with event scope" ); }, { "foo": "bar" }));
+ jQuery("#body").on("click", "#foo", jQuery.proxy(function(){ equal( this["foo"], "bar", "on with event scope" ); }, { "foo": "bar" }));
jQuery("#foo").trigger("click");
jQuery("#body").off("click", "#foo");
@@ -1595,7 +1604,7 @@ test(".on()/.off()", function() {
// Verify that return false prevents default action
jQuery("#body").on("click", "#anchor2", function(){ return false; });
- var hash = window.location.hash;
+ hash = window.location.hash;
jQuery("#anchor2").trigger("click");
equal( window.location.hash, hash, "return false worked" );
jQuery("#body").off("click", "#anchor2");
@@ -1608,7 +1617,7 @@ test(".on()/.off()", function() {
jQuery("#body").off("click", "#anchor2");
// Test binding the same handler to multiple points
- var called = 0;
+ called = 0;
function callback(){ called++; return false; }
jQuery("#body").on("click", "#nothiddendiv", callback);
@@ -1652,10 +1661,10 @@ test(".on()/.off()", function() {
// Make sure we don't loose the target by DOM modifications
// after the bubble already reached the liveHandler
- var livec = 0;
+ livec = 0;
jQuery("#nothiddendivchild").html("<span></span>");
- jQuery("#body").on("click", "#nothiddendivchild", function(e){ jQuery("#nothiddendivchild").html(""); });
+ jQuery("#body").on("click", "#nothiddendivchild", function(){ jQuery("#nothiddendivchild").html(""); });
jQuery("#body").on("click", "#nothiddendivchild", function(e){ if(e.target) {livec++;} });
jQuery("#nothiddendiv span").trigger("click");
@@ -1667,7 +1676,8 @@ test(".on()/.off()", function() {
// Verify that .live() occurs and cancel bubble in the same order as
// we would expect .on() and .click() without delegation
- var lived = 0, livee = 0;
+ lived = 0;
+ livee = 0;
// bind one pair in one order
jQuery("#body").on("click", "span#liveSpan1 a", function(){ lived++; return false; });
@@ -1691,7 +1701,7 @@ test(".on()/.off()", function() {
jQuery("#body").off("click", "**");
// Test this, target and currentTarget are correct
- jQuery("#body").on("click", "span#liveSpan1", function(e){
+ jQuery("#body").on("click", "span#liveSpan1", function( e ) {
equal( this.id, "liveSpan1", "Check the this within a on handler" );
equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a on handler" );
equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a on handler" );
@@ -1705,7 +1715,7 @@ test(".on()/.off()", function() {
// Work with deep selectors
livee = 0;
- function clickB(){ livee++; }
+ function clickB() { livee++; }
jQuery("#body").on("click", "#nothiddendiv div", function(){ livee++; });
jQuery("#body").on("click", "#nothiddendiv div", clickB);
@@ -1793,7 +1803,7 @@ test( "delegated event with selector matching Object.prototype property (#13203)
var matched = 0;
- jQuery("#foo").on( "click", "toString", function( e ) {
+ jQuery("#foo").on( "click", "toString", function() {
matched++;
});
@@ -1842,8 +1852,8 @@ test("off all bound delegated events", function(){
test("on with multiple delegated events", function(){
expect(1);
- var count = 0;
- var div = jQuery("#body");
+ var count = 0,
+ div = jQuery("#body");
div.on("click submit", "div#nothiddendivchild", function(){ count++; });
@@ -1858,17 +1868,21 @@ test("on with multiple delegated events", function(){
test("delegated on with change", function(){
expect(8);
- var selectChange = 0, checkboxChange = 0;
+ var select, checkbox, checkboxFunction,
+ text, textChange, oldTextVal,
+ password, passwordChange, oldPasswordVal,
+ selectChange = 0,
+ checkboxChange = 0;
- var select = jQuery("select[name='S1']");
+ select = jQuery("select[name='S1']");
jQuery("#body").on("change", "select[name='S1']", function() {
selectChange++;
});
- var checkbox = jQuery("#check2"),
- checkboxFunction = function(){
- checkboxChange++;
- };
+ checkbox = jQuery("#check2");
+ checkboxFunction = function(){
+ checkboxChange++;
+ };
jQuery("#body").on("change", "#check2", checkboxFunction);
// test click on select
@@ -1890,7 +1904,10 @@ test("delegated on with change", function(){
equal( checkboxChange, 1, "Change on checkbox." );
// test blur/focus on text
- var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
+ text = jQuery("#name");
+ textChange = 0;
+ oldTextVal = text.val();
+
jQuery("#body").on("change", "#name", function() {
textChange++;
});
@@ -1903,7 +1920,9 @@ test("delegated on with change", function(){
jQuery("#body").off("change", "#name");
// test blur/focus on password
- var password = jQuery("#name"), passwordChange = 0, oldPasswordVal = password.val();
+ password = jQuery("#name");
+ passwordChange = 0;
+ oldPasswordVal = password.val();
jQuery("#body").on("change", "#name", function() {
passwordChange++;
});
@@ -1964,7 +1983,7 @@ test("delegated off() with only namespaces", function() {
var $delegate = jQuery("#liveHandlerOrder"),
count = 0;
- $delegate.on("click.ns", "a", function(e) {
+ $delegate.on("click.ns", "a", function() {
count++;
});
@@ -1984,7 +2003,7 @@ test("Non DOM element events", function() {
var o = {};
- jQuery(o).on("nonelementobj", function(e) {
+ jQuery(o).on("nonelementobj", function() {
ok( true, "Event on non-DOM object triggered" );
});
@@ -2065,9 +2084,8 @@ test("custom events with colons (#3533, #8272)", function() {
test(".on and .off", function() {
expect(9);
- var counter, mixfn;
-
- var $onandoff = jQuery("<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>").appendTo("body");
+ var counter, mixfn, data,
+ $onandoff = jQuery("<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>").appendTo("body");
// Simple case
jQuery( "#onandoff" )
@@ -2156,7 +2174,7 @@ test(".on and .off", function() {
.off( "click cluck" );
// We should have removed all the event handlers ... kinda hacky way to check this
- var data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
+ data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
equal( data["events"], undefined, "no events left" );
$onandoff.remove();
@@ -2236,10 +2254,9 @@ test("special on name mapping", function() {
test(".on and .off, selective mixed removal (#10705)", function() {
expect(7);
- var clockout = 0,
- timingx = function( e ) {
- ok( true, "triggered " + e.type );
- };
+ var timingx = function( e ) {
+ ok( true, "triggered " + e.type );
+ };
jQuery( "<p>Strange Pursuit</p>" )
.on( "click", timingx )
@@ -2276,7 +2293,7 @@ test("clone() delegated events (#11076)", function() {
expect(3);
var counter = { "center": 0, "fold": 0, "centerfold": 0 },
- clicked = function( event ) {
+ clicked = function() {
counter[ jQuery(this).text().replace(/\s+/, "") ]++;
},
table =
@@ -2327,9 +2344,9 @@ test("checkbox state (#3827)", function() {
test("focus-blur order (#12868)", function() {
expect( 5 );
- var $text = jQuery("#text1"),
- $radio = jQuery("#radio1").trigger("focus"),
- order;
+ var order,
+ $text = jQuery("#text1"),
+ $radio = jQuery("#radio1").trigger("focus");
// IE6-10 fire focus/blur events asynchronously; this is the resulting mess.
// IE's browser window must be topmost for this to work properly!!
@@ -2394,7 +2411,7 @@ test("fixHooks extensions", function() {
$fixture.off( "click" );
jQuery.event.fixHooks.click = {
- filter: function( event, originalEvent ) {
+ filter: function( event ) {
event.blurrinessLevel = 42;
return event;
}
@@ -2505,19 +2522,17 @@ if ( hasPHP ) {
test("change handler should be detached from element", function() {
expect( 2 );
- var $fixture = jQuery( "<input type='text' id='change-ie-leak' />" ).appendTo( "body" );
-
- var originRemoveEvent = jQuery.removeEvent;
-
- var wrapperRemoveEvent = function(elem, type, handle){
- equal("change", type, "Event handler for 'change' event should be removed");
- equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element");
- originRemoveEvent(elem, type, handle);
- };
+ var $fixture = jQuery( "<input type='text' id='change-ie-leak' />" ).appendTo( "body" ),
+ originRemoveEvent = jQuery.removeEvent,
+ wrapperRemoveEvent = function(elem, type, handle){
+ equal("change", type, "Event handler for 'change' event should be removed");
+ equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element");
+ originRemoveEvent(elem, type, handle);
+ };
jQuery.removeEvent = wrapperRemoveEvent ;
- $fixture.on( "change", function( event ) {});
+ $fixture.on( "change", function() {});
$fixture.off( "change" );
$fixture.remove();
@@ -2559,7 +2574,7 @@ test( "Namespace preserved when passed an Event (#12739)", function() {
});
}
})
- .on( "foo.bar2", function( e ) {
+ .on( "foo.bar2", function() {
ok( false, "foo.bar2 called on trigger " + triggered + " id " + this.id );
});
@@ -2589,11 +2604,11 @@ test( "make sure events cloned correctly", 18, function() {
ok( result, "Change on original child element though delegation is fired" );
});
- p.on("click", function( event, result ) {
+ p.on("click", function() {
ok( true, "Click on original child element is fired" );
});
- checkbox.on("change", function( event, result ) {
+ checkbox.on("change", function() {
ok( true, "Change on original child element is fired" );
});
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index a15c4c5ad..8a32dac20 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -3,19 +3,19 @@ module( "manipulation", {
});
// Ensure that an extended Array prototype doesn't break jQuery
-Array.prototype.arrayProtoFn = function( arg ) {
+Array.prototype.arrayProtoFn = function() {
throw("arrayProtoFn should not be called");
};
-var manipulationBareObj = function( value ) {
+function manipulationBareObj( value ) {
return value;
-};
+}
-var manipulationFunctionReturningObj = function( value ) {
- return (function() {
+function manipulationFunctionReturningObj( value ) {
+ return function() {
return value;
- });
-};
+ };
+}
/*
======== local reference =======
@@ -62,7 +62,7 @@ test( "text(undefined)", function() {
equal( jQuery("#foo").text("<div").text(undefined)[ 0 ].innerHTML, "&lt;div", ".text(undefined) is chainable (#5571)" );
});
-var testText = function( valueObj ) {
+function testText( valueObj ) {
expect( 4 );
@@ -79,7 +79,7 @@ var testText = function( valueObj ) {
// Blackberry 4.6 doesn't maintain comments in the DOM
equal( jQuery("#nonnodes")[ 0 ].childNodes.length < 3 ? 8 : j[ 2 ].nodeType, 8, "Check node,textnode,comment with text()" );
-};
+}
test( "text(String)", function() {
testText( manipulationBareObj );
@@ -103,7 +103,7 @@ test( "text(Function) with incoming value", function() {
equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
});
-var testAppendForObject = function( valueObj, isFragment ) {
+function testAppendForObject( valueObj, isFragment ) {
var $base,
type = isFragment ? " (DocumentFragment)" : " (Element)",
text = "This link has class=\"blog\": Simon Willison's Weblog",
@@ -175,9 +175,9 @@ var testAppendForObject = function( valueObj, isFragment ) {
1,
"Check for appending a form (#910)" + type
);
-};
+}
-var testAppend = function( valueObj ) {
+function testAppend( valueObj ) {
expect( 78 );
@@ -286,7 +286,7 @@ var testAppend = function( valueObj ) {
equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" );
equal( jQuery("<div/>").append( valueObj("option<area/>") )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
-};
+}
test( "append(String|Element|Array<Element>|jQuery)", function() {
testAppend( manipulationBareObj );
@@ -577,7 +577,7 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );
});
-var testPrepend = function( val ) {
+function testPrepend( val ) {
expect( 6 );
@@ -608,7 +608,7 @@ var testPrepend = function( val ) {
expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend( val([ jQuery("#first"), jQuery("#yahoo, #google") ]) );
equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" );
-};
+}
test( "prepend(String|Element|Array<Element>|jQuery)", function() {
testPrepend( manipulationBareObj );
@@ -707,7 +707,7 @@ test( "prependTo(String|Element|Array<Element>|jQuery)", function() {
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
});
-var testBefore = function( val ) {
+function testBefore( val ) {
expect( 7 );
@@ -740,7 +740,7 @@ var testBefore = function( val ) {
set = jQuery("<div/>").before("<span>test</span>");
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert before a disconnected node should be a no-op" );
equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" );
-};
+}
test( "before(String|Element|Array<Element>|jQuery)", function() {
testBefore( manipulationBareObj );
@@ -813,7 +813,7 @@ test( "insertBefore(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery before" );
});
-var testAfter = function( val ) {
+function testAfter( val ) {
expect( 7 );
@@ -846,7 +846,7 @@ var testAfter = function( val ) {
set = jQuery("<div/>").before("<span>test</span>");
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert after a disconnected node should be a no-op" );
equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" );
-};
+}
test( "after(String|Element|Array<Element>|jQuery)", function() {
testAfter( manipulationBareObj );
@@ -882,7 +882,7 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery after" );
});
-var testReplaceWith = function( val ) {
+function testReplaceWith( val ) {
var tmp, y, child, child2, set, non_existent, $div,
expected = 23;
@@ -970,7 +970,7 @@ var testReplaceWith = function( val ) {
equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after subsequent replacement." );
return expected;
-};
+}
test( "replaceWith(String|Element|Array<Element>|jQuery)", function() {
testReplaceWith( manipulationBareObj );
@@ -1271,13 +1271,13 @@ test( "html() on empty set", function() {
strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" );
});
-var childNodeNames = function( node ) {
+function childNodeNames( node ) {
return jQuery.map( node.childNodes, function( child ) {
return child.nodeName.toUpperCase();
}).join(" ");
-};
+}
-var testHtml = function( valueObj ) {
+function testHtml( valueObj ) {
expect( 37 );
var actual, expected, tmp,
@@ -1381,7 +1381,7 @@ var testHtml = function( valueObj ) {
QUnit.reset();
fixture.html( valueObj( fixture.text() ) );
ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" );
-};
+}
test( "html(String)", function() {
testHtml( manipulationBareObj );
@@ -1484,7 +1484,7 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function()
ok( expected.test( $content.html() ), "html()" );
});
-var testRemove = function( method ) {
+function testRemove( method ) {
var markup, div,
first = jQuery("#ap").children().first();
@@ -1494,7 +1494,7 @@ var testRemove = function( method ) {
ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
equal( jQuery("#ap").children().length, 0, "Check remove" );
- equal( first.data("foo"), method == "remove" ? null : "bar", "first data" );
+ equal( first.data("foo"), method === "remove" ? null : "bar", "first data" );
QUnit.reset();
jQuery("#ap").children()[ method ]("a");
@@ -1526,7 +1526,7 @@ var testRemove = function( method ) {
if (method === "detach") {
first.remove();
}
-};
+}
test( "remove()", 11, function() {
testRemove("remove");
@@ -1746,7 +1746,7 @@ test( "Cloned, detached HTML5 elems (#10667,10670)", function() {
}
// Bind an event
- $section.on( "click", function( event ) {
+ $section.on( "click", function() {
ok( true, "clone fired event" );
});
diff --git a/test/unit/offset.js b/test/unit/offset.js
index 0d8bcc726..f1e33bd4b 100644
--- a/test/unit/offset.js
+++ b/test/unit/offset.js
@@ -94,8 +94,10 @@ testIframe("offset/absolute", "absolute", function($, iframe) {
testIframe("offset/absolute", "absolute", function( $ ) {
expect(178);
+ var tests, offset;
+
// get offset tests
- var tests = [
+ tests = [
{ "id": "#absolute-1", "top": 1, "left": 1 },
{ "id": "#absolute-1-1", "top": 5, "left": 5 },
{ "id": "#absolute-1-1-1", "top": 9, "left": 9 },
@@ -120,7 +122,7 @@ testIframe("offset/absolute", "absolute", function( $ ) {
});
// test #5781
- var offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
+ offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
@@ -179,11 +181,13 @@ testIframe("offset/absolute", "absolute", function( $ ) {
testIframe("offset/relative", "relative", function( $ ) {
expect(60);
+ var ie, tests;
+
// IE is collapsing the top margin of 1px; detect and adjust accordingly
- var ie = $("#relative-1").offset().top === 6;
+ ie = $("#relative-1").offset().top === 6;
// get offset
- var tests = [
+ tests = [
{ "id": "#relative-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#relative-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#relative-2", "top": ie ? 141 : 142, "left": 27 }
@@ -238,14 +242,15 @@ testIframe("offset/relative", "relative", function( $ ) {
});
testIframe("offset/static", "static", function( $ ) {
+ expect( 80 );
- // IE is collapsing the top margin of 1px; detect and adjust accordingly
- var ie = $("#static-1").offset().top === 6;
+ var ie, tests;
- expect( 80 );
+ // IE is collapsing the top margin of 1px; detect and adjust accordingly
+ ie = $("#static-1").offset().top === 6;
// get offset
- var tests = [
+ tests = [
{ "id": "#static-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#static-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#static-1-1-1", "top": ie ? 20 : 23, "left": 23 },
@@ -306,12 +311,14 @@ testIframe("offset/static", "static", function( $ ) {
});
testIframe("offset/fixed", "fixed", function( $ ) {
- // IE is collapsing the top margin of 1px; detect and adjust accordingly
- var ie = $("#fixed-1").position().top === 2;
-
expect(34);
- var tests = [
+ var ie, tests, $noTopLeft;
+
+ // IE is collapsing the top margin of 1px; detect and adjust accordingly
+ ie = $("#fixed-1").position().top === 2;
+
+ tests = [
{
"id": "#fixed-1",
"offsetTop": 1001,
@@ -382,7 +389,7 @@ testIframe("offset/fixed", "fixed", function( $ ) {
});
// Bug 8316
- var $noTopLeft = $("#fixed-no-top-left");
+ $noTopLeft = $("#fixed-no-top-left");
if ( window.supportsFixedPosition ) {
equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
@@ -487,15 +494,17 @@ test("chaining", function() {
test("offsetParent", function(){
expect(13);
- var body = jQuery("body").offsetParent();
+ var body, header, div, area;
+
+ body = jQuery("body").offsetParent();
equal( body.length, 1, "Only one offsetParent found." );
equal( body[0], document.documentElement, "The html element is the offsetParent of the body." );
- var header = jQuery("#qunit").offsetParent();
+ header = jQuery("#qunit").offsetParent();
equal( header.length, 1, "Only one offsetParent found." );
equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." );
- var div = jQuery("#nothiddendivchild").offsetParent();
+ div = jQuery("#nothiddendivchild").offsetParent();
equal( div.length, 1, "Only one offsetParent found." );
equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
@@ -510,7 +519,7 @@ test("offsetParent", function(){
equal( div[0], document.documentElement, "The html element is the offsetParent of the body." );
equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
- var area = jQuery("#imgmap area").offsetParent();
+ area = jQuery("#imgmap area").offsetParent();
equal( area[0], document.documentElement, "The html element is the offsetParent of the body." );
div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body");
@@ -524,8 +533,9 @@ test("fractions (see #7730 and #7885)", function() {
jQuery("body").append("<div id='fractions'/>");
- var expected = { "top": 1000, "left": 1000 };
- var div = jQuery("#fractions");
+ var result,
+ expected = { "top": 1000, "left": 1000 },
+ div = jQuery("#fractions");
div.css({
"position": "absolute",
@@ -537,7 +547,7 @@ test("fractions (see #7730 and #7885)", function() {
div.offset(expected);
- var result = div.offset();
+ result = div.offset();
equal( result.top, expected.top, "Check top" );
equal( result.left, expected.left, "Check left" );
diff --git a/test/unit/queue.js b/test/unit/queue.js
index 5328d608a..f60d802fb 100644
--- a/test/unit/queue.js
+++ b/test/unit/queue.js
@@ -1,12 +1,11 @@
module( "queue", { teardown: moduleTeardown });
test( "queue() with other types", 14, function() {
- var counter = 0;
-
stop();
var $div = jQuery({}),
- defer;
+ counter = 0;
+
$div.promise( "foo" ).done(function() {
equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
});
@@ -56,8 +55,8 @@ test( "queue() with other types", 14, function() {
test("queue(name) passes in the next item in the queue as a parameter", function() {
expect(2);
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
div.queue("foo", function(next) {
equal(++counter, 1, "Dequeueing");
@@ -76,8 +75,8 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
expect(3);
stop();
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
div.queue(function(next) {
equal(++counter, 1, "Dequeueing");
@@ -148,14 +147,14 @@ test("clearQueue(name) clears the queue", function() {
stop();
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
- div.queue("foo", function(next) {
+ div.queue("foo", function( next ) {
counter++;
jQuery(this).clearQueue("foo");
next();
- }).queue("foo", function( next ) {
+ }).queue("foo", function() {
counter++;
});
@@ -172,14 +171,14 @@ test("clearQueue(name) clears the queue", function() {
test("clearQueue() clears the fx queue", function() {
expect(1);
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
- div.queue(function(next) {
+ div.queue(function( next ) {
counter++;
var self = this;
setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
- }).queue(function( next ) {
+ }).queue(function() {
counter++;
});
@@ -251,8 +250,8 @@ asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before res
test( ".promise(obj)", function() {
expect(2);
- var obj = {};
- var promise = jQuery( "#foo" ).promise( "promise", obj );
+ var obj = {},
+ promise = jQuery( "#foo" ).promise( "promise", obj );
ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
strictEqual( promise, obj, ".promise(type, obj) returns obj" );
diff --git a/test/unit/serialize.js b/test/unit/serialize.js
index 63607a323..39e7d777e 100644
--- a/test/unit/serialize.js
+++ b/test/unit/serialize.js
@@ -3,9 +3,11 @@ module("serialize", { teardown: moduleTeardown });
test("jQuery.param()", function() {
expect(22);
+ var params, settings;
+
equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" );
- var params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
+ params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"string":"foo","null":null,"undefined":undefined};
@@ -37,7 +39,7 @@ test("jQuery.param()", function() {
// #7945
equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
- var settings = { traditional: true };
+ settings = { traditional: true };
if ( jQuery.ajaxSettings ) {
jQuery.ajaxSetup( settings );
diff --git a/test/unit/traversing.js b/test/unit/traversing.js
index b600e130b..d99de436a 100644
--- a/test/unit/traversing.js
+++ b/test/unit/traversing.js
@@ -418,49 +418,54 @@ test("not(jQuery)", function() {
test("has(Element)", function() {
expect(3);
+ var obj, detached, multipleParent;
- var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
+ obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
- var detached = jQuery("<a><b><i/></b></a>");
+ detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
- var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
+ multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
});
test("has(Selector)", function() {
expect( 5 );
- var obj = jQuery("#qunit-fixture").has("#sndp");
+ var obj, detached, multipleParent, multipleHas;
+
+ obj = jQuery("#qunit-fixture").has("#sndp");
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
- var detached = jQuery("<a><b><i/></b></a>");
+ detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
- var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
+ multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a");
deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" );
- var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
+ multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
});
test("has(Arrayish)", function() {
expect(4);
- var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
+ var simple, detached, multipleParent, multipleHas;
+
+ simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
- var detached = jQuery("<a><b><i/></b></a>");
+ detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
- var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
+ multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
- var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
+ multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
});
@@ -478,6 +483,7 @@ test("siblings([String])", function() {
deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
deepEqual( jQuery("#nonnodes").contents().eq(1).siblings().get(), q("nonnodesElement"), "Check for text node siblings" );
deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
+
var set = q("sndp", "en", "sap");
deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
@@ -626,9 +632,11 @@ test("prevUntil([String])", function() {
test("contents()", function() {
expect(12);
+ var ibody, c;
+
equal( jQuery("#ap").contents().length, 9, "Check element contents" );
ok( jQuery("#iframe").contents()[0], "Check existence of IFrame document" );
- var ibody = jQuery("#loadediframe").contents()[0].body;
+ ibody = jQuery("#loadediframe").contents()[0].body;
ok( ibody, "Check existence of IFrame body" );
equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
@@ -651,13 +659,16 @@ test("contents()", function() {
equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
// using contents will get comments regular, text, and comment nodes
- var c = jQuery("#nonnodes").contents().contents();
+ c = jQuery("#nonnodes").contents().contents();
equal( c.length, 1, "Check node,textnode,comment contents is just one" );
equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
});
test("add(String|Element|Array|undefined)", function() {
expect( 15 );
+
+ var divs, tmp, x, notDefined;
+
deepEqual( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
@@ -671,15 +682,15 @@ test("add(String|Element|Array|undefined)", function() {
// use jQuery([]).add(form.elements) instead.
//equal( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
- var divs = jQuery("<div/>").add("#sndp");
+ divs = jQuery("<div/>").add("#sndp");
ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
divs = jQuery("#sndp").add("<div/>");
ok( !divs[1].parentNode, "Sort with the disconnected node last." );
- var tmp = jQuery("<div/>");
+ tmp = jQuery("<div/>");
- var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
+ x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
@@ -695,7 +706,6 @@ test("add(String|Element|Array|undefined)", function() {
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
- var notDefined;
equal( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
@@ -726,14 +736,15 @@ test("eq('-1') #10616", function() {
test("index(no arg) #10977", function() {
expect(2);
+ var $list, fragment, div;
- var $list = jQuery("<ul id='indextest'><li class='zero'>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>");
+ $list = jQuery("<ul id='indextest'><li class='zero'>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>");
jQuery("#qunit-fixture").append( $list );
strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" );
$list.remove();
- var fragment = document.createDocumentFragment(),
- div = fragment.appendChild( document.createElement("div") );
+ fragment = document.createDocumentFragment();
+ div = fragment.appendChild( document.createElement("div") );
equal( jQuery( div ).index(), 0, "If jQuery#index called on element whose parent is fragment, it still should work correctly" );
});
diff --git a/test/unit/wrap.js b/test/unit/wrap.js
index 1775aafb6..3de1c7931 100644
--- a/test/unit/wrap.js
+++ b/test/unit/wrap.js
@@ -9,17 +9,17 @@ module( "wrap", {
});
// See test/unit/manipulation.js for explanation about these 2 functions
-var manipulationBareObj = function( value ) {
+function manipulationBareObj( value ) {
return value;
-};
+}
-var manipulationFunctionReturningObj = function( value ) {
- return (function() {
+function manipulationFunctionReturningObj( value ) {
+ return function() {
return value;
- });
-};
+ };
+}
-var testWrap = function( val ) {
+function testWrap( val ) {
expect( 19 );
@@ -99,7 +99,7 @@ var testWrap = function( val ) {
// clean up attached elements
QUnit.reset();
-};
+}
test( "wrap(String|Element)", function() {
testWrap( manipulationBareObj );
@@ -136,7 +136,7 @@ test( "wrap(String) consecutive elements (#10177)", function() {
});
});
-var testWrapAll = function( val ) {
+function testWrapAll( val ) {
expect( 8 );
@@ -160,17 +160,18 @@ var testWrapAll = function( val ) {
equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" );
equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
-};
+}
test( "wrapAll(String|Element)", function() {
testWrapAll( manipulationBareObj );
});
-var testWrapInner = function( val ) {
+function testWrapInner( val ) {
expect( 11 );
- var num;
+ var num,
+ div = jQuery("<div/>");
num = jQuery("#first").children().length;
jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
@@ -193,11 +194,10 @@ var testWrapInner = function( val ) {
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
- var div = jQuery("<div/>");
div.wrapInner( val("<span></span>") );
equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
-};
+}
test( "wrapInner(String|Element)", function() {
testWrapInner( manipulationBareObj );