Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update jshintrc to conform to new style guide. Conform to onevar and …

…unused in tests. Fixes #13755.
  • Loading branch information...
commit 0fa52c11cbfe70780648b99717f1dd3502befaff 1 parent 0afc92b
@timmywil timmywil authored
View
13 .jshintrc
@@ -1,14 +1,17 @@
{
+ "boss": true,
"curly": true,
"eqeqeq": true,
- "latedef": true,
+ "eqnull": true,
+ "expr": true,
+ "immed": true,
"noarg": true,
- "noempty": true,
+ "onevar": true,
"quotmark": "double",
+ "smarttabs": true,
+ "trailing": true,
"undef": true,
"unused": true,
- "strict": true,
- "trailing": true,
"node": true
-}
+}
View
6 Gruntfile.js
@@ -406,7 +406,7 @@ module.exports = function( grunt ) {
// Process files for distribution
grunt.registerTask( "dist", function() {
- var flags, paths, stored;
+ var stored, flags, paths, fs, nonascii;
// Check for stored destination paths
// ( set in dist/.destination.json )
@@ -421,8 +421,8 @@ module.exports = function( grunt ) {
});
// Ensure the dist files are pure ASCII
- var fs = require("fs"),
- nonascii = false;
+ fs = require("fs");
+ nonascii = false;
distpaths.forEach(function( filename ) {
var i, c, map,
View
12 src/.jshintrc
@@ -1,18 +1,18 @@
{
+ "boss": true,
"curly": true,
+ "eqeqeq": true,
+ "eqnull": true,
"expr": true,
- "newcap": false,
+ "immed": true,
+ "noarg": true,
"quotmark": "double",
+ "smarttabs": true,
"trailing": true,
"undef": true,
"unused": true,
- "latedef": false,
- "eqeqeq": true,
- "maxerr": 100,
- "eqnull": true,
"sub": true,
- "boss": true,
"browser": true,
"es5": true,
View
12 src/data.js
@@ -333,12 +333,12 @@ function dataAttr( elem, key, data ) {
if ( typeof data === "string" ) {
try {
data = data === "true" ? true :
- data === "false" ? false :
- data === "null" ? null :
- // Only convert to a number if it doesn't change the string
- +data + "" === data ? +data :
- rbrace.test( data ) ?
- JSON.parse( data ) : data;
+ data === "false" ? false :
+ data === "null" ? null :
+ // Only convert to a number if it doesn't change the string
+ +data + "" === data ? +data :
+ rbrace.test( data ) ? JSON.parse( data ) :
+ data;
} catch( e ) {}
// Make sure we set the data so it isn't changed later
View
11 test/.jshintrc
@@ -1,14 +1,19 @@
{
+ "boss": true,
"curly": true,
+ "eqeqeq": true,
+ "eqnull": true,
"expr": true,
+ "immed": true,
+ "noarg": true,
+ "onevar": true,
"quotmark": "double",
+ "smarttabs": true,
"trailing": true,
"undef": true,
- "maxerr": 100,
+ "unused": true,
- "eqnull": true,
"evil": true,
- "smarttabs": true,
"sub": true,
"browser": true,
View
2  test/data/test.js
@@ -1,3 +1,3 @@
-var testBar = "bar";
+this.testBar = "bar";
jQuery("#ap").html("bar");
ok( true, "test.js executed");
View
131 test/data/testinit.js
@@ -3,11 +3,12 @@
var amdDefined, fireNative,
originaljQuery = this.jQuery || "jQuery",
original$ = this.$ || "$",
- hasPHP = true,
- isLocal = window.location.protocol === "file:",
// see RFC 2606
externalHost = "example.com";
+this.hasPHP = true;
+this.isLocal = window.location.protocol === "file:";
+
// For testing .noConflict()
this.jQuery = originaljQuery;
this.$ = original$;
@@ -26,7 +27,7 @@ define.amd = {};
* @example q("main", "foo", "bar")
* @result [<div id="main">, <span id="foo">, <input id="bar">]
*/
-function q() {
+this.q = function() {
var r = [],
i = 0;
@@ -34,7 +35,7 @@ function q() {
r.push( document.getElementById( arguments[i] ) );
}
return r;
-}
+};
/**
* Asserts that a select matches the given IDs
@@ -44,7 +45,7 @@ function q() {
* @example t("Check for something", "//[a]", ["foo", "baar"]);
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
*/
-function t( a, b, c ) {
+this.t = function( a, b, c ) {
var f = jQuery(b).get(),
s = "",
i = 0;
@@ -54,9 +55,9 @@ function t( a, b, c ) {
}
deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
-}
+};
-function createDashboardXML() {
+this.createDashboardXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<dashboard> \
<locations class="foo"> \
@@ -70,9 +71,9 @@ function createDashboardXML() {
</dashboard>';
return jQuery.parseXML(string);
-}
+};
-function createWithFriesXML() {
+this.createWithFriesXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
@@ -100,9 +101,9 @@ function createWithFriesXML() {
</soap:Envelope>';
return jQuery.parseXML( string.replace( /\{\{\s*externalHost\s*\}\}/g, externalHost ) );
-}
+};
-function createXMLFragment() {
+this.createXMLFragment = function() {
var xml, frag;
if ( window.ActiveXObject ) {
xml = new ActiveXObject("msxml2.domdocument");
@@ -115,7 +116,7 @@ function createXMLFragment() {
}
return frag;
-}
+};
fireNative = document.createEvent ?
function( node, type ) {
@@ -142,7 +143,7 @@ function url( value ) {
}
// Ajax testing helper
-function ajaxTest( title, expect, options ) {
+this.ajaxTest = function( title, expect, options ) {
var requestOptions;
if ( jQuery.isFunction( options ) ) {
options = options();
@@ -205,63 +206,59 @@ function ajaxTest( title, expect, options ) {
}
};
});
-}
+};
-(function () {
-
- this.testIframe = function( fileName, name, fn ) {
-
- test(name, function() {
- // pause execution for now
- stop();
-
- // load fixture in iframe
- var iframe = loadFixture(),
- win = iframe.contentWindow,
- interval = setInterval( function() {
- if ( win && win.jQuery && win.jQuery.isReady ) {
- clearInterval( interval );
- // continue
- start();
- // call actual tests passing the correct jQuery instance to use
- fn.call( this, win.jQuery, win, win.document );
- document.body.removeChild( iframe );
- iframe = null;
- }
- }, 15 );
- });
-
- function loadFixture() {
- var src = url("./data/" + fileName + ".html"),
- iframe = jQuery("<iframe />").appendTo("body")[0];
- iframe.style.cssText = "width: 500px; height: 500px; position: absolute; top: -600px; left: -600px; visibility: hidden;";
- iframe.contentWindow.location = src;
- return iframe;
- }
- };
- this.testIframeWithCallback = function( title, fileName, func ) {
+this.testIframe = function( fileName, name, fn ) {
- test( title, function() {
- var iframe;
+ test(name, function() {
+ // pause execution for now
+ stop();
- stop();
- window.iframeCallback = function() {
- var self = this,
- args = arguments;
- setTimeout(function() {
- window.iframeCallback = undefined;
- iframe.remove();
- func.apply( self, args );
- func = function() {};
+ // load fixture in iframe
+ var iframe = loadFixture(),
+ win = iframe.contentWindow,
+ interval = setInterval( function() {
+ if ( win && win.jQuery && win.jQuery.isReady ) {
+ clearInterval( interval );
+ // continue
start();
- }, 0 );
- };
- iframe = jQuery( "<div/>" ).append(
- jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) )
- ).appendTo( "body" );
- });
- };
+ // call actual tests passing the correct jQuery instance to use
+ fn.call( this, win.jQuery, win, win.document );
+ document.body.removeChild( iframe );
+ iframe = null;
+ }
+ }, 15 );
+ });
- window.iframeCallback = undefined;
-}());
+ function loadFixture() {
+ var src = url("./data/" + fileName + ".html"),
+ iframe = jQuery("<iframe />").appendTo("body")[0];
+ iframe.style.cssText = "width: 500px; height: 500px; position: absolute; top: -600px; left: -600px; visibility: hidden;";
+ iframe.contentWindow.location = src;
+ return iframe;
+ }
+};
+
+this.testIframeWithCallback = function( title, fileName, func ) {
+
+ test( title, function() {
+ var iframe;
+
+ stop();
+ window.iframeCallback = function() {
+ var self = this,
+ args = arguments;
+ setTimeout(function() {
+ window.iframeCallback = undefined;
+ iframe.remove();
+ func.apply( self, args );
+ func = function() {};
+ start();
+ }, 0 );
+ };
+ iframe = jQuery( "<div/>" ).append(
+ jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) )
+ ).appendTo( "body" );
+ });
+};
View
10 test/data/testrunner.js
@@ -10,13 +10,13 @@ jQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ],
// Expose Sizzle for Sizzle's selector tests
// We remove Sizzle's globalization in jQuery
-var Sizzle = Sizzle || jQuery.find;
+var Sizzle = Sizzle || jQuery.find,
// Allow subprojects to test against their own fixtures
-var qunitModule = QUnit.module,
+ qunitModule = QUnit.module,
qunitTest = QUnit.test;
-function testSubproject( label, url, risTests ) {
+this.testSubproject = function( label, url, risTests ) {
var sub, fixture, fixtureHTML,
fixtureReplaced = false;
@@ -132,11 +132,11 @@ function testSubproject( label, url, risTests ) {
fn.apply( this, arguments );
};
}
-}
+};
// Register globals for cleanup and the cleanup code itself
// Explanation at http://perfectionkills.com/understanding-delete/#ie_bugs
-var Globals = (function() {
+this.Globals = (function() {
var globals = {};
return {
register: function( name ) {
View
37 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();
});
View
133 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;
}
}
View
4 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() {
View
179 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" );
});
View
91 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");
View
51 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;
View
28 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" );
});