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,
"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
}
}
\ No newline at end of file
......@@ -411,7 +411,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 )
......@@ -426,8 +426,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,
......
{
"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,
"evil": true,
"sub": true,
"boss": true,
"browser": true,
"wsh": true,
"predef": [
"define",
"module",
"jQuery"
]
"globals": {
"define": true,
"module": true,
"jQuery": true
}
}
{
"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,
......
var testBar = "bar";
this.testBar = "bar";
jQuery("#ap").html("bar");
ok( true, "test.js executed");
......@@ -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" );
});
};
......@@ -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 ) {
......
......@@ -498,10 +498,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" );
}
});
......@@ -571,14 +571,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;
});
......@@ -842,7 +842,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)" );
}
});
......@@ -866,7 +866,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)" );
}
});
......@@ -1295,9 +1295,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;
......@@ -1313,7 +1314,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;
},
......@@ -1577,12 +1578,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();
};
......@@ -1700,7 +1701,7 @@ module( "ajax", {
Globals.register("JSON");
}
window.JSON = {
parse: function( str ) {
parse: function() {
ok( true, "Verifying that parse method was run" );
window.JSON = old;
return true;
......@@ -1724,7 +1725,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();
});
......@@ -1861,8 +1862,7 @@ module( "ajax", {
});
asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() {
var slice = [].slice,
completeArgs = {};
var completeArgs = {};
jQuery.ajaxSetup({
success: function( _, status, jqXHR ) {
......
This diff is collapsed.
......@@ -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() {
......
This diff is collapsed.
This diff is collapsed.
......@@ -7,7 +7,7 @@ test("expando", function(){
});
function dataTests (elem) {
var oldCacheLength, dataObj, internalDataObj, expected, actual;
var dataObj, internalDataObj;
equal( jQuery.data(elem, "foo"), undefined, "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() {
test("jQuery.acceptData", function() {
expect(9);
var flash, applet;
ok( jQuery.acceptData( document ), "document" );
ok( jQuery.acceptData( document.documentElement ), "documentElement" );
ok( jQuery.acceptData( {} ), "object" );
ok( !jQuery.acceptData( document.createElement("embed") ), "embed" );
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");
ok( jQuery.acceptData( flash ), "flash" );
var applet = document.createElement("object");
applet = document.createElement("object");
applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
ok( !jQuery.acceptData( applet ), "applet" );
......@@ -165,19 +167,21 @@ test("jQuery.acceptData", 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());
......@@ -185,7 +189,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,
......@@ -203,7 +207,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 );
......@@ -236,7 +240,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>");
......@@ -262,16 +268,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-." );
}
......@@ -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>",
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();
......@@ -363,14 +368,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" );
......@@ -382,7 +389,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" );
......@@ -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"), "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");
......@@ -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 );
var div, plain, compare;
......
......@@ -47,7 +47,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
funcPromise = defer.promise( func );
strictEqual( defer.promise(), promise, "promise is always the same" );
strictEqual( funcPromise, func, "non objects get extended" );
jQuery.each( promise, function( key, value ) {
jQuery.each( promise, function( key ) {
if ( !jQuery.isFunction( promise[ key ] ) ) {
ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
}
......@@ -275,7 +275,8 @@ test( "jQuery.Deferred.then - context", function() {
expect( 7 );
var context = {};
var defer, piped, defer2, piped2,
context = {};
jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
return value * 3;
......@@ -290,10 +291,10 @@ test( "jQuery.Deferred.then - context", function() {
strictEqual( this, context, "custom context of returned deferred correctly propagated" );
});
var defer = jQuery.Deferred(),
piped = defer.then(function( value ) {
return value * 3;
});
defer = jQuery.Deferred();
piped = defer.then(function( value ) {
return value * 3;
});
defer.resolve( 2 );
......@@ -302,8 +303,8 @@ test( "jQuery.Deferred.then - context", function() {
strictEqual( value, 6, "proper value received" );
});
var defer2 = jQuery.Deferred(),
piped2 = defer2.then();
defer2 = jQuery.Deferred();
piped2 = defer2.then();
defer2.resolve( 2 );
......@@ -319,7 +320,6 @@ test( "jQuery.when", function() {
// Some other objects
jQuery.each({
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
......@@ -329,9 +329,7 @@ test( "jQuery.when", function() {
"null": null,
"undefined": undefined,
"a plain object": {}
}, function( message, value ) {
ok(
jQuery.isFunction(
jQuery.when( value ).done(function( resolveValue ) {
......@@ -341,8 +339,7 @@ test( "jQuery.when", function() {
),
"Test " + message + " triggers the creation of a new Promise"
);
} );
});
ok(
jQuery.isFunction(
......@@ -354,14 +351,13 @@ test( "jQuery.when", function() {
"Test calling when with no parameter triggers the creation of a new Promise"
);
var context = {};
var cache,
context = {};
jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
strictEqual( this, context, "when( promise ) propagates context" );
});
var cache;
jQuery.each([ 1, 2, 3 ], function( k, i ) {
jQuery.when( cache || jQuery.Deferred(function() {
......
if ( jQuery.fn.width ) {
(function() {
if ( !jQuery.fn.width ) {
return;
}
module("dimensions", { teardown: moduleTeardown });
var pass = function( val ) {
function pass( val ) {
return val;
};
}
var fn = function( val ) {
function fn( val ) {
return function() {
return val;
};
};
}
/*
======== local reference =======
......@@ -24,10 +28,11 @@ var fn = function( val ) {
Returns a function that returns the value
*/
var testWidth = function( val ) {
function testWidth( val ) {
expect(9);
var $div, blah;
var $div = jQuery("#nothiddendiv");
$div = jQuery("#nothiddendiv");
$div.width( val(30) );
equal($div.width(), 30, "Test set to 30 correctly");
$div.hide();
......@@ -46,14 +51,14 @@ var testWidth = function( val ) {
equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" });
var blah = jQuery("blah");
blah = jQuery("blah");
equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
equal( blah.width(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" );
};
}
test("width()", function() {
testWidth( pass );
......@@ -75,10 +80,12 @@ test("width(Function(args))", function() {
equal( $div.width(), 31, "Make sure value was modified correctly." );
});
var testHeight = function( val ) {
function testHeight( val ) {
expect(9);
var $div = jQuery("#nothiddendiv");
var $div, blah;
$div = jQuery("#nothiddendiv");
$div.height( val(30) );
equal($div.height(), 30, "Test set to 30 correctly");
$div.hide();
......@@ -97,14 +104,14 @@ var testHeight = function( val ) {
equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" });
var blah = jQuery("blah");
blah = jQuery("blah");
equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
equal( blah.height(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" );
};
}
test("height()", function() {
testHeight( pass );
......@@ -129,13 +136,14 @@ test("height(Function(args))", function() {
test("innerWidth()", function() {
expect(6);
var winWidth = jQuery( window ).width(),
var $div, div,
winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width();
equal(jQuery(window).innerWidth(), winWidth, "Test on window");
equal(jQuery(document).innerWidth(), docWidth, "Test on document");
var $div = jQuery("#nothiddendiv");
$div = jQuery("#nothiddendiv");
// set styles
$div.css({
"margin": 10,
......@@ -152,7 +160,7 @@ test("innerWidth()", function() {
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
......@@ -164,13 +172,14 @@ test("innerWidth()", function() {
test("innerHeight()", function() {
expect(6);
var winHeight = jQuery( window ).height(),
var $div, div,
winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height();
equal(jQuery(window).innerHeight(), winHeight, "Test on window");
equal(jQuery(document).innerHeight(), docHeight, "Test on document");
var $div = jQuery("#nothiddendiv");
$div = jQuery("#nothiddendiv");
// set styles
$div.css({
"margin": 10,
......@@ -187,7 +196,7 @@ test("innerHeight()", function() {
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
......@@ -199,7 +208,8 @@ test("innerHeight()", function() {
test("outerWidth()", function() {
expect(11);
var winWidth = jQuery( window ).width(),
var $div, div,
winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width();
equal( jQuery( window ).outerWidth(), winWidth, "Test on window without margin option" );
......@@ -207,7 +217,7 @@ test("outerWidth()", function() {
equal( jQuery( document ).outerWidth(), docWidth, "Test on document without margin option" );
equal( jQuery( document ).outerWidth( true ), docWidth, "Test on document with margin option" );
var $div = jQuery("#nothiddendiv");
$div = jQuery("#nothiddendiv");
$div.css("width", 30);
equal($div.outerWidth(), 30, "Test with only width set");
......@@ -225,7 +235,7 @@ test("outerWidth()", function() {
// reset styles
$div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
......@@ -345,7 +355,8 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
test("outerHeight()", function() {
expect(11);
var winHeight = jQuery( window ).height(),
var $div, div,
winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height();
......@@ -354,7 +365,7 @@ test("outerHeight()", function() {
equal( jQuery( document ).outerHeight(), docHeight, "Test on document without margin option" );
equal( jQuery( document ).outerHeight( true ), docHeight, "Test on document with margin option" );
var $div = jQuery("#nothiddendiv");
$div = jQuery("#nothiddendiv");
$div.css("height", 30);
equal($div.outerHeight(), 30, "Test with only width set");
......@@ -371,7 +382,7 @@ test("outerHeight()", function() {
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
......@@ -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" );
});
}
})();
This diff is collapsed.
This diff is collapsed.
......@@ -3,19 +3,19 @@ module( "manipulation", {
});
// Ensure that an extended Array prototype doesn't break jQuery
Array.prototype.arrayProtoFn = function( arg ) {
Array.prototype.arrayProtoFn = function() {
throw("arrayProtoFn should not be called");
};
var manipulationBareObj = function( value ) {
function manipulationBareObj( value ) {
return value;
};
}
var manipulationFunctionReturningObj = function( value ) {
return (function() {
function manipulationFunctionReturningObj( value ) {
return function() {
return value;
});
};
};
}
/*
======== local reference =======
......@@ -62,7 +62,7 @@ test( "text(undefined)", function() {
equal( jQuery("#foo").text("<div").text(undefined)[ 0 ].innerHTML, "&lt;div", ".text(undefined) is chainable (#5571)" );
});
var testText = function( valueObj ) {
function testText( valueObj ) {
expect( 4 );
......@@ -79,7 +79,7 @@ var testText = function( valueObj ) {
// Blackberry 4.6 doesn't maintain comments in the DOM
equal( jQuery("#nonnodes")[ 0 ].childNodes.length < 3 ? 8 : j[ 2 ].nodeType, 8, "Check node,textnode,comment with text()" );
};
}
test( "text(String)", function() {
testText( manipulationBareObj );
......@@ -103,7 +103,7 @@ test( "text(Function) with incoming value", function() {
equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
});
var testWrap = function( val ) {
function testWrap( val ) {
expect( 19 );
......@@ -183,7 +183,7 @@ var testWrap = function( val ) {
// clean up attached elements
QUnit.reset();
};
}
test( "wrap(String|Element)", function() {
testWrap( manipulationBareObj );
......@@ -220,7 +220,7 @@ test( "wrap(String) consecutive elements (#10177)", function() {
});
});
var testWrapAll = function( val ) {
function testWrapAll( val ) {
expect( 8 );
......@@ -244,17 +244,17 @@ var testWrapAll = function( val ) {
equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" );
equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
};
}
test( "wrapAll(String|Element)", function() {
testWrapAll( manipulationBareObj );
});
var testWrapInner = function( val ) {
function testWrapInner( val ) {
expect( 11 );
var num, result;
var num, result, div;
num = jQuery("#first").children().length;
result = jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
......@@ -277,11 +277,11 @@ var testWrapInner = function( val ) {
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
var div = jQuery("<div/>");
div = jQuery("<div/>");
div.wrapInner( val("<span></span>") );
equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
};
}
test( "wrapInner(String|Element)", function() {
testWrapInner( manipulationBareObj );
......@@ -319,7 +319,7 @@ test( "unwrap()", function() {
jQuery("body > span.unwrap").remove();
});
var testAppendForObject = function( valueObj, isFragment ) {
function testAppendForObject( valueObj, isFragment ) {
var $base,
type = isFragment ? " (DocumentFragment)" : " (Element)",
text = "This link has class=\"blog\": Simon Willison's Weblog",
......@@ -391,9 +391,9 @@ var testAppendForObject = function( valueObj, isFragment ) {
1,
"Check for appending a form (#910)" + type
);
};
}
var testAppend = function( valueObj ) {
function testAppend( valueObj ) {
expect( 78 );
......@@ -500,7 +500,7 @@ var testAppend = function( valueObj ) {
equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" );
equal( jQuery("<div/>").append( valueObj("option<area/>") )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
};
}
test( "append(String|Element|Array<Element>|jQuery)", function() {
testAppend( manipulationBareObj );
......@@ -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." );
});
var testPrepend = function( val ) {
function testPrepend( val ) {
expect( 6 );
......@@ -864,7 +864,7 @@ var testPrepend = function( val ) {
expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend( val([ jQuery("#first"), jQuery("#yahoo, #google") ]) );
equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" );
};
}
test( "prepend(String|Element|Array<Element>|jQuery)", function() {
testPrepend( manipulationBareObj );
......@@ -963,7 +963,7 @@ test( "prependTo(String|Element|Array<Element>|jQuery)", function() {
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
});
var testBefore = function( val ) {
function testBefore( val ) {
expect( 7 );
......@@ -996,7 +996,7 @@ var testBefore = function( val ) {
set = jQuery("<div/>").before("<span>test</span>");
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert before a disconnected node should be a no-op" );
equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" );
};
}
test( "before(String|Element|Array<Element>|jQuery)", function() {
testBefore( manipulationBareObj );
......@@ -1069,7 +1069,7 @@ test( "insertBefore(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery before" );
});
var testAfter = function( val ) {
function testAfter( val ) {
expect( 7 );
......@@ -1102,7 +1102,7 @@ var testAfter = function( val ) {
set = jQuery("<div/>").before("<span>test</span>");
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert after a disconnected node should be a no-op" );
equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" );
};
}
test( "after(String|Element|Array<Element>|jQuery)", function() {
testAfter( manipulationBareObj );
......@@ -1138,7 +1138,7 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery after" );
});
var testReplaceWith = function( val ) {
function testReplaceWith( val ) {
var tmp, y, child, child2, set, non_existent, $div,
expected = 23;
......@@ -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." );
return expected;
};
}
test( "replaceWith(String|Element|Array<Element>|jQuery)", function() {
testReplaceWith( manipulationBareObj );
......@@ -1527,13 +1527,13 @@ test( "html() on empty set", function() {
strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" );
});
var childNodeNames = function( node ) {
function childNodeNames( node ) {
return jQuery.map( node.childNodes, function( child ) {
return child.nodeName.toUpperCase();
}).join(" ");
};
}
var testHtml = function( valueObj ) {
function testHtml( valueObj ) {
expect( 37 );
var actual, expected, tmp,
......@@ -1637,7 +1637,7 @@ var testHtml = function( valueObj ) {
QUnit.reset();
fixture.html( valueObj( fixture.text() ) );
ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" );
};
}
test( "html(String)", function() {
testHtml( manipulationBareObj );
......@@ -1740,7 +1740,7 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function()
ok( expected.test( $content.html() ), "html()" );
});
var testRemove = function( method ) {
function testRemove( method ) {
var markup, div,
first = jQuery("#ap").children().first();
......@@ -1750,7 +1750,7 @@ var testRemove = function( method ) {
ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
equal( jQuery("#ap").children().length, 0, "Check remove" );
equal( first.data("foo"), method == "remove" ? null : "bar", "first data" );
equal( first.data("foo"), method === "remove" ? null : "bar", "first data" );
QUnit.reset();
jQuery("#ap").children()[ method ]("a");
......@@ -1782,7 +1782,7 @@ var testRemove = function( method ) {
if (method === "detach") {
first.remove();
}
};
}
test( "remove()", 11, function() {
testRemove("remove");
......@@ -2021,7 +2021,7 @@ test( "Cloned, detached HTML5 elems (#10667,10670)", function() {
}
// Bind an event
$section.on( "click", function( event ) {
$section.on( "click", function() {
ok( true, "clone fired event" );
});
......
......@@ -95,8 +95,10 @@ testIframe("offset/absolute", "absolute", function($, iframe) {
testIframe("offset/absolute", "absolute", function( $ ) {
expect(178);
var tests, offset;
// get offset tests
var tests = [
tests = [
{ "id": "#absolute-1", "top": 1, "left": 1 },
{ "id": "#absolute-1-1", "top": 5, "left": 5 },
{ "id": "#absolute-1-1-1", "top": 9, "left": 9 },
......@@ -121,7 +123,7 @@ testIframe("offset/absolute", "absolute", function( $ ) {
});
// test #5781
var offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
......@@ -180,11 +182,13 @@ testIframe("offset/absolute", "absolute", function( $ ) {
testIframe("offset/relative", "relative", function( $ ) {
expect(60);
var ie, tests;
// IE is collapsing the top margin of 1px; detect and adjust accordingly
var ie = $("#relative-1").offset().top === 6;
ie = $("#relative-1").offset().top === 6;
// get offset
var tests = [
tests = [
{ "id": "#relative-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#relative-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#relative-2", "top": ie ? 141 : 142, "left": 27 }
......@@ -239,14 +243,15 @@ testIframe("offset/relative", "relative", function( $ ) {
});
testIframe("offset/static", "static", function( $ ) {
expect( 80 );
// IE is collapsing the top margin of 1px; detect and adjust accordingly
var ie = $("#static-1").offset().top === 6;
var ie, tests;
expect( 80 );
// IE is collapsing the top margin of 1px; detect and adjust accordingly
ie = $("#static-1").offset().top === 6;
// get offset
var tests = [
tests = [
{ "id": "#static-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#static-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#static-1-1-1", "top": ie ? 20 : 23, "left": 23 },
......@@ -307,12 +312,14 @@ testIframe("offset/static", "static", function( $ ) {
});
testIframe("offset/fixed", "fixed", function( $ ) {
// IE is collapsing the top margin of 1px; detect and adjust accordingly
var ie = $("#fixed-1").position().top === 2;
expect(34);
var tests = [
var ie, tests, $noTopLeft;
// IE is collapsing the top margin of 1px; detect and adjust accordingly
ie = $("#fixed-1").position().top === 2;
tests = [
{
"id": "#fixed-1",
"offsetTop": 1001,
......@@ -383,7 +390,7 @@ testIframe("offset/fixed", "fixed", function( $ ) {
});
// Bug 8316
var $noTopLeft = $("#fixed-no-top-left");
$noTopLeft = $("#fixed-no-top-left");
if ( window.supportsFixedPosition ) {
equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
......@@ -488,15 +495,17 @@ test("chaining", function() {
test("offsetParent", function(){
expect(13);
var body = jQuery("body").offsetParent();
var body, header, div, area;
body = jQuery("body").offsetParent();
equal( body.length, 1, "Only one offsetParent found." );
equal( body[0], document.documentElement, "The html element is the offsetParent of the body." );
var header = jQuery("#qunit").offsetParent();
header = jQuery("#qunit").offsetParent();
equal( header.length, 1, "Only one offsetParent found." );
equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." );
var div = jQuery("#nothiddendivchild").offsetParent();
div = jQuery("#nothiddendivchild").offsetParent();
equal( div.length, 1, "Only one offsetParent found." );
equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
......@@ -511,7 +520,7 @@ test("offsetParent", function(){
equal( div[0], document.documentElement, "The html element is the offsetParent of the body." );
equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
var area = jQuery("#imgmap area").offsetParent();
area = jQuery("#imgmap area").offsetParent();
equal( area[0], document.documentElement, "The html element is the offsetParent of the body." );
div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body");
......@@ -525,8 +534,9 @@ test("fractions (see #7730 and #7885)", function() {
jQuery("body").append("<div id='fractions'/>");
var expected = { "top": 1000, "left": 1000 };
var div = jQuery("#fractions");
var result,
expected = { "top": 1000, "left": 1000 },
div = jQuery("#fractions");
div.css({
"position": "absolute",
......@@ -538,7 +548,7 @@ test("fractions (see #7730 and #7885)", function() {
div.offset(expected);
var result = div.offset();
result = div.offset();
equal( result.top, expected.top, "Check top" );
equal( result.left, expected.left, "Check left" );
......
module( "queue", { teardown: moduleTeardown });
test( "queue() with other types", 14, function() {
var counter = 0;
stop();
var $div = jQuery({}),
defer;
var defer,
$div = jQuery({}),
counter = 0;
$div.promise( "foo" ).done(function() {
equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
});
......@@ -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() {
expect(2);
var div = jQuery({});
var counter = 0;
var div = jQuery({}),
counter = 0;
div.queue("foo", function(next) {
equal(++counter, 1, "Dequeueing");
......@@ -76,12 +76,11 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
expect(3);
stop();
var div = jQuery({});
var counter = 0;
var div = jQuery({}),
counter = 0;
div.queue(function(next) {
div.queue(function( next ) {
equal(++counter, 1, "Dequeueing");
var self = this;
setTimeout(function() { next(); }, 500);
}).queue(function(next) {
equal(++counter, 2, "Next was called");
......@@ -143,14 +142,14 @@ test("clearQueue(name) clears the queue", function() {
stop();
var div = jQuery({});
var counter = 0;
var div = jQuery({}),
counter = 0;
div.queue("foo", function(next) {
div.queue("foo", function( next ) {
counter++;
jQuery(this).clearQueue("foo");
next();
}).queue("foo", function(next) {
}).queue("foo", function() {
counter++;
});
......@@ -167,14 +166,14 @@ test("clearQueue(name) clears the queue", function() {
test("clearQueue() clears the fx queue", function() {
expect(1);
var div = jQuery({});
var counter = 0;
var div = jQuery({}),
counter = 0;
div.queue(function(next) {
div.queue(function( next ) {
counter++;
var self = this;
setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
}).queue(function(next) {
}).queue(function() {
counter++;
});
......@@ -246,8 +245,8 @@ asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before res
test( ".promise(obj)", function() {
expect(2);
var obj = {};
var promise = jQuery( "#foo" ).promise( "promise", obj );
var obj = {},
promise = jQuery( "#foo" ).promise( "promise", obj );
ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
strictEqual( promise, obj, ".promise(type, obj) returns obj" );
......
......@@ -3,9 +3,11 @@ module("serialize", { teardown: moduleTeardown });
test("jQuery.param()", function() {
expect(22);
var params, settings;
equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" );
var params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"string":"foo","null":null,"undefined":undefined};
......@@ -37,7 +39,7 @@ test("jQuery.param()", function() {
// #7945
equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
var settings = { traditional: true };
settings = { traditional: true };
if ( jQuery.ajaxSettings ) {
jQuery.ajaxSetup( settings );
......
......@@ -143,12 +143,13 @@ test("is() with :has() selectors", function() {
test("is() with positional selectors", function() {
expect(24);
var html = jQuery(
"<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" ),
isit = function(sel, match, expect) {
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" );
};
jQuery(
"<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" );
var isit = function(sel, match, expect) {
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" );
};
isit( "#posp", "#posp:first", true );
isit( "#posp", "#posp:eq(2)", false );
......@@ -271,19 +272,20 @@ test("filter(jQuery)", function() {
test("filter() with positional selectors", function() {
expect(19);
var html = jQuery( "" +
"<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" ),
filterit = function(sel, filter, length) {
equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" );
};
jQuery( "" +
"<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" );
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:eq(2)", 0 );
......@@ -416,50 +418,55 @@ test("not(jQuery)", function() {
test("has(Element)", function() {
expect(3);
var obj, detached, multipleParent;
var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
var detached = jQuery("<a><b><i/></b></a>");
detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
});
test("has(Selector)", function() {
expect( 5 );
var obj = jQuery("#qunit-fixture").has("#sndp");
var obj, detached, multipleParent, multipleHas;
obj = jQuery("#qunit-fixture").has("#sndp");
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
var detached = jQuery("<a><b><i/></b></a>");
detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a");
deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" );
var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
});
test("has(Arrayish)", function() {
expect(4);
var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
var simple, detached, multipleParent, multipleHas;
simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
var detached = jQuery("<a><b><i/></b></a>");
detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
deepEqual( simple.get(), q("qunit-fixture"), "Only adds elements once" );
multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
});
test("addBack()", function() {
......@@ -476,6 +483,7 @@ test("siblings([String])", function() {
deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
deepEqual( jQuery("#nonnodes").contents().eq(1).siblings().get(), q("nonnodesElement"), "Check for text node siblings" );
deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
var set = q("sndp", "en", "sap");
deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
......@@ -624,9 +632,11 @@ test("prevUntil([String])", function() {
test("contents()", function() {
expect(12);
var ibody, c;
equal( jQuery("#ap").contents().length, 9, "Check element contents" );
ok( jQuery("#iframe").contents()[0], "Check existence of IFrame document" );
var ibody = jQuery("#loadediframe").contents()[0].body;
ibody = jQuery("#loadediframe").contents()[0].body;
ok( ibody, "Check existence of IFrame body" );
equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
......@@ -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" );
// using contents will get comments regular, text, and comment nodes
var c = jQuery("#nonnodes").contents().contents();
c = jQuery("#nonnodes").contents().contents();
equal( c.length, 1, "Check node,textnode,comment contents is just one" );
equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
});
test("add(String|Element|Array|undefined)", function() {
expect( 15 );
var divs, tmp, x, notDefined;
deepEqual( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
......@@ -669,15 +682,15 @@ test("add(String|Element|Array|undefined)", function() {
// use jQuery([]).add(form.elements) instead.
//equal( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
var divs = jQuery("<div/>").add("#sndp");
divs = jQuery("<div/>").add("#sndp");
ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
divs = jQuery("#sndp").add("<div/>");
ok( !divs[1].parentNode, "Sort with the disconnected node last." );
var tmp = jQuery("<div/>");
tmp = jQuery("<div/>");
var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
......@@ -693,7 +706,6 @@ test("add(String|Element|Array|undefined)", function() {
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
var notDefined;
equal( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
......@@ -723,12 +735,18 @@ test("eq('-1') #10616", 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 );
strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" );
$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() {
......
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