Commit d2435ead authored by Timmy Willison's avatar Timmy Willison

Update jshintrc to conform to new style guide. Conform to onevar and unused in tests. Fixes #13755.

Conflicts:
	src/.jshintrc
	src/data.js
	test/unit/attributes.js
	test/unit/core.js
	test/unit/data.js
	test/unit/event.js
	test/unit/manipulation.js
	test/unit/queue.js
	test/unit/traversing.js
	test/unit/wrap.js
parent c6a694e1
{ {
"boss": true,
"curly": true, "curly": true,
"eqeqeq": true, "eqeqeq": true,
"latedef": true, "eqnull": true,
"expr": true,
"immed": true,
"noarg": true, "noarg": true,
"noempty": true, "onevar": true,
"quotmark": "double", "quotmark": "double",
"smarttabs": true,
"trailing": true,
"undef": true, "undef": true,
"unused": true, "unused": true,
"strict": true,
"trailing": true,
"node": true "node": true
} }
\ No newline at end of file
...@@ -411,7 +411,7 @@ module.exports = function( grunt ) { ...@@ -411,7 +411,7 @@ module.exports = function( grunt ) {
// Process files for distribution // Process files for distribution
grunt.registerTask( "dist", function() { grunt.registerTask( "dist", function() {
var flags, paths, stored; var stored, flags, paths, fs, nonascii;
// Check for stored destination paths // Check for stored destination paths
// ( set in dist/.destination.json ) // ( set in dist/.destination.json )
...@@ -426,8 +426,8 @@ module.exports = function( grunt ) { ...@@ -426,8 +426,8 @@ module.exports = function( grunt ) {
}); });
// Ensure the dist files are pure ASCII // Ensure the dist files are pure ASCII
var fs = require("fs"), fs = require("fs");
nonascii = false; nonascii = false;
distpaths.forEach(function( filename ) { distpaths.forEach(function( filename ) {
var i, c, map, var i, c, map,
......
{ {
"boss": true,
"curly": true, "curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true, "expr": true,
"newcap": false, "immed": true,
"noarg": true,
"quotmark": "double", "quotmark": "double",
"smarttabs": true,
"trailing": true, "trailing": true,
"undef": true, "undef": true,
"unused": true, "unused": true,
"latedef": false,
"eqeqeq": true,
"maxerr": 100,
"eqnull": true,
"evil": true, "evil": true,
"sub": true, "sub": true,
"boss": true,
"browser": true, "browser": true,
"wsh": true, "wsh": true,
"predef": [ "globals": {
"define", "define": true,
"module", "module": true,
"jQuery" "jQuery": true
] }
} }
{ {
"boss": true,
"curly": true, "curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true, "expr": true,
"immed": true,
"noarg": true,
"onevar": true,
"quotmark": "double", "quotmark": "double",
"smarttabs": true,
"trailing": true, "trailing": true,
"undef": true, "undef": true,
"maxerr": 100, "unused": true,
"eqnull": true,
"evil": true, "evil": true,
"smarttabs": true,
"sub": true, "sub": true,
"browser": true, "browser": true,
......
var testBar = "bar"; this.testBar = "bar";
jQuery("#ap").html("bar"); jQuery("#ap").html("bar");
ok( true, "test.js executed"); ok( true, "test.js executed");
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
var amdDefined, fireNative, var amdDefined, fireNative,
originaljQuery = this.jQuery || "jQuery", originaljQuery = this.jQuery || "jQuery",
original$ = this.$ || "$", original$ = this.$ || "$",
hasPHP = true,
isLocal = window.location.protocol === "file:",
// see RFC 2606 // see RFC 2606
externalHost = "example.com"; externalHost = "example.com";
this.hasPHP = true;
this.isLocal = window.location.protocol === "file:";
// For testing .noConflict() // For testing .noConflict()
this.jQuery = originaljQuery; this.jQuery = originaljQuery;
this.$ = original$; this.$ = original$;
...@@ -26,7 +27,7 @@ define.amd = {}; ...@@ -26,7 +27,7 @@ define.amd = {};
* @example q("main", "foo", "bar") * @example q("main", "foo", "bar")
* @result [<div id="main">, <span id="foo">, <input id="bar">] * @result [<div id="main">, <span id="foo">, <input id="bar">]
*/ */
function q() { this.q = function() {
var r = [], var r = [],
i = 0; i = 0;
...@@ -34,7 +35,7 @@ function q() { ...@@ -34,7 +35,7 @@ function q() {
r.push( document.getElementById( arguments[i] ) ); r.push( document.getElementById( arguments[i] ) );
} }
return r; return r;
} };
/** /**
* Asserts that a select matches the given IDs * Asserts that a select matches the given IDs
...@@ -44,7 +45,7 @@ function q() { ...@@ -44,7 +45,7 @@ function q() {
* @example t("Check for something", "//[a]", ["foo", "baar"]); * @example t("Check for something", "//[a]", ["foo", "baar"]);
* @result returns true if "//[a]" return two elements with the IDs 'foo' and '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(), var f = jQuery(b).get(),
s = "", s = "",
i = 0; i = 0;
...@@ -54,9 +55,9 @@ function t( a, b, c ) { ...@@ -54,9 +55,9 @@ function t( a, b, c ) {
} }
deepEqual(f, q.apply( q, c ), a + " (" + b + ")"); deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
} };
function createDashboardXML() { this.createDashboardXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \ var string = '<?xml version="1.0" encoding="UTF-8"?> \
<dashboard> \ <dashboard> \
<locations class="foo"> \ <locations class="foo"> \
...@@ -70,9 +71,9 @@ function createDashboardXML() { ...@@ -70,9 +71,9 @@ function createDashboardXML() {
</dashboard>'; </dashboard>';
return jQuery.parseXML(string); return jQuery.parseXML(string);
} };
function createWithFriesXML() { this.createWithFriesXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \ var string = '<?xml version="1.0" encoding="UTF-8"?> \
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \ xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
...@@ -100,9 +101,9 @@ function createWithFriesXML() { ...@@ -100,9 +101,9 @@ function createWithFriesXML() {
</soap:Envelope>'; </soap:Envelope>';
return jQuery.parseXML( string.replace( /\{\{\s*externalHost\s*\}\}/g, externalHost ) ); return jQuery.parseXML( string.replace( /\{\{\s*externalHost\s*\}\}/g, externalHost ) );
} };
function createXMLFragment() { this.createXMLFragment = function() {
var xml, frag; var xml, frag;
if ( window.ActiveXObject ) { if ( window.ActiveXObject ) {
xml = new ActiveXObject("msxml2.domdocument"); xml = new ActiveXObject("msxml2.domdocument");
...@@ -115,7 +116,7 @@ function createXMLFragment() { ...@@ -115,7 +116,7 @@ function createXMLFragment() {
} }
return frag; return frag;
} };
fireNative = document.createEvent ? fireNative = document.createEvent ?
function( node, type ) { function( node, type ) {
...@@ -142,7 +143,7 @@ function url( value ) { ...@@ -142,7 +143,7 @@ function url( value ) {
} }
// Ajax testing helper // Ajax testing helper
function ajaxTest( title, expect, options ) { this.ajaxTest = function( title, expect, options ) {
var requestOptions; var requestOptions;
if ( jQuery.isFunction( options ) ) { if ( jQuery.isFunction( options ) ) {
options = options(); options = options();
...@@ -205,63 +206,59 @@ function ajaxTest( title, expect, 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() { test(name, function() {
var iframe; // pause execution for now
stop();
stop(); // load fixture in iframe
window.iframeCallback = function() { var iframe = loadFixture(),
var self = this, win = iframe.contentWindow,
args = arguments; interval = setInterval( function() {
setTimeout(function() { if ( win && win.jQuery && win.jQuery.isReady ) {
window.iframeCallback = undefined; clearInterval( interval );
iframe.remove(); // continue
func.apply( self, args );
func = function() {};
start(); start();
}, 0 ); // call actual tests passing the correct jQuery instance to use
}; fn.call( this, win.jQuery, win, win.document );
iframe = jQuery( "<div/>" ).append( document.body.removeChild( iframe );
jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) ) iframe = null;
).appendTo( "body" ); }
}); }, 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" );
});
};
...@@ -10,13 +10,13 @@ jQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], ...@@ -10,13 +10,13 @@ jQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ],
// Expose Sizzle for Sizzle's selector tests // Expose Sizzle for Sizzle's selector tests
// We remove Sizzle's globalization in jQuery // 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 // Allow subprojects to test against their own fixtures
var qunitModule = QUnit.module, qunitModule = QUnit.module,
qunitTest = QUnit.test; qunitTest = QUnit.test;
function testSubproject( label, url, risTests ) { this.testSubproject = function( label, url, risTests ) {
var sub, fixture, fixtureHTML, var sub, fixture, fixtureHTML,
fixtureReplaced = false; fixtureReplaced = false;
...@@ -132,11 +132,11 @@ function testSubproject( label, url, risTests ) { ...@@ -132,11 +132,11 @@ function testSubproject( label, url, risTests ) {
fn.apply( this, arguments ); fn.apply( this, arguments );
}; };
} }
} };
// Register globals for cleanup and the cleanup code itself // Register globals for cleanup and the cleanup code itself
// Explanation at http://perfectionkills.com/understanding-delete/#ie_bugs // Explanation at http://perfectionkills.com/understanding-delete/#ie_bugs
var Globals = (function() { this.Globals = (function() {
var globals = {}; var globals = {};
return { return {
register: function( name ) { register: function( name ) {
......
...@@ -498,10 +498,10 @@ module( "ajax", { ...@@ -498,10 +498,10 @@ module( "ajax", {
ajaxTest( "jQuery.ajax() - beforeSend", 1, { ajaxTest( "jQuery.ajax() - beforeSend", 1, {
url: url("data/name.html"), url: url("data/name.html"),
beforeSend: function( xml ) { beforeSend: function() {
this.check = true; this.check = true;
}, },
success: function( data ) { success: function() {
ok( this.check, "check beforeSend was executed" ); ok( this.check, "check beforeSend was executed" );
} }
}); });
...@@ -571,14 +571,14 @@ module( "ajax", { ...@@ -571,14 +571,14 @@ module( "ajax", {
}); });
asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() { asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() {
var target = "data/name.html"; var target = "data/name.html",
var successCount = 0; successCount = 0,
var errorCount = 0; errorCount = 0,
var errorEx = ""; errorEx = "",
var success = function() { success = function() {
successCount++; successCount++;
}; };
jQuery( document ).on( "ajaxError.passthru", function( e, xml, s, ex ) { jQuery( document ).on( "ajaxError.passthru", function( e, xml ) {
errorCount++; errorCount++;
errorEx += ": " + xml.status; errorEx += ": " + xml.status;
}); });
...@@ -842,7 +842,7 @@ module( "ajax", { ...@@ -842,7 +842,7 @@ module( "ajax", {
}, },
url: window.location.href.replace( /[^\/]*$/, "" ) + "data/test.js", url: window.location.href.replace( /[^\/]*$/, "" ) + "data/test.js",
dataType: "script", dataType: "script",
success: function( data ) { success: function() {
strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
} }
}); });
...@@ -866,7 +866,7 @@ module( "ajax", { ...@@ -866,7 +866,7 @@ module( "ajax", {
}, },
url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/test.js", url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/test.js",
dataType: "script", dataType: "script",
success: function( data ) { success: function() {
strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
} }
}); });
...@@ -1295,9 +1295,10 @@ module( "ajax", { ...@@ -1295,9 +1295,10 @@ module( "ajax", {
}); });
test( "#7531 - jQuery.ajax() - Location object as url", 1, function () { test( "#7531 - jQuery.ajax() - Location object as url", 1, function () {
var success = false; var xhr,
success = false;
try { try {
var xhr = jQuery.ajax({ xhr = jQuery.ajax({
url: window.location url: window.location
}); });
success = true; success = true;
...@@ -1313,7 +1314,7 @@ module( "ajax", { ...@@ -1313,7 +1314,7 @@ module( "ajax", {
url: "data/jsonp.php", url: "data/jsonp.php",
dataType: "jsonp", dataType: "jsonp",
crossDomain: crossDomain, crossDomain: crossDomain,
beforeSend: function( jqXHR, s ) { beforeSend: function() {
strictEqual( this.cache, false, "cache must be false on JSON request" ); strictEqual( this.cache, false, "cache must be false on JSON request" );
return false; return false;
}, },
...@@ -1577,12 +1578,12 @@ module( "ajax", { ...@@ -1577,12 +1578,12 @@ module( "ajax", {
var passed = 0, var passed = 0,
pass = function() { pass = function() {
ok( passed++ < 2, "Error callback executed" ); ok( passed++ < 2, "Error callback executed" );
if ( passed == 2 ) { if ( passed === 2 ) {
jQuery( document ).off("ajaxError.setupTest"); jQuery( document ).off("ajaxError.setupTest");
start(); start();
} }
}, },
fail = function( a, b, c ) { fail = function( a, b ) {
ok( false, "Check for timeout failed " + a + " " + b ); ok( false, "Check for timeout failed " + a + " " + b );
start(); start();
}; };
...@@ -1700,7 +1701,7 @@ module( "ajax", { ...@@ -1700,7 +1701,7 @@ module( "ajax", {
Globals.register("JSON"); Globals.register("JSON");
} }
window.JSON = { window.JSON = {
parse: function( str ) { parse: function() {
ok( true, "Verifying that parse method was run" ); ok( true, "Verifying that parse method was run" );
window.JSON = old; window.JSON = old;
return true; return true;
...@@ -1724,7 +1725,7 @@ module( "ajax", { ...@@ -1724,7 +1725,7 @@ module( "ajax", {
asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() { asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() {
Globals.register("testBar"); 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" ); strictEqual( window["testBar"], "bar", "Check if script was evaluated" );
start(); start();
}); });
...@@ -1861,8 +1862,7 @@ module( "ajax", { ...@@ -1861,8 +1862,7 @@ module( "ajax", {
}); });
asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() { asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() {
var slice = [].slice, var completeArgs = {};
completeArgs = {};
jQuery.ajaxSetup({ jQuery.ajaxSetup({
success: function( _, status, jqXHR ) { success: function( _, status, jqXHR ) {
......
This diff is collapsed.
...@@ -56,7 +56,7 @@ jQuery.each( tests, function( strFlags, resultString ) { ...@@ -56,7 +56,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
} }
}); });
jQuery.each( filters, function( filterLabel, filter ) { jQuery.each( filters, function( filterLabel ) {
jQuery.each({ jQuery.each({
"string": strFlags, "string": strFlags,
...@@ -220,7 +220,7 @@ jQuery.each( tests, function( strFlags, resultString ) { ...@@ -220,7 +220,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Callbacks are not iterated // Callbacks are not iterated
output = ""; output = "";
function handler( tmp ) { function handler() {
output += "X"; output += "X";
} }
handler.method = function() { handler.method = function() {
......
This diff is collapsed.
This diff is collapsed.
...@@ -7,7 +7,7 @@ test("expando", function(){ ...@@ -7,7 +7,7 @@ test("expando", function(){
}); });
function dataTests (elem) { function dataTests (elem) {
var oldCacheLength, dataObj, internalDataObj, expected, actual; var dataObj, internalDataObj;
equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" ); equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" ); strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" );
...@@ -144,17 +144,19 @@ test("Data is not being set on comment and text nodes", function() { ...@@ -144,17 +144,19 @@ test("Data is not being set on comment and text nodes", function() {
test("jQuery.acceptData", function() { test("jQuery.acceptData", function() {
expect(9); expect(9);
var flash, applet;
ok( jQuery.acceptData( document ), "document" ); ok( jQuery.acceptData( document ), "document" );
ok( jQuery.acceptData( document.documentElement ), "documentElement" ); ok( jQuery.acceptData( document.documentElement ), "documentElement" );
ok( jQuery.acceptData( {} ), "object" ); ok( jQuery.acceptData( {} ), "object" );
ok( !jQuery.acceptData( document.createElement("embed") ), "embed" ); ok( !jQuery.acceptData( document.createElement("embed") ), "embed" );
ok( !jQuery.acceptData( document.createElement("applet") ), "applet" ); ok( !jQuery.acceptData( document.createElement("applet") ), "applet" );
var flash = document.createElement("object"); flash = document.createElement("object");
flash.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"); flash.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
ok( jQuery.acceptData( flash ), "flash" ); ok( jQuery.acceptData( flash ), "flash" );
var applet = document.createElement("object"); applet = document.createElement("object");
applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"); applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
ok( !jQuery.acceptData( applet ), "applet" ); ok( !jQuery.acceptData( applet ), "applet" );
...@@ -165,19 +167,21 @@ test("jQuery.acceptData", function() { ...@@ -165,19 +167,21 @@ test("jQuery.acceptData", function() {
test(".data()", function() { test(".data()", function() {
expect(5); 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" ); strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
div.data("test", "success"); div.data("test", "success");
var dataObj = div.data(); dataObj = div.data();
deepEqual( dataObj, {test: "success"}, "data() returns entire data object with expected properties" ); 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" ); 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" ); equal( nodiv.data(), null, "data() on empty set returns null" );
var obj = { foo: "bar" }; obj = { foo: "bar" };
jQuery(obj).data("foo", "baz"); jQuery(obj).data("foo", "baz");
dataObj = jQuery.extend(true, {}, jQuery(obj).data()); dataObj = jQuery.extend(true, {}, jQuery(obj).data());
...@@ -185,7 +189,7 @@ test(".data()", function() { ...@@ -185,7 +189,7 @@ test(".data()", function() {
deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" ); deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
}); });
var testDataTypes = function( $obj ) { function testDataTypes( $obj ) {
jQuery.each({ jQuery.each({
"null": null, "null": null,
"true": true, "true": true,
...@@ -203,7 +207,7 @@ var testDataTypes = function( $obj ) { ...@@ -203,7 +207,7 @@ var testDataTypes = function( $obj ) {
}, function( type, value ) { }, function( type, value ) {
strictEqual( $obj.data( "test", value ).data("test"), value, "Data set to " + type ); strictEqual( $obj.data( "test", value ).data("test"), value, "Data set to " + type );
}); });
}; }
test("jQuery(Element).data(String, Object).data(String)", function() { test("jQuery(Element).data(String, Object).data(String)", function() {
expect( 18 ); expect( 18 );
...@@ -236,7 +240,9 @@ test("jQuery(plain Object).data(String, Object).data(String)", function() { ...@@ -236,7 +240,9 @@ test("jQuery(plain Object).data(String, Object).data(String)", function() {
test("data-* attributes", function() { test("data-* attributes", function() {
expect(40); 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>"), 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>"); dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
...@@ -262,16 +268,15 @@ test("data-* attributes", function() { ...@@ -262,16 +268,15 @@ test("data-* attributes", function() {
child.data("ignored", "cache"); child.data("ignored", "cache");
equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback"); equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback");
var prop, obj = child.data();
obj = child.data(), obj2 = dummy.data();
obj2 = dummy.data(), check = [ "myobj", "ignored", "other" ];
check = [ "myobj", "ignored", "other" ], num = 0;
num = 0, num2 = 0;
num2 = 0;
dummy.remove(); 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( obj[ check[i] ], "Make sure data- property exists when calling data-." );
ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." ); ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
} }
...@@ -353,8 +358,8 @@ test("data-* attributes", function() { ...@@ -353,8 +358,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>", 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 = jQuery(metadata).appendTo("#qunit-fixture");
elem.find("li").each(testData); elem.find("li").each(testData);
elem.remove(); elem.remove();
...@@ -363,14 +368,16 @@ test("data-* attributes", function() { ...@@ -363,14 +368,16 @@ test("data-* attributes", function() {
test(".data(Object)", function() { test(".data(Object)", function() {
expect(4); expect(4);
var div = jQuery("<div/>"); var obj, jqobj,
div = jQuery("<div/>");
div.data({ "test": "in", "test2": "in2" }); div.data({ "test": "in", "test2": "in2" });
equal( div.data("test"), "in", "Verify setting an object in data" ); equal( div.data("test"), "in", "Verify setting an object in data" );
equal( div.data("test2"), "in2", "Verify setting an object in data" ); equal( div.data("test2"), "in2", "Verify setting an object in data" );
var obj = {test:"unset"}, obj = {test:"unset"};
jqobj = jQuery(obj); jqobj = jQuery(obj);
jqobj.data("test", "unset"); jqobj.data("test", "unset");
jqobj.data({ "test": "in", "test2": "in2" }); jqobj.data({ "test": "in", "test2": "in2" });
equal( jQuery.data(obj)["test"], "in", "Verify setting an object on an object extends the data object" ); equal( jQuery.data(obj)["test"], "in", "Verify setting an object on an object extends the data object" );
...@@ -382,7 +389,9 @@ test(".data(Object)", function() { ...@@ -382,7 +389,9 @@ test(".data(Object)", function() {
test("jQuery.removeData", function() { test("jQuery.removeData", function() {
expect(10); expect(10);
var div = jQuery("#foo")[0];
var obj,
div = jQuery("#foo")[0];
jQuery.data(div, "test", "testing"); jQuery.data(div, "test", "testing");
jQuery.removeData(div, "test"); jQuery.removeData(div, "test");
equal( jQuery.data(div, "test"), undefined, "Check removal of data" ); equal( jQuery.data(div, "test"), undefined, "Check removal of data" );
...@@ -414,7 +423,7 @@ test("jQuery.removeData", function() { ...@@ -414,7 +423,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 test4"), "Multiple delete with spaces deleted key with exact name" );
ok( jQuery.data(div, "test3"), "Left the partial matched key alone" ); ok( jQuery.data(div, "test3"), "Left the partial matched key alone" );
var obj = {}; obj = {};
jQuery.data(obj, "test", "testing"); jQuery.data(obj, "test", "testing");
equal( jQuery(obj).data("test"), "testing", "verify data on plain object"); equal( jQuery(obj).data("test"), "testing", "verify data on plain object");
jQuery.removeData(obj, "test"); jQuery.removeData(obj, "test");
...@@ -562,7 +571,7 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert ...@@ -562,7 +571,7 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert
}); });
}); });
test( "jQuery.fn.removeData supports removal of hyphenated properties via array (#12786)", function( assert ) { test( ".removeData supports removal of hyphenated properties via array (#12786)", function() {
expect( 4 ); expect( 4 );
var div, plain, compare; var div, plain, compare;
......
...@@ -47,7 +47,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { ...@@ -47,7 +47,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
funcPromise = defer.promise( func ); funcPromise = defer.promise( func );
strictEqual( defer.promise(), promise, "promise is always the same" ); strictEqual( defer.promise(), promise, "promise is always the same" );
strictEqual( funcPromise, func, "non objects get extended" ); strictEqual( funcPromise, func, "non objects get extended" );
jQuery.each( promise, function( key, value ) { jQuery.each( promise, function( key ) {
if ( !jQuery.isFunction( promise[ key ] ) ) { if ( !jQuery.isFunction( promise[ key ] ) ) {
ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" ); ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
} }
...@@ -275,7 +275,8 @@ test( "jQuery.Deferred.then - context", function() { ...@@ -275,7 +275,8 @@ test( "jQuery.Deferred.then - context", function() {
expect( 7 ); expect( 7 );
var context = {}; var defer, piped, defer2, piped2,
context = {};
jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) { jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
return value * 3; return value * 3;
...@@ -290,10 +291,10 @@ test( "jQuery.Deferred.then - context", function() { ...@@ -290,10 +291,10 @@ test( "jQuery.Deferred.then - context", function() {
strictEqual( this, context, "custom context of returned deferred correctly propagated" ); strictEqual( this, context, "custom context of returned deferred correctly propagated" );
}); });
var defer = jQuery.Deferred(), defer = jQuery.Deferred();
piped = defer.then(function( value ) { piped = defer.then(function( value ) {
return value * 3; return value * 3;
}); });
defer.resolve( 2 ); defer.resolve( 2 );
...@@ -302,8 +303,8 @@ test( "jQuery.Deferred.then - context", function() { ...@@ -302,8 +303,8 @@ test( "jQuery.Deferred.then - context", function() {
strictEqual( value, 6, "proper value received" ); strictEqual( value, 6, "proper value received" );
}); });
var defer2 = jQuery.Deferred(), defer2 = jQuery.Deferred();
piped2 = defer2.then(); piped2 = defer2.then();
defer2.resolve( 2 ); defer2.resolve( 2 );
...@@ -319,7 +320,6 @@ test( "jQuery.when", function() { ...@@ -319,7 +320,6 @@ test( "jQuery.when", function() {
// Some other objects // Some other objects
jQuery.each({ jQuery.each({
"an empty string": "", "an empty string": "",
"a non-empty string": "some string", "a non-empty string": "some string",
"zero": 0, "zero": 0,
...@@ -329,9 +329,7 @@ test( "jQuery.when", function() { ...@@ -329,9 +329,7 @@ test( "jQuery.when", function() {
"null": null, "null": null,
"undefined": undefined, "undefined": undefined,
"a plain object": {} "a plain object": {}
}, function( message, value ) { }, function( message, value ) {
ok( ok(
jQuery.isFunction( jQuery.isFunction(
jQuery.when( value ).done(function( resolveValue ) { jQuery.when( value ).done(function( resolveValue ) {
...@@ -341,8 +339,7 @@ test( "jQuery.when", function() { ...@@ -341,8 +339,7 @@ test( "jQuery.when", function() {
), ),
"Test " + message + " triggers the creation of a new Promise" "Test " + message + " triggers the creation of a new Promise"
); );
});
} );
ok( ok(
jQuery.isFunction( jQuery.isFunction(
...@@ -354,14 +351,13 @@ test( "jQuery.when", function() { ...@@ -354,14 +351,13 @@ test( "jQuery.when", function() {
"Test calling when with no parameter triggers the creation of a new Promise" "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() { jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
strictEqual( this, context, "when( promise ) propagates context" ); strictEqual( this, context, "when( promise ) propagates context" );
}); });
var cache;
jQuery.each([ 1, 2, 3 ], function( k, i ) { jQuery.each([ 1, 2, 3 ], function( k, i ) {
jQuery.when( cache || jQuery.Deferred(function() { jQuery.when( cache || jQuery.Deferred(function() {
......
if ( jQuery.fn.width ) { (function() {
if ( !jQuery.fn.width ) {
return;
}
module("dimensions", { teardown: moduleTeardown }); module("dimensions", { teardown: moduleTeardown });
var pass = function( val ) { function pass( val ) {
return val; return val;
}; }
var fn = function( val ) { function fn( val ) {
return function() { return function() {
return val; return val;
}; };
}; }
/* /*
======== local reference ======= ======== local reference =======
...@@ -24,10 +28,11 @@ var fn = function( val ) { ...@@ -24,10 +28,11 @@ var fn = function( val ) {
Returns a function that returns the value Returns a function that returns the value
*/ */
var testWidth = function( val ) { function testWidth( val ) {
expect(9); expect(9);
var $div, blah;
var $div = jQuery("#nothiddendiv"); $div = jQuery("#nothiddendiv");
$div.width( val(30) ); $div.width( val(30) );
equal($div.width(), 30, "Test set to 30 correctly"); equal($div.width(), 30, "Test set to 30 correctly");
$div.hide(); $div.hide();
...@@ -46,14 +51,14 @@ var testWidth = function( val ) { ...@@ -46,14 +51,14 @@ var testWidth = function( val ) {
equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding"); equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" }); 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( 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( 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." ); equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" ); QUnit.expectJqData( $div[0], "olddisplay" );
}; }
test("width()", function() { test("width()", function() {
testWidth( pass ); testWidth( pass );
...@@ -75,10 +80,12 @@ test("width(Function(args))", function() { ...@@ -75,10 +80,12 @@ test("width(Function(args))", function() {
equal( $div.width(), 31, "Make sure value was modified correctly." ); equal( $div.width(), 31, "Make sure value was modified correctly." );
}); });
var testHeight = function( val ) { function testHeight( val ) {
expect(9); expect(9);
var $div = jQuery("#nothiddendiv"); var $div, blah;
$div = jQuery("#nothiddendiv");
$div.height( val(30) ); $div.height( val(30) );
equal($div.height(), 30, "Test set to 30 correctly"); equal($div.height(), 30, "Test set to 30 correctly");
$div.hide(); $div.hide();
...@@ -97,14 +104,14 @@ var testHeight = function( val ) { ...@@ -97,14 +104,14 @@ var testHeight = function( val ) {
equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding"); equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" }); 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( 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( 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." ); equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" ); QUnit.expectJqData( $div[0], "olddisplay" );
}; }
test("height()", function() { test("height()", function() {
testHeight( pass ); testHeight( pass );
...@@ -129,13 +136,14 @@ test("height(Function(args))", function() { ...@@ -129,13 +136,14 @@ test("height(Function(args))", function() {
test("innerWidth()", function() { test("innerWidth()", function() {
expect(6); expect(6);
var winWidth = jQuery( window ).width(), var $div, div,
winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width(); docWidth = jQuery( document ).width();
equal(jQuery(window).innerWidth(), winWidth, "Test on window"); equal(jQuery(window).innerWidth(), winWidth, "Test on window");
equal(jQuery(document).innerWidth(), docWidth, "Test on document"); equal(jQuery(document).innerWidth(), docWidth, "Test on document");
var $div = jQuery("#nothiddendiv"); $div = jQuery("#nothiddendiv");
// set styles // set styles
$div.css({ $div.css({
"margin": 10, "margin": 10,
...@@ -152,7 +160,7 @@ test("innerWidth()", function() { ...@@ -152,7 +160,7 @@ test("innerWidth()", function() {
// reset styles // reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." ); equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
...@@ -164,13 +172,14 @@ test("innerWidth()", function() { ...@@ -164,13 +172,14 @@ test("innerWidth()", function() {
test("innerHeight()", function() { test("innerHeight()", function() {
expect(6); expect(6);
var winHeight = jQuery( window ).height(), var $div, div,
winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height(); docHeight = jQuery( document ).height();
equal(jQuery(window).innerHeight(), winHeight, "Test on window"); equal(jQuery(window).innerHeight(), winHeight, "Test on window");
equal(jQuery(document).innerHeight(), docHeight, "Test on document"); equal(jQuery(document).innerHeight(), docHeight, "Test on document");
var $div = jQuery("#nothiddendiv"); $div = jQuery("#nothiddendiv");
// set styles // set styles
$div.css({ $div.css({
"margin": 10, "margin": 10,
...@@ -187,7 +196,7 @@ test("innerHeight()", function() { ...@@ -187,7 +196,7 @@ test("innerHeight()", function() {
// reset styles // reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." ); equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
...@@ -199,7 +208,8 @@ test("innerHeight()", function() { ...@@ -199,7 +208,8 @@ test("innerHeight()", function() {
test("outerWidth()", function() { test("outerWidth()", function() {
expect(11); expect(11);
var winWidth = jQuery( window ).width(), var $div, div,
winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width(); docWidth = jQuery( document ).width();
equal( jQuery( window ).outerWidth(), winWidth, "Test on window without margin option" ); equal( jQuery( window ).outerWidth(), winWidth, "Test on window without margin option" );
...@@ -207,7 +217,7 @@ test("outerWidth()", function() { ...@@ -207,7 +217,7 @@ test("outerWidth()", function() {
equal( jQuery( document ).outerWidth(), docWidth, "Test on document without margin option" ); equal( jQuery( document ).outerWidth(), docWidth, "Test on document without margin option" );
equal( jQuery( document ).outerWidth( true ), docWidth, "Test on document with 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); $div.css("width", 30);
equal($div.outerWidth(), 30, "Test with only width set"); equal($div.outerWidth(), 30, "Test with only width set");
...@@ -225,7 +235,7 @@ test("outerWidth()", function() { ...@@ -225,7 +235,7 @@ test("outerWidth()", function() {
// reset styles // reset styles
$div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." ); 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 ...@@ -345,7 +355,8 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
test("outerHeight()", function() { test("outerHeight()", function() {
expect(11); expect(11);
var winHeight = jQuery( window ).height(), var $div, div,
winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height(); docHeight = jQuery( document ).height();
...@@ -354,7 +365,7 @@ test("outerHeight()", function() { ...@@ -354,7 +365,7 @@ test("outerHeight()", function() {
equal( jQuery( document ).outerHeight(), docHeight, "Test on document without margin option" ); equal( jQuery( document ).outerHeight(), docHeight, "Test on document without margin option" );
equal( jQuery( document ).outerHeight( true ), docHeight, "Test on document with 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); $div.css("height", 30);
equal($div.outerHeight(), 30, "Test with only width set"); equal($div.outerHeight(), 30, "Test with only width set");
...@@ -371,7 +382,7 @@ test("outerHeight()", function() { ...@@ -371,7 +382,7 @@ test("outerHeight()", function() {
// reset styles // reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." ); equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
...@@ -458,4 +469,4 @@ testIframe( "dimensions/documentLarge", "window vs. large document", function( j ...@@ -458,4 +469,4 @@ testIframe( "dimensions/documentLarge", "window vs. large document", function( j
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" ); ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
}); });
} })();
This diff is collapsed.
This diff is collapsed.
...@@ -3,19 +3,19 @@ module( "manipulation", { ...@@ -3,19 +3,19 @@ module( "manipulation", {
}); });
// Ensure that an extended Array prototype doesn't break jQuery // 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"); throw("arrayProtoFn should not be called");
}; };
var manipulationBareObj = function( value ) { function manipulationBareObj( value ) {
return value; return value;
}; }
var manipulationFunctionReturningObj = function( value ) { function manipulationFunctionReturningObj( value ) {
return (function() { return function() {
return value; return value;
}); };
}; }
/* /*
======== local reference ======= ======== local reference =======
...@@ -62,7 +62,7 @@ test( "text(undefined)", function() { ...@@ -62,7 +62,7 @@ test( "text(undefined)", function() {
equal( jQuery("#foo").text("<div").text(undefined)[ 0 ].innerHTML, "&lt;div", ".text(undefined) is chainable (#5571)" ); 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 ); expect( 4 );
...@@ -79,7 +79,7 @@ var testText = function( valueObj ) { ...@@ -79,7 +79,7 @@ var testText = function( valueObj ) {
// Blackberry 4.6 doesn't maintain comments in the DOM // 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()" ); equal( jQuery("#nonnodes")[ 0 ].childNodes.length < 3 ? 8 : j[ 2 ].nodeType, 8, "Check node,textnode,comment with text()" );
}; }
test( "text(String)", function() { test( "text(String)", function() {
testText( manipulationBareObj ); testText( manipulationBareObj );
...@@ -103,7 +103,7 @@ test( "text(Function) with incoming value", function() { ...@@ -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." ); equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
}); });
var testWrap = function( val ) { function testWrap( val ) {
expect( 19 ); expect( 19 );
...@@ -183,7 +183,7 @@ var testWrap = function( val ) { ...@@ -183,7 +183,7 @@ var testWrap = function( val ) {
// clean up attached elements // clean up attached elements
QUnit.reset(); QUnit.reset();
}; }
test( "wrap(String|Element)", function() { test( "wrap(String|Element)", function() {
testWrap( manipulationBareObj ); testWrap( manipulationBareObj );
...@@ -220,7 +220,7 @@ test( "wrap(String) consecutive elements (#10177)", function() { ...@@ -220,7 +220,7 @@ test( "wrap(String) consecutive elements (#10177)", function() {
}); });
}); });
var testWrapAll = function( val ) { function testWrapAll( val ) {
expect( 8 ); expect( 8 );
...@@ -244,17 +244,17 @@ var testWrapAll = function( val ) { ...@@ -244,17 +244,17 @@ var testWrapAll = function( val ) {
equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" ); 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 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" ); equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
}; }
test( "wrapAll(String|Element)", function() { test( "wrapAll(String|Element)", function() {
testWrapAll( manipulationBareObj ); testWrapAll( manipulationBareObj );
}); });
var testWrapInner = function( val ) { function testWrapInner( val ) {
expect( 11 ); expect( 11 );
var num, result; var num, result, div;
num = jQuery("#first").children().length; num = jQuery("#first").children().length;
result = jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") ); result = jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
...@@ -277,11 +277,11 @@ var testWrapInner = function( val ) { ...@@ -277,11 +277,11 @@ var testWrapInner = function( val ) {
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" ); ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
var div = jQuery("<div/>"); div = jQuery("<div/>");
div.wrapInner( val("<span></span>") ); div.wrapInner( val("<span></span>") );
equal( div.children().length, 1, "The contents were wrapped." ); equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." ); equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
}; }
test( "wrapInner(String|Element)", function() { test( "wrapInner(String|Element)", function() {
testWrapInner( manipulationBareObj ); testWrapInner( manipulationBareObj );
...@@ -319,7 +319,7 @@ test( "unwrap()", function() { ...@@ -319,7 +319,7 @@ test( "unwrap()", function() {
jQuery("body > span.unwrap").remove(); jQuery("body > span.unwrap").remove();
}); });
var testAppendForObject = function( valueObj, isFragment ) { function testAppendForObject( valueObj, isFragment ) {
var $base, var $base,
type = isFragment ? " (DocumentFragment)" : " (Element)", type = isFragment ? " (DocumentFragment)" : " (Element)",
text = "This link has class=\"blog\": Simon Willison's Weblog", text = "This link has class=\"blog\": Simon Willison's Weblog",
...@@ -391,9 +391,9 @@ var testAppendForObject = function( valueObj, isFragment ) { ...@@ -391,9 +391,9 @@ var testAppendForObject = function( valueObj, isFragment ) {
1, 1,
"Check for appending a form (#910)" + type "Check for appending a form (#910)" + type
); );
}; }
var testAppend = function( valueObj ) { function testAppend( valueObj ) {
expect( 78 ); expect( 78 );
...@@ -500,7 +500,7 @@ var testAppend = function( valueObj ) { ...@@ -500,7 +500,7 @@ var testAppend = function( valueObj ) {
equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" ); 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" ); 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() { test( "append(String|Element|Array<Element>|jQuery)", function() {
testAppend( manipulationBareObj ); testAppend( manipulationBareObj );
...@@ -833,7 +833,7 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() { ...@@ -833,7 +833,7 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." ); equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );
}); });
var testPrepend = function( val ) { function testPrepend( val ) {
expect( 6 ); expect( 6 );
...@@ -864,7 +864,7 @@ var testPrepend = function( val ) { ...@@ -864,7 +864,7 @@ var testPrepend = function( val ) {
expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend( val([ jQuery("#first"), jQuery("#yahoo, #google") ]) ); jQuery("#sap").prepend( val([ jQuery("#first"), jQuery("#yahoo, #google") ]) );
equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" ); equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" );
}; }
test( "prepend(String|Element|Array<Element>|jQuery)", function() { test( "prepend(String|Element|Array<Element>|jQuery)", function() {
testPrepend( manipulationBareObj ); testPrepend( manipulationBareObj );
...@@ -963,7 +963,7 @@ test( "prependTo(String|Element|Array<Element>|jQuery)", function() { ...@@ -963,7 +963,7 @@ test( "prependTo(String|Element|Array<Element>|jQuery)", function() {
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] ); t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
}); });
var testBefore = function( val ) { function testBefore( val ) {
expect( 7 ); expect( 7 );
...@@ -996,7 +996,7 @@ var testBefore = function( val ) { ...@@ -996,7 +996,7 @@ var testBefore = function( val ) {
set = jQuery("<div/>").before("<span>test</span>"); 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[ 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" ); equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" );
}; }
test( "before(String|Element|Array<Element>|jQuery)", function() { test( "before(String|Element|Array<Element>|jQuery)", function() {
testBefore( manipulationBareObj ); testBefore( manipulationBareObj );
...@@ -1069,7 +1069,7 @@ test( "insertBefore(String|Element|Array<Element>|jQuery)", function() { ...@@ -1069,7 +1069,7 @@ test( "insertBefore(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery before" ); equal( jQuery("#en").text(), expected, "Insert jQuery before" );
}); });
var testAfter = function( val ) { function testAfter( val ) {
expect( 7 ); expect( 7 );
...@@ -1102,7 +1102,7 @@ var testAfter = function( val ) { ...@@ -1102,7 +1102,7 @@ var testAfter = function( val ) {
set = jQuery("<div/>").before("<span>test</span>"); 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[ 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" ); equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" );
}; }
test( "after(String|Element|Array<Element>|jQuery)", function() { test( "after(String|Element|Array<Element>|jQuery)", function() {
testAfter( manipulationBareObj ); testAfter( manipulationBareObj );
...@@ -1138,7 +1138,7 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() { ...@@ -1138,7 +1138,7 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery after" ); equal( jQuery("#en").text(), expected, "Insert jQuery after" );
}); });
var testReplaceWith = function( val ) { function testReplaceWith( val ) {
var tmp, y, child, child2, set, non_existent, $div, var tmp, y, child, child2, set, non_existent, $div,
expected = 23; expected = 23;
...@@ -1226,7 +1226,7 @@ var testReplaceWith = function( val ) { ...@@ -1226,7 +1226,7 @@ var testReplaceWith = function( val ) {
equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after subsequent replacement." ); equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after subsequent replacement." );
return expected; return expected;
}; }
test( "replaceWith(String|Element|Array<Element>|jQuery)", function() { test( "replaceWith(String|Element|Array<Element>|jQuery)", function() {
testReplaceWith( manipulationBareObj ); testReplaceWith( manipulationBareObj );
...@@ -1527,13 +1527,13 @@ test( "html() on empty set", function() { ...@@ -1527,13 +1527,13 @@ test( "html() on empty set", function() {
strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" ); 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 jQuery.map( node.childNodes, function( child ) {
return child.nodeName.toUpperCase(); return child.nodeName.toUpperCase();
}).join(" "); }).join(" ");
}; }
var testHtml = function( valueObj ) { function testHtml( valueObj ) {
expect( 37 ); expect( 37 );
var actual, expected, tmp, var actual, expected, tmp,
...@@ -1637,7 +1637,7 @@ var testHtml = function( valueObj ) { ...@@ -1637,7 +1637,7 @@ var testHtml = function( valueObj ) {
QUnit.reset(); QUnit.reset();
fixture.html( valueObj( fixture.text() ) ); fixture.html( valueObj( fixture.text() ) );
ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" ); ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" );
}; }
test( "html(String)", function() { test( "html(String)", function() {
testHtml( manipulationBareObj ); testHtml( manipulationBareObj );
...@@ -1740,7 +1740,7 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function() ...@@ -1740,7 +1740,7 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function()
ok( expected.test( $content.html() ), "html()" ); ok( expected.test( $content.html() ), "html()" );
}); });
var testRemove = function( method ) { function testRemove( method ) {
var markup, div, var markup, div,
first = jQuery("#ap").children().first(); first = jQuery("#ap").children().first();
...@@ -1750,7 +1750,7 @@ var testRemove = function( method ) { ...@@ -1750,7 +1750,7 @@ var testRemove = function( method ) {
ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
equal( jQuery("#ap").children().length, 0, "Check remove" ); 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(); QUnit.reset();
jQuery("#ap").children()[ method ]("a"); jQuery("#ap").children()[ method ]("a");
...@@ -1782,7 +1782,7 @@ var testRemove = function( method ) { ...@@ -1782,7 +1782,7 @@ var testRemove = function( method ) {
if (method === "detach") { if (method === "detach") {
first.remove(); first.remove();
} }
}; }
test( "remove()", 11, function() { test( "remove()", 11, function() {
testRemove("remove"); testRemove("remove");
...@@ -2021,7 +2021,7 @@ test( "Cloned, detached HTML5 elems (#10667,10670)", function() { ...@@ -2021,7 +2021,7 @@ test( "Cloned, detached HTML5 elems (#10667,10670)", function() {
} }
// Bind an event // Bind an event
$section.on( "click", function( event ) { $section.on( "click", function() {
ok( true, "clone fired event" ); ok( true, "clone fired event" );
}); });
......
...@@ -95,8 +95,10 @@ testIframe("offset/absolute", "absolute", function($, iframe) { ...@@ -95,8 +95,10 @@ testIframe("offset/absolute", "absolute", function($, iframe) {
testIframe("offset/absolute", "absolute", function( $ ) { testIframe("offset/absolute", "absolute", function( $ ) {
expect(178); expect(178);
var tests, offset;
// get offset tests // get offset tests
var tests = [ tests = [
{ "id": "#absolute-1", "top": 1, "left": 1 }, { "id": "#absolute-1", "top": 1, "left": 1 },
{ "id": "#absolute-1-1", "top": 5, "left": 5 }, { "id": "#absolute-1-1", "top": 5, "left": 5 },
{ "id": "#absolute-1-1-1", "top": 9, "left": 9 }, { "id": "#absolute-1-1-1", "top": 9, "left": 9 },
...@@ -121,7 +123,7 @@ testIframe("offset/absolute", "absolute", function( $ ) { ...@@ -121,7 +123,7 @@ testIframe("offset/absolute", "absolute", function( $ ) {
}); });
// test #5781 // 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.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." ); equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
...@@ -180,11 +182,13 @@ testIframe("offset/absolute", "absolute", function( $ ) { ...@@ -180,11 +182,13 @@ testIframe("offset/absolute", "absolute", function( $ ) {
testIframe("offset/relative", "relative", function( $ ) { testIframe("offset/relative", "relative", function( $ ) {
expect(60); expect(60);
var ie, tests;
// IE is collapsing the top margin of 1px; detect and adjust accordingly // 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 // get offset
var tests = [ tests = [
{ "id": "#relative-1", "top": ie ? 6 : 7, "left": 7 }, { "id": "#relative-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#relative-1-1", "top": ie ? 13 : 15, "left": 15 }, { "id": "#relative-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#relative-2", "top": ie ? 141 : 142, "left": 27 } { "id": "#relative-2", "top": ie ? 141 : 142, "left": 27 }
...@@ -239,14 +243,15 @@ testIframe("offset/relative", "relative", function( $ ) { ...@@ -239,14 +243,15 @@ testIframe("offset/relative", "relative", function( $ ) {
}); });
testIframe("offset/static", "static", function( $ ) { testIframe("offset/static", "static", function( $ ) {
expect( 80 );
// IE is collapsing the top margin of 1px; detect and adjust accordingly var ie, tests;
var ie = $("#static-1").offset().top === 6;
expect( 80 ); // IE is collapsing the top margin of 1px; detect and adjust accordingly
ie = $("#static-1").offset().top === 6;
// get offset // get offset
var tests = [ tests = [
{ "id": "#static-1", "top": ie ? 6 : 7, "left": 7 }, { "id": "#static-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#static-1-1", "top": ie ? 13 : 15, "left": 15 }, { "id": "#static-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#static-1-1-1", "top": ie ? 20 : 23, "left": 23 }, { "id": "#static-1-1-1", "top": ie ? 20 : 23, "left": 23 },
...@@ -307,12 +312,14 @@ testIframe("offset/static", "static", function( $ ) { ...@@ -307,12 +312,14 @@ testIframe("offset/static", "static", function( $ ) {
}); });
testIframe("offset/fixed", "fixed", 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); 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", "id": "#fixed-1",
"offsetTop": 1001, "offsetTop": 1001,
...@@ -383,7 +390,7 @@ testIframe("offset/fixed", "fixed", function( $ ) { ...@@ -383,7 +390,7 @@ testIframe("offset/fixed", "fixed", function( $ ) {
}); });
// Bug 8316 // Bug 8316
var $noTopLeft = $("#fixed-no-top-left"); $noTopLeft = $("#fixed-no-top-left");
if ( window.supportsFixedPosition ) { if ( window.supportsFixedPosition ) {
equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" ); 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" ); equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
...@@ -488,15 +495,17 @@ test("chaining", function() { ...@@ -488,15 +495,17 @@ test("chaining", function() {
test("offsetParent", function(){ test("offsetParent", function(){
expect(13); 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.length, 1, "Only one offsetParent found." );
equal( body[0], document.documentElement, "The html element is the offsetParent of the body." ); 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.length, 1, "Only one offsetParent found." );
equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." ); 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.length, 1, "Only one offsetParent found." );
equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." ); equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
...@@ -511,7 +520,7 @@ test("offsetParent", function(){ ...@@ -511,7 +520,7 @@ test("offsetParent", function(){
equal( div[0], document.documentElement, "The html element is the offsetParent of the body." ); 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." ); 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." ); equal( area[0], document.documentElement, "The html element is the offsetParent of the body." );
div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body"); div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body");
...@@ -525,8 +534,9 @@ test("fractions (see #7730 and #7885)", function() { ...@@ -525,8 +534,9 @@ test("fractions (see #7730 and #7885)", function() {
jQuery("body").append("<div id='fractions'/>"); jQuery("body").append("<div id='fractions'/>");
var expected = { "top": 1000, "left": 1000 }; var result,
var div = jQuery("#fractions"); expected = { "top": 1000, "left": 1000 },
div = jQuery("#fractions");
div.css({ div.css({
"position": "absolute", "position": "absolute",
...@@ -538,7 +548,7 @@ test("fractions (see #7730 and #7885)", function() { ...@@ -538,7 +548,7 @@ test("fractions (see #7730 and #7885)", function() {
div.offset(expected); div.offset(expected);
var result = div.offset(); result = div.offset();
equal( result.top, expected.top, "Check top" ); equal( result.top, expected.top, "Check top" );
equal( result.left, expected.left, "Check left" ); equal( result.left, expected.left, "Check left" );
......
module( "queue", { teardown: moduleTeardown }); module( "queue", { teardown: moduleTeardown });
test( "queue() with other types", 14, function() { test( "queue() with other types", 14, function() {
var counter = 0;
stop(); stop();
var $div = jQuery({}), var defer,
defer; $div = jQuery({}),
counter = 0;
$div.promise( "foo" ).done(function() { $div.promise( "foo" ).done(function() {
equal( counter, 0, "Deferred for collection with no queue is automatically resolved" ); equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
}); });
...@@ -56,8 +56,8 @@ test( "queue() with other types", 14, function() { ...@@ -56,8 +56,8 @@ test( "queue() with other types", 14, function() {
test("queue(name) passes in the next item in the queue as a parameter", function() { test("queue(name) passes in the next item in the queue as a parameter", function() {
expect(2); expect(2);
var div = jQuery({}); var div = jQuery({}),
var counter = 0; counter = 0;
div.queue("foo", function(next) { div.queue("foo", function(next) {
equal(++counter, 1, "Dequeueing"); equal(++counter, 1, "Dequeueing");
...@@ -76,12 +76,11 @@ test("queue() passes in the next item in the queue as a parameter to fx queues", ...@@ -76,12 +76,11 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
expect(3); expect(3);
stop(); stop();
var div = jQuery({}); var div = jQuery({}),
var counter = 0; counter = 0;
div.queue(function(next) { div.queue(function( next ) {
equal(++counter, 1, "Dequeueing"); equal(++counter, 1, "Dequeueing");
var self = this;
setTimeout(function() { next(); }, 500); setTimeout(function() { next(); }, 500);
}).queue(function(next) { }).queue(function(next) {
equal(++counter, 2, "Next was called"); equal(++counter, 2, "Next was called");
...@@ -143,14 +142,14 @@ test("clearQueue(name) clears the queue", function() { ...@@ -143,14 +142,14 @@ test("clearQueue(name) clears the queue", function() {
stop(); stop();
var div = jQuery({}); var div = jQuery({}),
var counter = 0; counter = 0;
div.queue("foo", function(next) { div.queue("foo", function( next ) {
counter++; counter++;
jQuery(this).clearQueue("foo"); jQuery(this).clearQueue("foo");
next(); next();
}).queue("foo", function(next) { }).queue("foo", function() {
counter++; counter++;
}); });
...@@ -167,14 +166,14 @@ test("clearQueue(name) clears the queue", function() { ...@@ -167,14 +166,14 @@ test("clearQueue(name) clears the queue", function() {
test("clearQueue() clears the fx queue", function() { test("clearQueue() clears the fx queue", function() {
expect(1); expect(1);
var div = jQuery({}); var div = jQuery({}),
var counter = 0; counter = 0;
div.queue(function(next) { div.queue(function( next ) {
counter++; counter++;
var self = this; var self = this;
setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50); setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
}).queue(function(next) { }).queue(function() {
counter++; counter++;
}); });
...@@ -246,8 +245,8 @@ asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before res ...@@ -246,8 +245,8 @@ asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before res
test( ".promise(obj)", function() { test( ".promise(obj)", function() {
expect(2); expect(2);
var obj = {}; var obj = {},
var promise = jQuery( "#foo" ).promise( "promise", obj ); promise = jQuery( "#foo" ).promise( "promise", obj );
ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" ); ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
strictEqual( promise, obj, ".promise(type, obj) returns obj" ); strictEqual( promise, obj, ".promise(type, obj) returns obj" );
......
...@@ -3,9 +3,11 @@ module("serialize", { teardown: moduleTeardown }); ...@@ -3,9 +3,11 @@ module("serialize", { teardown: moduleTeardown });
test("jQuery.param()", function() { test("jQuery.param()", function() {
expect(22); expect(22);
var params, settings;
equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" ); 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" ); equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"string":"foo","null":null,"undefined":undefined}; params = {"string":"foo","null":null,"undefined":undefined};
...@@ -37,7 +39,7 @@ test("jQuery.param()", function() { ...@@ -37,7 +39,7 @@ test("jQuery.param()", function() {
// #7945 // #7945
equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" ); 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 ) { if ( jQuery.ajaxSettings ) {
jQuery.ajaxSetup( settings ); jQuery.ajaxSetup( settings );
......
...@@ -143,12 +143,13 @@ test("is() with :has() selectors", function() { ...@@ -143,12 +143,13 @@ test("is() with :has() selectors", function() {
test("is() with positional selectors", function() { test("is() with positional selectors", function() {
expect(24); expect(24);
var html = jQuery( jQuery(
"<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>" "<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>"
).appendTo( "#qunit-fixture" ), ).appendTo( "#qunit-fixture" );
isit = function(sel, match, expect) {
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" ); var isit = function(sel, match, expect) {
}; equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" );
};
isit( "#posp", "#posp:first", true ); isit( "#posp", "#posp:first", true );
isit( "#posp", "#posp:eq(2)", false ); isit( "#posp", "#posp:eq(2)", false );
...@@ -271,19 +272,20 @@ test("filter(jQuery)", function() { ...@@ -271,19 +272,20 @@ test("filter(jQuery)", function() {
test("filter() with positional selectors", function() { test("filter() with positional selectors", function() {
expect(19); expect(19);
var html = jQuery( "" + jQuery( "" +
"<p id='posp'>" + "<p id='posp'>" +
"<a class='firsta' href='#'>" + "<a class='firsta' href='#'>" +
"<em>first</em>" + "<em>first</em>" +
"</a>" + "</a>" +
"<a class='seconda' href='#'>" + "<a class='seconda' href='#'>" +
"<b>test</b>" + "<b>test</b>" +
"</a>" + "</a>" +
"<em></em>" + "<em></em>" +
"</p>" ).appendTo( "#qunit-fixture" ), "</p>" ).appendTo( "#qunit-fixture" );
filterit = function(sel, filter, length) {
equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); var filterit = function(sel, filter, length) {
}; equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" );
};
filterit( "#posp", "#posp:first", 1); filterit( "#posp", "#posp:first", 1);
filterit( "#posp", "#posp:eq(2)", 0 ); filterit( "#posp", "#posp:eq(2)", 0 );
...@@ -416,50 +418,55 @@ test("not(jQuery)", function() { ...@@ -416,50 +418,55 @@ test("not(jQuery)", function() {
test("has(Element)", function() { test("has(Element)", function() {
expect(3); 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" ); 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" ); 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( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
}); });
test("has(Selector)", function() { test("has(Selector)", function() {
expect( 5 ); 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" ); 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" ); 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" ); 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"); multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a");
deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" ); 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" ); deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
}); });
test("has(Arrayish)", function() { test("has(Arrayish)", function() {
expect(4); 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" ); 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" ); 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" ); 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( simple.get(), q("qunit-fixture"), "Only adds elements once" ); deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
}); });
test("addBack()", function() { test("addBack()", function() {
...@@ -476,6 +483,7 @@ test("siblings([String])", function() { ...@@ -476,6 +483,7 @@ test("siblings([String])", function() {
deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); 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("#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" ); deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
var set = q("sndp", "en", "sap"); var set = q("sndp", "en", "sap");
deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" ); 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)" ); deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
...@@ -624,9 +632,11 @@ test("prevUntil([String])", function() { ...@@ -624,9 +632,11 @@ test("prevUntil([String])", function() {
test("contents()", function() { test("contents()", function() {
expect(12); expect(12);
var ibody, c;
equal( jQuery("#ap").contents().length, 9, "Check element contents" ); equal( jQuery("#ap").contents().length, 9, "Check element contents" );
ok( jQuery("#iframe").contents()[0], "Check existence of IFrame document" ); 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" ); ok( ibody, "Check existence of IFrame body" );
equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" ); equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
...@@ -649,13 +659,16 @@ test("contents()", function() { ...@@ -649,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" ); 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 // 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.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" ); equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
}); });
test("add(String|Element|Array|undefined)", function() { test("add(String|Element|Array|undefined)", function() {
expect( 15 ); 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("#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" ); deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
...@@ -669,15 +682,15 @@ test("add(String|Element|Array|undefined)", function() { ...@@ -669,15 +682,15 @@ test("add(String|Element|Array|undefined)", function() {
// use jQuery([]).add(form.elements) instead. // 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()" ); //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)." ); ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
divs = jQuery("#sndp").add("<div/>"); divs = jQuery("#sndp").add("<div/>");
ok( !divs[1].parentNode, "Sort with the disconnected node last." ); 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[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" ); equal( x[1].id, "x2", "Check on-the-fly element2" );
...@@ -693,7 +706,6 @@ test("add(String|Element|Array|undefined)", function() { ...@@ -693,7 +706,6 @@ test("add(String|Element|Array|undefined)", function() {
equal( x[0].id, "x1", "Check on-the-fly element1" ); equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" ); 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(notDefined).length, 0, "Check that undefined adds nothing" );
equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" ); equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
...@@ -723,12 +735,18 @@ test("eq('-1') #10616", function() { ...@@ -723,12 +735,18 @@ test("eq('-1') #10616", function() {
}); });
test("index(no arg) #10977", function() { test("index(no arg) #10977", function() {
expect(1); 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 ); jQuery("#qunit-fixture").append( $list );
strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" ); strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" );
$list.remove(); $list.remove();
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" );
}); });
test("traversing non-elements with attribute filters (#12523)", function() { test("traversing non-elements with attribute filters (#12523)", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment