aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorOleg Gaidarenko <markelog@gmail.com>2015-08-16 09:59:58 +0300
committerOleg Gaidarenko <markelog@gmail.com>2015-09-07 20:03:50 +0300
commit10fdad742a2a6aa9f0e00b3e04fc5264797c53c7 (patch)
tree6b6d7b1375ff88f4bebbfa0703f7b595eb485df9 /test/unit
parent7aa46e0df8a673e6b00550bbbbed21eed50108b7 (diff)
downloadjquery-10fdad742a2a6aa9f0e00b3e04fc5264797c53c7.tar.gz
jquery-10fdad742a2a6aa9f0e00b3e04fc5264797c53c7.zip
Build: Update jscs and lint files
Fixes gh-2056
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/ajax.js938
-rw-r--r--test/unit/attributes.js1220
-rw-r--r--test/unit/callbacks.js130
-rw-r--r--test/unit/core.js1004
-rw-r--r--test/unit/css.js874
-rw-r--r--test/unit/data.js672
-rw-r--r--test/unit/deferred.js430
-rw-r--r--test/unit/deprecated.js2
-rw-r--r--test/unit/dimensions.js240
-rw-r--r--test/unit/effects.js1336
-rw-r--r--test/unit/event.js1866
-rw-r--r--test/unit/exports.js8
-rw-r--r--test/unit/manipulation.js1577
-rw-r--r--test/unit/offset.js416
-rw-r--r--test/unit/queue.js240
-rw-r--r--test/unit/ready.js10
-rw-r--r--test/unit/selector.js458
-rw-r--r--test/unit/serialize.js128
-rw-r--r--test/unit/support.js16
-rw-r--r--test/unit/traversing.js1046
-rw-r--r--test/unit/wrap.js551
21 files changed, 6693 insertions, 6469 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 2f8334147..0cc799800 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -3,15 +3,15 @@ QUnit.module( "ajax", {
jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
moduleTeardown.apply( this, arguments );
}
-});
+} );
-(function() {
- QUnit.test("Unit Testing Environment", function( assert ) {
+( function() {
+ QUnit.test( "Unit Testing Environment", function( assert ) {
assert.expect( 2 );
assert.ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" );
assert.ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" );
- });
+ } );
if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) {
return;
@@ -21,8 +21,8 @@ QUnit.module( "ajax", {
return function() {
expected = expected || "";
jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) {
- assert.ok( expected.indexOf(e.type) !== -1, e.type );
- });
+ assert.ok( expected.indexOf( e.type ) !== -1, e.type );
+ } );
};
}
@@ -40,7 +40,7 @@ QUnit.module( "ajax", {
ajaxTest( "jQuery.ajax() - success callbacks", 8, function( assert ) {
return {
setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
beforeSend: function() {
assert.ok( true, "beforeSend" );
},
@@ -48,16 +48,16 @@ QUnit.module( "ajax", {
assert.ok( true, "success" );
},
complete: function() {
- assert.ok( true, "complete");
+ assert.ok( true, "complete" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, function( assert ) {
return {
- setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
+ setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
create: function( options ) {
- return jQuery.ajax( url("data/name.html"), options );
+ return jQuery.ajax( url( "data/name.html" ), options );
},
beforeSend: function() {
assert.ok( true, "beforeSend" );
@@ -69,52 +69,52 @@ QUnit.module( "ajax", {
assert.ok( true, "complete" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert ) {
return {
- setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
- url: url("data/name.html"),
+ setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
+ url: url( "data/name.html" ),
beforeSend: function() {
assert.ok( true, "beforeSend" );
},
success: true,
afterSend: function( request ) {
- request.always(function() {
+ request.always( function() {
assert.ok( true, "complete" );
- }).done(function() {
+ } ).done( function() {
assert.ok( true, "success" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( false, "error" );
- });
+ } );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, function( assert ) {
return {
- setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
- url: url("data/name.html"),
+ setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
+ url: url( "data/name.html" ),
beforeSend: function() {
assert.ok( true, "beforeSend" );
},
success: true,
complete: function( xhr ) {
- xhr.always(function() {
+ xhr.always( function() {
assert.ok( true, "complete" );
- }).done(function() {
+ } ).done( function() {
assert.ok( true, "success" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( false, "error" );
- });
+ } );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - error callbacks", 8, function( assert ) {
return {
- setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert ),
- url: url("data/name.php?wait=5"),
+ setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert ),
+ url: url( "data/name.php?wait=5" ),
beforeSend: function() {
assert.ok( true, "beforeSend" );
},
@@ -128,11 +128,11 @@ QUnit.module( "ajax", {
assert.ok( true, "complete" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, function( assert ) {
- return [{
- url: url("data/name.php?wait=5"),
+ return [ {
+ url: url( "data/name.php?wait=5" ),
error: function( _, textStatus, errorThrown ) {
assert.strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
assert.strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" );
@@ -142,39 +142,39 @@ QUnit.module( "ajax", {
}
},
{
- url: url("data/name.php?wait=5"),
+ url: url( "data/name.php?wait=5" ),
error: function( _, textStatus, errorThrown ) {
assert.strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
assert.strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" );
},
afterSend: function( request ) {
- request.abort("mystatus");
+ request.abort( "mystatus" );
}
- }];
- });
+ } ];
+ } );
ajaxTest( "jQuery.ajax() - responseText on error", 1, function( assert ) {
return {
- url: url("data/errorWithText.php"),
+ url: url( "data/errorWithText.php" ),
error: function( xhr ) {
assert.strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" );
}
};
- });
+ } );
QUnit.asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function( assert ) {
var previousUrl,
firstTime = true;
- jQuery.ajax({
- url: url("data/errorWithText.php"),
+ jQuery.ajax( {
+ url: url( "data/errorWithText.php" ),
error: function() {
if ( firstTime ) {
firstTime = false;
jQuery.ajax( this );
} else {
ok ( true, "Test retrying with jQuery.ajax(this) works" );
- jQuery.ajax({
- url: url("data/errorWithText.php"),
+ jQuery.ajax( {
+ url: url( "data/errorWithText.php" ),
data: {
"x": 1
},
@@ -190,20 +190,20 @@ QUnit.module( "ajax", {
error: function() {
jQuery.ajax( this );
}
- });
+ } );
}
}
- });
- });
+ } );
+ } );
ajaxTest( "jQuery.ajax() - headers", 5, function( assert ) {
return {
setup: function() {
- jQuery( document ).ajaxSend(function( evt, xhr ) {
+ jQuery( document ).ajaxSend( function( evt, xhr ) {
xhr.setRequestHeader( "ajax-send", "test" );
- });
+ } );
},
- url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send"),
+ url: url( "data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send" ),
headers: {
"siMPle": "value",
"SometHing-elsE": "other value",
@@ -220,63 +220,64 @@ QUnit.module( "ajax", {
var i, emptyHeader,
requestHeaders = jQuery.extend( this.headers, {
"ajax-send": "test"
- }),
+ } ),
tmp = [];
for ( i in requestHeaders ) {
tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" );
}
- tmp = tmp.join("");
+ tmp = tmp.join( "" );
assert.strictEqual( data, tmp, "Headers were sent" );
- assert.strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" );
- assert.ok( data.indexOf( "undefined" ) < 0 , "Undefined header value was not sent" );
+ assert.strictEqual( xhr.getResponseHeader( "Sample-Header" ), "Hello World", "Sample header received" );
+ assert.ok( data.indexOf( "undefined" ) < 0, "Undefined header value was not sent" );
- emptyHeader = xhr.getResponseHeader("Empty-Header");
+ emptyHeader = xhr.getResponseHeader( "Empty-Header" );
if ( emptyHeader === null ) {
assert.ok( true, "Firefox doesn't support empty headers" );
} else {
assert.strictEqual( emptyHeader, "", "Empty header received" );
}
- assert.strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" );
+ assert.strictEqual( xhr.getResponseHeader( "Sample-Header2" ), "Hello World 2", "Second sample header received" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - Accept header", 1, function( assert ) {
return {
- url: url("data/headers.php?keys=accept"),
+ url: url( "data/headers.php?keys=accept" ),
headers: {
Accept: "very wrong accept value"
},
beforeSend: function( xhr ) {
- xhr.setRequestHeader("Accept", "*/*");
+ xhr.setRequestHeader( "Accept", "*/*" );
},
success: function( data ) {
assert.strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - contentType", 2, function( assert ) {
return [
{
- url: url("data/headers.php?keys=content-type"),
+ url: url( "data/headers.php?keys=content-type" ),
contentType: "test",
success: function( data ) {
assert.strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" );
}
},
{
- url: url("data/headers.php?keys=content-type"),
+ url: url( "data/headers.php?keys=content-type" ),
contentType: false,
success: function( data ) {
+
// Some server/interpreter combinations always supply a Content-Type to scripts
data = data || "content-type: \n";
assert.strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" );
}
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - protocol-less urls", 1, function( assert ) {
return {
@@ -287,7 +288,7 @@ QUnit.module( "ajax", {
},
error: true
};
- });
+ } );
ajaxTest( "jQuery.ajax() - hash", 3, function( assert ) {
return [
@@ -319,7 +320,7 @@ QUnit.module( "ajax", {
error: true
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - cross-domain detection", 8, function( assert ) {
function request( url, title, crossDomainOrOptions ) {
@@ -377,12 +378,12 @@ QUnit.module( "ajax", {
"Cross-domain url with leading space is detected as cross-domain"
)
];
- });
+ } );
ajaxTest( "jQuery.ajax() - abort", 9, function( assert ) {
return {
- setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete", assert ),
- url: url("data/name.php?wait=5"),
+ setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete", assert ),
+ url: url( "data/name.php?wait=5" ),
beforeSend: function() {
assert.ok( true, "beforeSend" );
},
@@ -396,10 +397,10 @@ QUnit.module( "ajax", {
assert.ok( true, "complete" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) {
- var context = document.createElement("div");
+ var context = document.createElement( "div" );
function event( e ) {
assert.equal( this, context, e.type );
@@ -413,27 +414,27 @@ QUnit.module( "ajax", {
return {
setup: function() {
- jQuery( context ).appendTo("#foo")
+ jQuery( context ).appendTo( "#foo" )
.ajaxSend( event )
.ajaxComplete( event )
.ajaxError( event )
.ajaxSuccess( event );
},
- requests: [{
- url: url("data/name.html"),
+ requests: [ {
+ url: url( "data/name.html" ),
context: context,
- beforeSend: callback("beforeSend"),
- success: callback("success"),
- complete: callback("complete")
+ beforeSend: callback( "beforeSend" ),
+ success: callback( "success" ),
+ complete: callback( "complete" )
}, {
- url: url("data/404.html"),
+ url: url( "data/404.html" ),
context: context,
- beforeSend: callback("beforeSend"),
- error: callback("error"),
- complete: callback("complete")
- }]
+ beforeSend: callback( "beforeSend" ),
+ error: callback( "error" ),
+ complete: callback( "complete" )
+ } ]
};
- });
+ } );
ajaxTest( "jQuery.ajax() - events without context", 3, function( assert ) {
function nocallback( msg ) {
@@ -442,12 +443,12 @@ QUnit.module( "ajax", {
};
}
return {
- url: url("data/404.html"),
- beforeSend: nocallback("beforeSend"),
- error: nocallback("error"),
- complete: nocallback("complete")
+ url: url( "data/404.html" ),
+ beforeSend: nocallback( "beforeSend" ),
+ error: nocallback( "error" ),
+ complete: nocallback( "complete" )
};
- });
+ } );
ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function( assert ) {
var holder;
@@ -463,30 +464,30 @@ QUnit.module( "ajax", {
},
success: true
};
- });
+ } );
ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, function( assert ) {
return {
setup: function() {
jQuery( document ).on( "ajaxSend", function( e, jqXHR ) {
jqXHR.abort();
- });
+ } );
jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) {
assert.equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" );
- });
+ } );
},
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
error: true,
complete: function() {
assert.ok( true, "complete" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - context modification", 1, function( assert ) {
return {
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
context: {},
beforeSend: function() {
this.test = "foo";
@@ -496,37 +497,37 @@ QUnit.module( "ajax", {
},
success: true
};
- });
+ } );
ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function( assert ) {
var obj = {};
return {
setup: function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
context: obj
- });
+ } );
assert.strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
},
- requests: [{
- url: url("data/name.html"),
+ requests: [ {
+ url: url( "data/name.html" ),
success: function() {
assert.strictEqual( this, obj, "Make sure the original object is maintained." );
}
}, {
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
context: {},
success: function() {
assert.ok( this !== obj, "Make sure overriding context is possible." );
}
- }]
+ } ]
};
- });
+ } );
ajaxTest( "jQuery.ajax() - disabled globals", 3, function( assert ) {
return {
setup: addGlobalEvents( "", assert ),
global: false,
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
beforeSend: function() {
assert.ok( true, "beforeSend" );
},
@@ -537,11 +538,11 @@ QUnit.module( "ajax", {
assert.ok( true, "complete" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, function( assert ) {
return {
- url: url("data/with_fries.xml"),
+ url: url( "data/with_fries.xml" ),
dataType: "xml",
success: function( resp ) {
assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
@@ -549,11 +550,11 @@ QUnit.module( "ajax", {
assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, function( assert ) {
return {
- url: url("data/with_fries_over_jsonp.php"),
+ url: url( "data/with_fries_over_jsonp.php" ),
dataType: "jsonp xml",
success: function( resp ) {
assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
@@ -561,19 +562,19 @@ QUnit.module( "ajax", {
assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - HEAD requests", 2, function( assert ) {
return [
{
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
type: "HEAD",
success: function( data, status, xhr ) {
assert.ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" );
}
},
{
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
data: {
"whip_it": "good"
},
@@ -583,11 +584,11 @@ QUnit.module( "ajax", {
}
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - beforeSend", 1, function( assert ) {
return {
- url: url("data/name.html"),
+ url: url( "data/name.html" ),
beforeSend: function() {
this.check = true;
},
@@ -595,13 +596,13 @@ QUnit.module( "ajax", {
assert.ok( this.check, "check beforeSend was executed" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, function( assert ) {
return {
create: function() {
- return jQuery.ajax({
- url: url("data/name.html"),
+ return jQuery.ajax( {
+ url: url( "data/name.html" ),
beforeSend: function( xhr ) {
assert.ok( true, "beforeSend got called, canceling" );
xhr.abort();
@@ -615,34 +616,34 @@ QUnit.module( "ajax", {
error: function() {
assert.ok( false, "request didn't get canceled" );
}
- });
+ } );
},
fail: function( _, reason ) {
assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - dataType html", 5, function( assert ) {
return {
setup: function() {
- Globals.register("testFoo");
- Globals.register("testBar");
+ Globals.register( "testFoo" );
+ Globals.register( "testBar" );
},
dataType: "html",
- url: url("data/test.html"),
+ url: url( "data/test.html" ),
success: function( data ) {
assert.ok( data.match( /^html text/ ), "Check content for datatype html" );
- jQuery("#ap").html( data );
- assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" );
- assert.strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" );
+ jQuery( "#ap" ).html( data );
+ assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated for datatype html" );
+ assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated for datatype html" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - synchronous request", 1, function( assert ) {
return {
- url: url("data/json_obj.js"),
+ url: url( "data/json_obj.js" ),
dataType: "text",
async: false,
success: true,
@@ -650,24 +651,24 @@ QUnit.module( "ajax", {
assert.ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, function( assert ) {
return {
- url: url("data/json_obj.js"),
+ url: url( "data/json_obj.js" ),
async: false,
dataType: "text",
success: true,
afterSend: function( xhr ) {
var result;
- xhr.done(function( data ) {
+ xhr.done( function( data ) {
assert.ok( true, "success callback executed" );
result = data;
- });
+ } );
assert.ok( /^\{ "data"/.test( result ), "check returned text" );
}
};
- });
+ } );
QUnit.asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function( assert ) {
var target = "data/name.html",
@@ -680,24 +681,24 @@ QUnit.module( "ajax", {
jQuery( document ).on( "ajaxError.passthru", function( e, xml ) {
errorCount++;
errorEx += ": " + xml.status;
- });
+ } );
jQuery( document ).one( "ajaxStop", function() {
assert.equal( successCount, 5, "Check all ajax calls successful" );
assert.equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
- jQuery( document ).off("ajaxError.passthru");
+ jQuery( document ).off( "ajaxError.passthru" );
QUnit.start();
- });
- Globals.register("testBar");
-
- assert.ok( jQuery.get( url(target), success ), "get" );
- assert.ok( jQuery.post( url(target), success ), "post" );
- assert.ok( jQuery.getScript( url("data/testbar.php"), success ), "script" );
- assert.ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" );
- assert.ok( jQuery.ajax({
+ } );
+ Globals.register( "testBar" );
+
+ assert.ok( jQuery.get( url( target ), success ), "get" );
+ assert.ok( jQuery.post( url( target ), success ), "post" );
+ assert.ok( jQuery.getScript( url( "data/testbar.php" ), success ), "script" );
+ assert.ok( jQuery.getJSON( url( "data/json_obj.js" ), success ), "json" );
+ assert.ok( jQuery.ajax( {
url: url( target ),
success: success
- }), "generic" );
- });
+ } ), "generic" );
+ } );
ajaxTest( "jQuery.ajax() - cache", 12, function( assert ) {
var re = /_=(.*?)(&|$)/g;
@@ -708,7 +709,7 @@ QUnit.module( "ajax", {
cache: false,
beforeSend: function() {
var parameter, tmp;
- while(( tmp = re.exec( this.url ) )) {
+ while ( ( tmp = re.exec( this.url ) ) ) {
assert.strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
parameter = tmp[ 1 ];
assert.notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" );
@@ -745,7 +746,7 @@ QUnit.module( "ajax", {
"2 parameters surrounding _="
)
];
- });
+ } );
jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
@@ -784,25 +785,25 @@ QUnit.module( "ajax", {
}
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 10, function( assert ) {
return {
setup: function() {
- Globals.register("functionToCleanUp");
- Globals.register("XXX");
- Globals.register("jsonpResults");
- window["jsonpResults"] = function( data ) {
- assert.ok( data["data"], "JSON results returned (GET, custom callback function)" );
+ Globals.register( "functionToCleanUp" );
+ Globals.register( "XXX" );
+ Globals.register( "jsonpResults" );
+ window[ "jsonpResults" ] = function( data ) {
+ assert.ok( data[ "data" ], "JSON results returned (GET, custom callback function)" );
};
},
- requests: [{
+ requests: [ {
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
jsonp: "callback",
success: function( data ) {
- assert.ok( data["data"], "JSON results returned (GET, data obj callback)" );
+ assert.ok( data[ "data" ], "JSON results returned (GET, data obj callback)" );
}
}, {
url: "data/jsonp.php",
@@ -823,10 +824,10 @@ QUnit.module( "ajax", {
crossDomain: crossDomain,
jsonpCallback: "functionToCleanUp",
success: function( data ) {
- assert.ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" );
- assert.strictEqual( window["functionToCleanUp"], true, "Callback was removed (GET, custom callback name to be cleaned up)" );
+ assert.ok( data[ "data" ], "JSON results returned (GET, custom callback name to be cleaned up)" );
+ assert.strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed (GET, custom callback name to be cleaned up)" );
var xhr;
- jQuery.ajax({
+ jQuery.ajax( {
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
@@ -835,11 +836,11 @@ QUnit.module( "ajax", {
xhr = jqXHR;
return false;
}
- });
- xhr.fail(function() {
+ } );
+ xhr.fail( function() {
assert.ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
- assert.strictEqual( window["functionToCleanUp"], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
- });
+ assert.strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
+ } );
}
}, {
url: "data/jsonp.php?callback=XXX",
@@ -851,11 +852,11 @@ QUnit.module( "ajax", {
assert.ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
},
success: function( data ) {
- assert.ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
+ assert.ok( data[ "data" ], "JSON results returned (GET, custom callback name with no url manipulation)" );
}
- }]
+ } ]
};
- });
+ } );
ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, function( assert ) {
return [
@@ -878,8 +879,7 @@ QUnit.module( "ajax", {
}
}
];
- });
-
+ } );
ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, function( assert ) {
return [
@@ -889,7 +889,7 @@ QUnit.module( "ajax", {
dataType: "jsonp",
crossDomain: crossDomain,
success: function( data ) {
- assert.ok( data["data"], "JSON results returned (POST, no callback)" );
+ assert.ok( data[ "data" ], "JSON results returned (POST, no callback)" );
}
},
{
@@ -899,7 +899,7 @@ QUnit.module( "ajax", {
dataType: "jsonp",
crossDomain: crossDomain,
success: function( data ) {
- assert.ok( data["data"], "JSON results returned (POST, data callback)" );
+ assert.ok( data[ "data" ], "JSON results returned (POST, data callback)" );
}
},
{
@@ -909,11 +909,11 @@ QUnit.module( "ajax", {
dataType: "jsonp",
crossDomain: crossDomain,
success: function( data ) {
- assert.ok( data["data"], "JSON results returned (POST, data obj callback)" );
+ assert.ok( data[ "data" ], "JSON results returned (POST, data obj callback)" );
}
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - JSONP" + label, 3, function( assert ) {
return [
@@ -928,14 +928,14 @@ QUnit.module( "ajax", {
{
create: function( options ) {
var request = jQuery.ajax( options ),
- promise = request.then(function( data ) {
+ promise = request.then( function( data ) {
assert.ok( data.data, "first request: JSON results returned (GET, no callback)" );
- request = jQuery.ajax( this ).done(function( data ) {
+ request = jQuery.ajax( this ).done( function( data ) {
assert.ok( data.data, "this re-used: JSON results returned (GET, no callback)" );
- });
+ } );
promise.abort = request.abort;
return request;
- });
+ } );
promise.abort = request.abort;
return promise;
},
@@ -945,50 +945,50 @@ QUnit.module( "ajax", {
success: true
}
];
- });
+ } );
- });
+ } );
ajaxTest( "jQuery.ajax() - script, Remote", 2, function( assert ) {
return {
setup: function() {
- Globals.register("testBar");
+ Globals.register( "testBar" );
},
url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php",
dataType: "script",
success: function() {
- assert.strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
+ assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, function( assert ) {
return {
setup: function() {
- Globals.register("testBar");
+ Globals.register( "testBar" );
},
url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php",
type: "POST",
dataType: "script",
success: function( data, status ) {
- assert.strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" );
+ assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (POST, no callback)" );
assert.strictEqual( status, "success", "Script results returned (POST, no callback)" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, function( assert ) {
return {
setup: function() {
- Globals.register("testBar");
+ Globals.register( "testBar" );
},
url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/testbar.php",
dataType: "script",
success: function() {
- assert.strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" );
+ assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - malformed JSON", 2, function( assert ) {
return {
@@ -999,7 +999,7 @@ QUnit.module( "ajax", {
assert.ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - script by content-type", 2, function() {
return [
@@ -1018,7 +1018,7 @@ QUnit.module( "ajax", {
success: true
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - JSON by content-type", 5, function( assert ) {
return {
@@ -1029,17 +1029,17 @@ QUnit.module( "ajax", {
},
success: function( json ) {
assert.ok( json.length >= 2, "Check length" );
- assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
- assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
- assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
- assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
+ assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" );
+ assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
+ assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
+ assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, function( assert ) {
return {
- url: url("data/json.php"),
+ url: url( "data/json.php" ),
data: {
"header": "json",
"json": "array"
@@ -1050,35 +1050,35 @@ QUnit.module( "ajax", {
success: function( text ) {
assert.strictEqual( typeof text, "string", "json wasn't auto-determined" );
var json = jQuery.parseJSON( text );
- assert.ok( json.length >= 2, "Check length");
- assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
- assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
- assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
- assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
+ assert.ok( json.length >= 2, "Check length" );
+ assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" );
+ assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
+ assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
+ assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - simple get", 1, function( assert ) {
return {
type: "GET",
- url: url("data/name.php?name=foo"),
+ url: url( "data/name.php?name=foo" ),
success: function( msg ) {
assert.strictEqual( msg, "bar", "Check for GET" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - simple post", 1, function( assert ) {
return {
type: "POST",
- url: url("data/name.php"),
+ url: url( "data/name.php" ),
data: "name=peter",
success: function( msg ) {
assert.strictEqual( msg, "pan", "Check for POST" );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, function( assert ) {
return {
@@ -1089,7 +1089,7 @@ QUnit.module( "ajax", {
assert.strictEqual( result, "" );
}
};
- });
+ } );
var ifModifiedNow = new Date();
@@ -1108,13 +1108,13 @@ QUnit.module( "ajax", {
function( type, url ) {
url = "data/" + url + "?ts=" + ifModifiedNow++;
QUnit.asyncTest( "jQuery.ajax() - " + type + " support" + label, 4, function( assert ) {
- jQuery.ajax({
+ jQuery.ajax( {
url: url,
ifModified: true,
cache: cache,
success: function( _, status ) {
assert.strictEqual( status, "success", "Initial status is 'success'" );
- jQuery.ajax({
+ jQuery.ajax( {
url: url,
ifModified: true,
cache: cache,
@@ -1126,10 +1126,10 @@ QUnit.module( "ajax", {
complete: function() {
QUnit.start();
}
- });
+ } );
}
- });
- });
+ } );
+ } );
}
);
}
@@ -1138,13 +1138,14 @@ QUnit.module( "ajax", {
ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, function( assert ) {
return {
+
// see RFC 2606
url: "http://example.invalid",
error: function( xhr, _, e ) {
assert.ok( true, "file not found: " + xhr.status + " => " + e );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - failing cross-domain", 1, function( assert ) {
return {
@@ -1153,34 +1154,34 @@ QUnit.module( "ajax", {
assert.ok( true, "access denied: " + xhr.status + " => " + e );
}
};
- });
+ } );
ajaxTest( "jQuery.ajax() - atom+xml", 1, function( assert ) {
return {
- url: url("data/atom+xml.php"),
+ url: url( "data/atom+xml.php" ),
success: function() {
assert.ok( true, "success" );
}
};
- });
+ } );
QUnit.asyncTest( "jQuery.ajax() - statusText", 3, function( assert ) {
- jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) {
+ jQuery.ajax( url( "data/statusText.php?status=200&text=Hello" ) ).done( function( _, statusText, jqXHR ) {
assert.strictEqual( statusText, "success", "callback status text ok for success" );
assert.ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" );
- jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) {
+ jQuery.ajax( url( "data/statusText.php?status=404&text=World" ) ).fail( function( jqXHR, statusText ) {
assert.strictEqual( statusText, "error", "callback status text ok for error" );
QUnit.start();
- });
- });
- });
+ } );
+ } );
+ } );
QUnit.asyncTest( "jQuery.ajax() - statusCode", 20, function( assert ) {
var count = 12;
function countComplete() {
- if ( ! --count ) {
+ if ( !--count ) {
QUnit.start();
}
}
@@ -1205,45 +1206,45 @@ QUnit.module( "ajax", {
},
function( uri, isSuccess ) {
- jQuery.ajax( url(uri), {
+ jQuery.ajax( url( uri ), {
statusCode: createStatusCodes( "in options", isSuccess ),
complete: countComplete
- });
+ } );
- jQuery.ajax( url(uri), {
+ jQuery.ajax( url( uri ), {
complete: countComplete
- }).statusCode( createStatusCodes("immediately with method", isSuccess) );
+ } ).statusCode( createStatusCodes( "immediately with method", isSuccess ) );
- jQuery.ajax( url(uri), {
+ jQuery.ajax( url( uri ), {
complete: function( jqXHR ) {
- jqXHR.statusCode( createStatusCodes("on complete", isSuccess) );
+ jqXHR.statusCode( createStatusCodes( "on complete", isSuccess ) );
countComplete();
}
- });
+ } );
- jQuery.ajax( url(uri), {
+ jQuery.ajax( url( uri ), {
complete: function( jqXHR ) {
- setTimeout(function() {
- jqXHR.statusCode( createStatusCodes("very late binding", isSuccess) );
+ setTimeout( function() {
+ jqXHR.statusCode( createStatusCodes( "very late binding", isSuccess ) );
countComplete();
}, 100 );
}
- });
+ } );
- jQuery.ajax( url(uri), {
+ jQuery.ajax( url( uri ), {
statusCode: createStatusCodes( "all (options)", isSuccess ),
complete: function( jqXHR ) {
- jqXHR.statusCode( createStatusCodes("all (on complete)", isSuccess) );
- setTimeout(function() {
- jqXHR.statusCode( createStatusCodes("all (very late binding)", isSuccess) );
+ jqXHR.statusCode( createStatusCodes( "all (on complete)", isSuccess ) );
+ setTimeout( function() {
+ jqXHR.statusCode( createStatusCodes( "all (very late binding)", isSuccess ) );
countComplete();
}, 100 );
}
- }).statusCode( createStatusCodes("all (immediately with method)", isSuccess) );
+ } ).statusCode( createStatusCodes( "all (immediately with method)", isSuccess ) );
var testString = "";
- jQuery.ajax( url(uri), {
+ jQuery.ajax( url( uri ), {
success: function( a, b, jqXHR ) {
assert.ok( isSuccess, "success" );
var statusCode = {};
@@ -1270,17 +1271,17 @@ QUnit.module( "ajax", {
);
countComplete();
}
- });
+ } );
}
/* jQuery.each arguments end*/
);
- });
+ } );
ajaxTest( "jQuery.ajax() - transitive conversions", 8, function( assert ) {
return [
{
- url: url("data/json.php"),
+ url: url( "data/json.php" ),
converters: {
"json myJson": function( data ) {
assert.ok( true, "converter called" );
@@ -1295,7 +1296,7 @@ QUnit.module( "ajax", {
}
},
{
- url: url("data/json.php"),
+ url: url( "data/json.php" ),
converters: {
"json myJson": function( data ) {
assert.ok( true, "converter called (*)" );
@@ -1311,12 +1312,12 @@ QUnit.module( "ajax", {
}
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - overrideMimeType", 2, function( assert ) {
return [
{
- url: url("data/json.php"),
+ url: url( "data/json.php" ),
beforeSend: function( xhr ) {
xhr.overrideMimeType( "application/json" );
},
@@ -1325,30 +1326,30 @@ QUnit.module( "ajax", {
}
},
{
- url: url("data/json.php"),
+ url: url( "data/json.php" ),
mimeType: "application/json",
success: function( json ) {
assert.ok( json.data, "Mimetype overridden using mimeType option" );
}
}
];
- });
+ } );
ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, function( assert ) {
return {
- url: url("data/echoData.php"),
+ url: url( "data/echoData.php" ),
error: function( _, __, error ) {
assert.equal( typeof error === "object", true, "Didn't get back error object for empty json response" );
},
dataType: "json"
};
- });
+ } );
ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, function( assert ) {
return {
create: function() {
- return jQuery.ajax({
- url: url("data/name.html"),
+ return jQuery.ajax( {
+ url: url( "data/name.html" ),
beforeSend: function() {
assert.ok( true, "beforeSend got called, canceling" );
return false;
@@ -1362,13 +1363,13 @@ QUnit.module( "ajax", {
error: function() {
assert.ok( false, "request didn't get canceled" );
}
- });
+ } );
},
fail: function( _, reason ) {
assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
}
};
- });
+ } );
ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, function( assert ) {
return {
@@ -1382,7 +1383,7 @@ QUnit.module( "ajax", {
assert.strictEqual( result, "key=value" );
}
};
- });
+ } );
QUnit.test( "#7531 - jQuery.ajax() - Location object as url", function( assert ) {
assert.expect( 1 );
@@ -1390,16 +1391,16 @@ QUnit.module( "ajax", {
var xhr,
success = false;
try {
- xhr = jQuery.ajax({
+ xhr = jQuery.ajax( {
url: window.location
- });
+ } );
success = true;
xhr.abort();
- } catch (e) {
+ } catch ( e ) {
}
assert.ok( success, "document.location did not generate exception" );
- });
+ } );
jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, function( assert ) {
@@ -1413,8 +1414,8 @@ QUnit.module( "ajax", {
},
error: true
};
- });
- });
+ } );
+ } );
ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, function( assert ) {
return [
@@ -1428,7 +1429,7 @@ QUnit.module( "ajax", {
},
{
create: function() {
- return jQuery.ajax("data/name.html");
+ return jQuery.ajax( "data/name.html" );
},
done: function() {
assert.ok( true, "With only string URL argument" );
@@ -1436,7 +1437,7 @@ QUnit.module( "ajax", {
},
{
create: function() {
- return jQuery.ajax( "data/name.html", {});
+ return jQuery.ajax( "data/name.html", {} );
},
done: function() {
assert.ok( true, "With string URL param and map" );
@@ -1452,7 +1453,7 @@ QUnit.module( "ajax", {
}
}
];
- });
+ } );
jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 4, function( assert ) {
@@ -1479,7 +1480,7 @@ QUnit.module( "ajax", {
"JSONP callback name was removed from the window"
);
- jQuery.ajax({
+ jQuery.ajax( {
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
@@ -1487,11 +1488,11 @@ QUnit.module( "ajax", {
assert.strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" );
return false;
}
- });
+ } );
}
};
- });
- });
+ } );
+ } );
QUnit.test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function( assert ) {
assert.expect( 2 );
@@ -1506,13 +1507,13 @@ QUnit.module( "ajax", {
assert.ok( this === context, "context was not deep extended" );
return false;
}
- });
+ } );
success = true;
} catch ( e ) {
console.log( e );
}
assert.ok( success, "context with circular reference did not generate an exception" );
- });
+ } );
jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) {
@@ -1534,12 +1535,12 @@ QUnit.module( "ajax", {
request( assert, null ),
request( assert, undefined )
];
- });
- });
+ } );
+ } );
ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, function( assert ) {
return {
- url: url("data/errorWithJSON.php"),
+ url: url( "data/errorWithJSON.php" ),
dataFilter: function( string ) {
assert.ok( false, "dataFilter called" );
return string;
@@ -1549,18 +1550,19 @@ QUnit.module( "ajax", {
assert.deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" );
}
};
- });
+ } );
ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, function( assert ) {
return {
- url: url("data/1x1.jpg"),
+ url: url( "data/1x1.jpg" ),
success: function( data ) {
assert.ok( data === undefined || /JFIF/.test( data ), "success callback reached" );
}
};
- });
+ } );
QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) {
+
// Support: Android 2.3 only
// Android 2.3 doesn't fire the window.onerror handler, just accept the reality there.
if ( /android 2\.3/i.test( navigator.userAgent ) ) {
@@ -1576,17 +1578,17 @@ QUnit.module( "ajax", {
window.onerror = onerror;
QUnit.start();
};
- jQuery.ajax({
+ jQuery.ajax( {
url: "data/badjson.js",
dataType: "script",
throws: true
- });
- });
+ } );
+ } );
jQuery.each( [ "method", "type" ], function( _, globalOption ) {
function request( assert, option ) {
var options = {
- url: url("data/echoData.php"),
+ url: url( "data/echoData.php" ),
data: "hello",
success: function( msg ) {
assert.strictEqual( msg, "hello", "Check for POST (no override)" );
@@ -1612,38 +1614,39 @@ QUnit.module( "ajax", {
jQuery.ajaxSetup( options );
},
requests: [
- request(assert, "type"),
- request(assert, "method"),
- request(assert )
+ request( assert, "type" ),
+ request( assert, "method" ),
+ request( assert )
]
};
}
);
- });
+ } );
ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, function( assert ) {
return {
url: "data/dashboard.xml",
dataType: "xml",
success: function( ajaxXML ) {
- var parsedXML = jQuery( jQuery.parseXML("<tab title=\"Added\">blibli</tab>") ).find("tab");
+ var parsedXML = jQuery( jQuery.parseXML( "<tab title=\"Added\">blibli</tab>" ) ).find( "tab" );
ajaxXML = jQuery( ajaxXML );
try {
+
// Android 2.3 doesn't automatically adopt nodes from foreign documents.
// (see the comment in test/manipulation.js)
// Support: Android 2.3
if ( /android 2\.3/i.test( navigator.userAgent ) ) {
parsedXML = jQuery( ajaxXML[ 0 ].adoptNode( parsedXML[ 0 ] ) );
}
- ajaxXML.find("infowindowtab").append( parsedXML );
- } catch( e ) {
+ ajaxXML.find( "infowindowtab" ).append( parsedXML );
+ } catch ( e ) {
assert.strictEqual( e, undefined, "error" );
return;
}
- assert.strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" );
+ assert.strictEqual( ajaxXML.find( "tab" ).length, 3, "Parsed node was added properly" );
}
};
- });
+ } );
ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, function( assert ) {
return {
@@ -1665,11 +1668,11 @@ QUnit.module( "ajax", {
assert.strictEqual( error, "converter was called", "Converter was called" );
}
};
- });
+ } );
ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, function( assert ) {
return {
- url: url("data/with_fries.xml"),
+ url: url( "data/with_fries.xml" ),
dataType: "xml",
success: function( resp, _, jqXHR ) {
assert.notStrictEqual( resp, undefined, "XML document exists" );
@@ -1677,7 +1680,7 @@ QUnit.module( "ajax", {
assert.strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" );
}
};
- });
+ } );
ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, function( assert ) {
return {
@@ -1702,7 +1705,7 @@ QUnit.module( "ajax", {
assert.strictEqual( error, "converter was called", "Converter was called" );
}
};
- });
+ } );
testIframeWithCallback(
"#14379 - jQuery.ajax() on unload",
@@ -1714,7 +1717,7 @@ QUnit.module( "ajax", {
);
ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, function( assert ) {
- return [{
+ return [ {
url: "data/params_html.php",
method: "POST",
data: {
@@ -1739,7 +1742,7 @@ QUnit.module( "ajax", {
fail: function( _, status, error ) {
assert.ok( true, "fail: " + status + " - " + error );
}
- }];
+ } ];
}
);
@@ -1749,12 +1752,13 @@ QUnit.module( "ajax", {
return {
dataType: "prefix",
setup: function() {
+
// Ensure prefix does not throw an error
- jQuery.ajaxPrefilter("+prefix", function( options, _, jqXHR ) {
+ jQuery.ajaxPrefilter( "+prefix", function( options, _, jqXHR ) {
if ( options.abortInPrefilter ) {
jqXHR.abort();
}
- });
+ } );
},
abortInPrefilter: true,
error: function() {
@@ -1764,27 +1768,27 @@ QUnit.module( "ajax", {
assert.strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" );
}
};
- });
+ } );
//----------- jQuery.ajaxSetup()
QUnit.asyncTest( "jQuery.ajaxSetup()", 1, function( assert ) {
- jQuery.ajaxSetup({
- url: url("data/name.php?name=foo"),
+ jQuery.ajaxSetup( {
+ url: url( "data/name.php?name=foo" ),
success: function( msg ) {
assert.strictEqual( msg, "bar", "Check for GET" );
QUnit.start();
}
- });
+ } );
jQuery.ajax();
- });
+ } );
QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function( assert ) {
var passed = 0,
pass = function() {
assert.ok( passed++ < 2, "Error callback executed" );
if ( passed === 2 ) {
- jQuery( document ).off("ajaxError.setupTest");
+ jQuery( document ).off( "ajaxError.setupTest" );
QUnit.start();
}
},
@@ -1795,26 +1799,26 @@ QUnit.module( "ajax", {
jQuery( document ).on( "ajaxError.setupTest", pass );
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
timeout: 1000
- });
+ } );
- jQuery.ajax({
+ jQuery.ajax( {
type: "GET",
- url: url("data/name.php?wait=5"),
+ url: url( "data/name.php?wait=5" ),
error: pass,
success: fail
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function( assert ) {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
timeout: 50
- });
- jQuery.ajax({
+ } );
+ jQuery.ajax( {
type: "GET",
timeout: 15000,
- url: url("data/name.php?wait=1"),
+ url: url( "data/name.php?wait=1" ),
error: function() {
assert.ok( false, "Check for local timeout failed" );
QUnit.start();
@@ -1823,137 +1827,137 @@ QUnit.module( "ajax", {
assert.ok( true, "Check for local timeout" );
QUnit.start();
}
- });
- });
+ } );
+ } );
//----------- jQuery.domManip()
QUnit.test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", function( assert ) {
assert.expect( 1 );
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
type: "POST"
- });
+ } );
jQuery( document ).on( "ajaxStart ajaxStop", function() {
assert.ok( false, "Global event triggered" );
- });
+ } );
- jQuery("#qunit-fixture").append("<script src='data/ajax/evalScript.php'></script>");
+ jQuery( "#qunit-fixture" ).append( "<script src='data/ajax/evalScript.php'></script>" );
- jQuery( document ).off("ajaxStart ajaxStop");
- });
+ jQuery( document ).off( "ajaxStart ajaxStop" );
+ } );
QUnit.asyncTest( "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1, function( assert ) {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
type: "POST"
- });
+ } );
jQuery( "#qunit-fixture" ).load( "data/ajax/method.php", function( method ) {
assert.equal( method, "GET" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() {
- jQuery("#qunit-fixture").load( "data/cleanScript.html", start );
- });
+ jQuery( "#qunit-fixture" ).load( "data/cleanScript.html", start );
+ } );
//----------- jQuery.get()
QUnit.asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function( assert ) {
- jQuery.get( url("data/dashboard.xml"), function( xml ) {
+ jQuery.get( url( "data/dashboard.xml" ), function( xml ) {
var content = [];
- jQuery( "tab", xml ).each(function() {
+ jQuery( "tab", xml ).each( function() {
content.push( jQuery( this ).text() );
- });
+ } );
assert.strictEqual( content[ 0 ], "blabla", "Check first tab" );
assert.strictEqual( content[ 1 ], "blublu", "Check second tab" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function( assert ) {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
data: "helloworld"
- });
- jQuery.get( url("data/echoQuery.php"), function( data ) {
+ } );
+ jQuery.get( url( "data/echoQuery.php" ), function( data ) {
assert.ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
QUnit.start();
- });
- });
+ } );
+ } );
//----------- jQuery.getJSON()
QUnit.asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function( assert ) {
jQuery.getJSON(
- url("data/json.php"),
+ url( "data/json.php" ),
{
"json": "array"
},
function( json ) {
assert.ok( json.length >= 2, "Check length" );
- assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
- assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
- assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
- assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
+ assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" );
+ assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
+ assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
+ assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
QUnit.start();
}
);
- });
+ } );
QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function( assert ) {
- jQuery.getJSON( url("data/json.php"), function( json ) {
- if ( json && json["data"] ) {
- assert.strictEqual( json["data"]["lang"], "en", "Check JSON: lang" );
- assert.strictEqual( json["data"].length, 25, "Check JSON: length" );
+ jQuery.getJSON( url( "data/json.php" ), function( json ) {
+ if ( json && json[ "data" ] ) {
+ assert.strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" );
+ assert.strictEqual( json[ "data" ].length, 25, "Check JSON: length" );
QUnit.start();
}
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function( assert ) {
jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) {
assert.strictEqual( json.data.lang, "en", "Check JSON: lang" );
assert.strictEqual( json.data.length, 25, "Check JSON: length" );
QUnit.start();
- });
- });
+ } );
+ } );
//----------- jQuery.getScript()
QUnit.asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function( assert ) {
- Globals.register("testBar");
- jQuery.getScript( url("data/testbar.php"), function() {
- assert.strictEqual( window["testBar"], "bar", "Check if script was evaluated" );
+ Globals.register( "testBar" );
+ jQuery.getScript( url( "data/testbar.php" ), function() {
+ assert.strictEqual( window[ "testBar" ], "bar", "Check if script was evaluated" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() {
- Globals.register("testBar");
- jQuery.getScript( url("data/testbar.php") ).done( start );
- });
+ Globals.register( "testBar" );
+ jQuery.getScript( url( "data/testbar.php" ) ).done( start );
+ } );
QUnit.asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function( assert ) {
- Globals.register("testBar");
- jQuery.getScript( url("data/testbar.php"), function( data, _, jqXHR ) {
+ Globals.register( "testBar" );
+ jQuery.getScript( url( "data/testbar.php" ), function( data, _, jqXHR ) {
assert.strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" );
QUnit.start();
- });
- });
+ } );
+ } );
// //----------- jQuery.fn.load()
// check if load can be called with only url
QUnit.asyncTest( "jQuery.fn.load( String )", 2, function( assert ) {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" );
}
- });
- jQuery("#first").load( "data/name.html", start );
- });
+ } );
+ jQuery( "#first" ).load( "data/name.html", start );
+ } );
QUnit.test( "jQuery.fn.load() - 404 error callbacks", function( assert ) {
assert.expect( 6 );
@@ -1961,134 +1965,134 @@ QUnit.module( "ajax", {
addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert )();
jQuery( document ).ajaxStop( done );
- jQuery("<div/>").load( "data/404.html", function() {
+ jQuery( "<div/>" ).load( "data/404.html", function() {
assert.ok( true, "complete" );
- });
- });
+ } );
+ } );
// check if load can be called with url and null data
QUnit.asyncTest( "jQuery.fn.load( String, null )", 2, function( assert ) {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" );
}
- });
- jQuery("#first").load( "data/name.html", null, start );
- });
+ } );
+ jQuery( "#first" ).load( "data/name.html", null, start );
+ } );
// check if load can be called with url and undefined data
QUnit.asyncTest( "jQuery.fn.load( String, undefined )", 2, function( assert ) {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" );
}
- });
- jQuery("#first").load( "data/name.html", undefined, start );
- });
+ } );
+ jQuery( "#first" ).load( "data/name.html", undefined, start );
+ } );
// check if load can be called with only url
QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function( assert ) {
- jQuery("#first").load( "data/test3.html div.user", function() {
- assert.strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" );
+ jQuery( "#first" ).load( "data/test3.html div.user", function() {
+ assert.strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" );
QUnit.start();
- });
- });
+ } );
+ } );
// Selector should be trimmed to avoid leading spaces (#14773)
QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function( assert ) {
- jQuery("#first").load( "data/test3.html #superuser ", function() {
- assert.strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" );
+ jQuery( "#first" ).load( "data/test3.html #superuser ", function() {
+ assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function( assert ) {
- jQuery("#first").load( url("data/name.html"), function() {
- assert.ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
+ jQuery( "#first" ).load( url( "data/name.html" ), function() {
+ assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function( assert ) {
var verifyEvaluation = function() {
- assert.strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" );
- assert.strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
+ assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated after load" );
+ assert.strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" );
QUnit.start();
};
- Globals.register("testFoo");
- Globals.register("testBar");
+ Globals.register( "testFoo" );
+ Globals.register( "testBar" );
- jQuery("#first").load( url("data/test.html"), function() {
- assert.ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" );
- assert.strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" );
- assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
+ jQuery( "#first" ).load( url( "data/test.html" ), function() {
+ assert.ok( jQuery( "#first" ).html().match( /^html text/ ), "Check content after loading html" );
+ assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
+ assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" );
setTimeout( verifyEvaluation, 600 );
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function( assert ) {
- Globals.register("testFoo");
+ Globals.register( "testFoo" );
- jQuery("#first").load( url("data/test2.html"), function() {
- assert.strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
- assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
+ jQuery( "#first" ).load( url( "data/test2.html" ), function() {
+ assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
+ assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function( assert ) {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
dataFilter: function() {
return "Hello World";
}
- });
- jQuery("<div/>").load( url("data/name.html"), function( responseText ) {
+ } );
+ jQuery( "<div/>" ).load( url( "data/name.html" ), function( responseText ) {
assert.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
assert.strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function( assert ) {
- jQuery("<div />").load( url("data/params_html.php"), {
+ jQuery( "<div />" ).load( url( "data/params_html.php" ), {
"foo": 3,
"bar": "ok"
}, function() {
- var $post = jQuery( this ).find("#post");
- assert.strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" );
- assert.strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" );
+ var $post = jQuery( this ).find( "#post" );
+ assert.strictEqual( $post.find( "#foo" ).text(), "3", "Check if a hash of data is passed correctly" );
+ assert.strictEqual( $post.find( "#bar" ).text(), "ok", "Check if a hash of data is passed correctly" );
QUnit.start();
- });
- });
+ } );
+ } );
QUnit.test( "jQuery.fn.load( String, String, Function )", 2, function( assert ) {
var done = assert.async();
- jQuery("<div />").load( url("data/params_html.php"), "foo=3&bar=ok", function() {
- var $get = jQuery( this ).find("#get");
- assert.strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" );
- assert.strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" );
+ jQuery( "<div />" ).load( url( "data/params_html.php" ), "foo=3&bar=ok", function() {
+ var $get = jQuery( this ).find( "#get" );
+ assert.strictEqual( $get.find( "#foo" ).text(), "3", "Check if a string of data is passed correctly" );
+ assert.strictEqual( $get.find( "#bar" ).text(), "ok", "Check if a of data is passed correctly" );
done();
- });
- });
+ } );
+ } );
QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", 8, function( assert ) {
var completeArgs = {};
var done = assert.async();
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
success: function( _, status, jqXHR ) {
completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
},
error: function( jqXHR, status ) {
completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
}
- });
+ } );
jQuery.when.apply(
jQuery,
- jQuery.map([
+ jQuery.map( [
{
type: "success",
url: "data/echoQuery.php?arg=pop"
@@ -2099,33 +2103,33 @@ QUnit.module( "ajax", {
}
],
function( options ) {
- return jQuery.Deferred(function( defer ) {
- jQuery("#foo").load( options.url, function() {
+ return jQuery.Deferred( function( defer ) {
+ jQuery( "#foo" ).load( options.url, function() {
var args = arguments;
assert.strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" );
jQuery.each( completeArgs[ options.url ], function( i, value ) {
assert.strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" );
- });
+ } );
defer.resolve();
- });
- });
- })
+ } );
+ } );
+ } )
).always( done );
- });
+ } );
QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function( assert ) {
var done = assert.async();
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
dataType: "json"
- });
- jQuery( document ).ajaxComplete(function( e, xml, s ) {
+ } );
+ jQuery( document ).ajaxComplete( function( e, xml, s ) {
assert.strictEqual( s.dataType, "html", "Verify the load() dataType was html" );
- jQuery( document ).off("ajaxComplete");
+ jQuery( document ).off( "ajaxComplete" );
done();
- });
- jQuery("#first").load("data/test3.html");
- });
+ } );
+ jQuery( "#first" ).load( "data/test3.html" );
+ } );
QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function( assert ) {
var done = assert.async();
@@ -2133,17 +2137,17 @@ QUnit.module( "ajax", {
var data = {
"baz": 1
};
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
data: {
"foo": "bar"
}
- });
- jQuery("#foo").load( "data/echoQuery.php", data );
- jQuery( document ).ajaxComplete(function( event, jqXHR, options ) {
- assert.ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" );
+ } );
+ jQuery( "#foo" ).load( "data/echoQuery.php", data );
+ jQuery( document ).ajaxComplete( function( event, jqXHR, options ) {
+ assert.ok( ~options.data.indexOf( "foo=bar" ), "Data from ajaxSettings was used" );
done();
- });
- });
+ } );
+ } );
// //----------- jQuery.post()
@@ -2152,20 +2156,20 @@ QUnit.module( "ajax", {
jQuery.when(
jQuery.post(
- url("data/name.php"),
+ url( "data/name.php" ),
{
xml: "5-2",
length: 3
},
function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery( "math", xml ).each( function() {
assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
+ } );
}
),
- jQuery.ajax({
- url: url("data/echoData.php"),
+ jQuery.ajax( {
+ url: url( "data/echoData.php" ),
type: "POST",
data: {
"test": {
@@ -2176,66 +2180,66 @@ QUnit.module( "ajax", {
success: function( data ) {
assert.strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
}
- })
- ).always(function() {
+ } )
+ ).always( function() {
done();
- });
- });
+ } );
+ } );
QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function( assert ) {
var done = assert.async();
jQuery.when(
jQuery.post(
- url("data/name.php"),
+ url( "data/name.php" ),
{
"xml": "5-2"
},
function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery( "math", xml ).each( function() {
assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
+ } );
}
),
- jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery.post( url( "data/name.php?xml=5-2" ), {}, function( xml ) {
+ jQuery( "math", xml ).each( function() {
assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
- })
- ).always(function() {
+ } );
+ } )
+ ).always( function() {
done();
- });
- });
+ } );
+ } );
QUnit.test( "jQuery[get|post]( options ) - simple with xml", 2, function( assert ) {
var done = assert.async();
jQuery.when.apply( jQuery,
- jQuery.map( [ "get", "post" ] , function( method ) {
- return jQuery[ method ]({
+ jQuery.map( [ "get", "post" ], function( method ) {
+ return jQuery[ method ]( {
url: url( "data/name.php" ),
data: {
"xml": "5-2"
},
success: function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery( "math", xml ).each( function() {
assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
+ } );
}
- });
- })
- ).always(function() {
+ } );
+ } )
+ ).always( function() {
done();
- });
- });
+ } );
+ } );
//----------- jQuery.active
QUnit.test( "jQuery.active", function( assert ) {
assert.expect( 1 );
assert.ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
- });
+ } );
-})();
+} )();
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index 6d8848a3e..59c8ec50b 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -1,6 +1,6 @@
QUnit.module( "attributes", {
teardown: moduleTeardown
-});
+} );
function bareObj( value ) {
return value;
@@ -47,7 +47,7 @@ QUnit.test( "jQuery.propFix integrity test", function( assert ) {
};
assert.deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" );
-});
+} );
QUnit.test( "attr(String)", function( assert ) {
assert.expect( 50 );
@@ -56,199 +56,200 @@ QUnit.test( "attr(String)", function( assert ) {
select, optgroup, option, $img, styleElem,
$button, $form, $a;
- assert.equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" );
- assert.equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" );
- assert.equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" );
- assert.equal( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" );
- assert.equal( jQuery("#google").attr("title"), "Google!", "Check for title attribute" );
- assert.equal( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" );
- assert.equal( jQuery("#en").attr("lang"), "en", "Check for lang attribute" );
- assert.equal( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" );
- assert.equal( jQuery("#name").attr("name"), "name", "Check for name attribute" );
- assert.equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" );
- assert.ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" );
- assert.equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" );
- assert.equal( jQuery("#text1").attr("value", "").attr("value"), "", "Check setting the value attribute to empty string" );
- assert.equal( jQuery("<div value='t'></div>").attr("value"), "t", "Check setting custom attr named 'value' on a div" );
- assert.equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existent attribute on a form" );
- assert.equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" );
+ assert.equal( jQuery( "#text1" ).attr( "type" ), "text", "Check for type attribute" );
+ assert.equal( jQuery( "#radio1" ).attr( "type" ), "radio", "Check for type attribute" );
+ assert.equal( jQuery( "#check1" ).attr( "type" ), "checkbox", "Check for type attribute" );
+ assert.equal( jQuery( "#simon1" ).attr( "rel" ), "bookmark", "Check for rel attribute" );
+ assert.equal( jQuery( "#google" ).attr( "title" ), "Google!", "Check for title attribute" );
+ assert.equal( jQuery( "#mark" ).attr( "hreflang" ), "en", "Check for hreflang attribute" );
+ assert.equal( jQuery( "#en" ).attr( "lang" ), "en", "Check for lang attribute" );
+ assert.equal( jQuery( "#simon" ).attr( "class" ), "blog link", "Check for class attribute" );
+ assert.equal( jQuery( "#name" ).attr( "name" ), "name", "Check for name attribute" );
+ assert.equal( jQuery( "#text1" ).attr( "name" ), "action", "Check for name attribute" );
+ assert.ok( jQuery( "#form" ).attr( "action" ).indexOf( "formaction" ) >= 0, "Check for action attribute" );
+ assert.equal( jQuery( "#text1" ).attr( "value", "t" ).attr( "value" ), "t", "Check setting the value attribute" );
+ assert.equal( jQuery( "#text1" ).attr( "value", "" ).attr( "value" ), "", "Check setting the value attribute to empty string" );
+ assert.equal( jQuery( "<div value='t'></div>" ).attr( "value" ), "t", "Check setting custom attr named 'value' on a div" );
+ assert.equal( jQuery( "#form" ).attr( "blah", "blah" ).attr( "blah" ), "blah", "Set non-existent attribute on a form" );
+ assert.equal( jQuery( "#foo" ).attr( "height" ), undefined, "Non existent height attribute should return undefined" );
// [7472] & [3113] (form contains an input with name="action" or name="id")
- extras = jQuery("<input id='id' name='id' /><input id='name' name='name' /><input id='target' name='target' />").appendTo("#testForm");
- assert.equal( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" );
- assert.equal( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" );
- assert.equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" );
- assert.equal( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" );
+ extras = jQuery( "<input id='id' name='id' /><input id='name' name='name' /><input id='target' name='target' />" ).appendTo( "#testForm" );
+ assert.equal( jQuery( "#form" ).attr( "action", "newformaction" ).attr( "action" ), "newformaction", "Check that action attribute was changed" );
+ assert.equal( jQuery( "#testForm" ).attr( "target" ), undefined, "Retrieving target does not equal the input with name=target" );
+ assert.equal( jQuery( "#testForm" ).attr( "target", "newTarget" ).attr( "target" ), "newTarget", "Set target successfully on a form" );
+ assert.equal( jQuery( "#testForm" ).removeAttr( "id" ).attr( "id" ), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" );
+
// Bug #3685 (form contains input with name="name")
- assert.equal( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" );
+ assert.equal( jQuery( "#testForm" ).attr( "name" ), undefined, "Retrieving name does not retrieve input with name=name" );
extras.remove();
- assert.equal( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" );
- assert.equal( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" );
- assert.equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" );
+ assert.equal( jQuery( "#text1" ).attr( "maxlength" ), "30", "Check for maxlength attribute" );
+ assert.equal( jQuery( "#text1" ).attr( "maxLength" ), "30", "Check for maxLength attribute" );
+ assert.equal( jQuery( "#area1" ).attr( "maxLength" ), "30", "Check for maxLength attribute" );
// using innerHTML in IE causes href attribute to be serialized to the full path
- jQuery("<a/>").attr({
+ jQuery( "<a/>" ).attr( {
"id": "tAnchor5",
"href": "#5"
- }).appendTo("#qunit-fixture");
- assert.equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" );
- jQuery("<a id='tAnchor6' href='#5' />").appendTo("#qunit-fixture");
- assert.equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" );
+ } ).appendTo( "#qunit-fixture" );
+ assert.equal( jQuery( "#tAnchor5" ).attr( "href" ), "#5", "Check for non-absolute href (an anchor)" );
+ jQuery( "<a id='tAnchor6' href='#5' />" ).appendTo( "#qunit-fixture" );
+ assert.equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#tAnchor6" ).prop( "href" ), "Check for absolute href prop on an anchor" );
- jQuery("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture");
- assert.equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" );
+ jQuery( "<script type='jquery/test' src='#5' id='scriptSrc'></script>" ).appendTo( "#qunit-fixture" );
+ assert.equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#scriptSrc" ).prop( "src" ), "Check for absolute src prop on a script" );
// list attribute is readonly by default in browsers that support it
- jQuery("#list-test").attr( "list", "datalist" );
- assert.equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" );
+ jQuery( "#list-test" ).attr( "list", "datalist" );
+ assert.equal( jQuery( "#list-test" ).attr( "list" ), "datalist", "Check setting list attribute" );
// Related to [5574] and [5683]
body = document.body;
$body = jQuery( body );
- assert.strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" );
+ assert.strictEqual( $body.attr( "foo" ), undefined, "Make sure that a non existent attribute returns undefined" );
body.setAttribute( "foo", "baz" );
- assert.equal( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
+ assert.equal( $body.attr( "foo" ), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
- $body.attr( "foo","cool" );
- assert.equal( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" );
+ $body.attr( "foo", "cool" );
+ assert.equal( $body.attr( "foo" ), "cool", "Make sure that setting works well when both expando and dom attribute are available" );
- body.removeAttribute("foo"); // Cleanup
+ body.removeAttribute( "foo" ); // Cleanup
- select = document.createElement("select");
- optgroup = document.createElement("optgroup");
- option = document.createElement("option");
+ select = document.createElement( "select" );
+ optgroup = document.createElement( "optgroup" );
+ option = document.createElement( "option" );
optgroup.appendChild( option );
select.appendChild( optgroup );
- assert.equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
+ assert.equal( jQuery( option ).prop( "selected" ), true, "Make sure that a single option is selected, even when in an optgroup." );
- $img = jQuery("<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>").appendTo("body");
- assert.equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." );
- assert.equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." );
+ $img = jQuery( "<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>" ).appendTo( "body" );
+ assert.equal( $img.attr( "width" ), "215", "Retrieve width attribute an an element with display:none." );
+ assert.equal( $img.attr( "height" ), "53", "Retrieve height attribute an an element with display:none." );
// Check for style support
- styleElem = jQuery("<div/>").appendTo("#qunit-fixture").css({
+ styleElem = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).css( {
background: "url(UPPERlower.gif)"
- });
- assert.ok( !!~styleElem.attr("style").indexOf("UPPERlower.gif"), "Check style attribute getter" );
- assert.ok( !!~styleElem.attr("style", "position:absolute;").attr("style").indexOf("absolute"), "Check style setter" );
+ } );
+ assert.ok( !!~styleElem.attr( "style" ).indexOf( "UPPERlower.gif" ), "Check style attribute getter" );
+ assert.ok( !!~styleElem.attr( "style", "position:absolute;" ).attr( "style" ).indexOf( "absolute" ), "Check style setter" );
// Check value on button element (#1954)
- $button = jQuery("<button>text</button>").insertAfter("#button");
- assert.strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" );
- assert.equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" );
- assert.equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" );
+ $button = jQuery( "<button>text</button>" ).insertAfter( "#button" );
+ assert.strictEqual( $button.attr( "value" ), undefined, "Absence of value attribute on a button" );
+ assert.equal( $button.attr( "value", "foobar" ).attr( "value" ), "foobar", "Value attribute on a button does not return innerHTML" );
+ assert.equal( $button.attr( "value", "baz" ).html(), "text", "Setting the value attribute does not change innerHTML" );
// Attributes with a colon on a table element (#1591)
- assert.equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
- assert.equal( jQuery("#table").attr( "test:attrib", "foobar" ).attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
+ assert.equal( jQuery( "#table" ).attr( "test:attrib" ), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
+ assert.equal( jQuery( "#table" ).attr( "test:attrib", "foobar" ).attr( "test:attrib" ), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
- $form = jQuery("<form class='something'></form>").appendTo("#qunit-fixture");
- assert.equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." );
+ $form = jQuery( "<form class='something'></form>" ).appendTo( "#qunit-fixture" );
+ assert.equal( $form.attr( "class" ), "something", "Retrieve the class attribute on a form." );
- $a = jQuery("<a href='#' onclick='something()'>Click</a>").appendTo("#qunit-fixture");
- assert.equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." );
+ $a = jQuery( "<a href='#' onclick='something()'>Click</a>" ).appendTo( "#qunit-fixture" );
+ assert.equal( $a.attr( "onclick" ), "something()", "Retrieve ^on attribute without anonymous function wrapper." );
- assert.ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
- assert.ok( jQuery("<div/>").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." );
- assert.equal( jQuery("<div/>").attr( "title", "something" ).attr("title"), "something", "Set the title attribute." );
- assert.ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
- assert.equal( jQuery("<div/>").attr("value"), undefined, "An unset value on a div returns undefined." );
- assert.strictEqual( jQuery("<select><option value='property'></option></select>").attr("value"), undefined, "An unset value on a select returns undefined." );
+ assert.ok( jQuery( "<div/>" ).attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no attribute is found." );
+ assert.ok( jQuery( "<div/>" ).attr( "title" ) === undefined, "Make sure undefined is returned when no attribute is found." );
+ assert.equal( jQuery( "<div/>" ).attr( "title", "something" ).attr( "title" ), "something", "Set the title attribute." );
+ assert.ok( jQuery().attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no element is there." );
+ assert.equal( jQuery( "<div/>" ).attr( "value" ), undefined, "An unset value on a div returns undefined." );
+ assert.strictEqual( jQuery( "<select><option value='property'></option></select>" ).attr( "value" ), undefined, "An unset value on a select returns undefined." );
- $form = jQuery("#form").attr( "enctype", "multipart/form-data" );
- assert.equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
+ $form = jQuery( "#form" ).attr( "enctype", "multipart/form-data" );
+ assert.equal( $form.prop( "enctype" ), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
-});
+} );
QUnit.test( "attr(String) on cloned elements, #9646", function( assert ) {
assert.expect( 4 );
var div,
- input = jQuery("<input name='tester' />");
+ input = jQuery( "<input name='tester' />" );
- input.attr("name");
+ input.attr( "name" );
assert.strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" );
- div = jQuery("<div id='tester' />");
- div.attr("id");
+ div = jQuery( "<div id='tester' />" );
+ div.attr( "id" );
assert.strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" );
- input = jQuery("<input value='tester' />");
- input.attr("value");
+ input = jQuery( "<input value='tester' />" );
+ input.attr( "value" );
assert.strictEqual( input.clone( true ).attr( "value", "test" )[ 0 ].value, "test", "Value attribute should be changed on cloned element" );
assert.strictEqual( input.clone( true ).attr( "value", 42 )[ 0 ].value, "42", "Value attribute should be changed on cloned element" );
-});
+} );
QUnit.test( "attr(String) in XML Files", function( assert ) {
assert.expect( 3 );
var xml = createDashboardXML();
- assert.equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
- assert.equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
- assert.equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" );
-});
+ assert.equal( jQuery( "locations", xml ).attr( "class" ), "foo", "Check class attribute in XML document" );
+ assert.equal( jQuery( "location", xml ).attr( "for" ), "bar", "Check for attribute in XML document" );
+ assert.equal( jQuery( "location", xml ).attr( "checked" ), "different", "Check that hooks are not attached in XML document" );
+} );
QUnit.test( "attr(String, Function)", function( assert ) {
assert.expect( 2 );
assert.equal(
- jQuery("#text1").attr( "value", function() {
+ jQuery( "#text1" ).attr( "value", function() {
return this.id;
- }).attr("value"),
+ } ).attr( "value" ),
"text1",
"Set value from id"
);
assert.equal(
- jQuery("#text1").attr( "title", function(i) {
+ jQuery( "#text1" ).attr( "title", function( i ) {
return i;
- }).attr("title"),
+ } ).attr( "title" ),
"0",
"Set value with an index"
);
-});
+} );
QUnit.test( "attr(Hash)", function( assert ) {
assert.expect( 3 );
var pass = true;
- jQuery("div").attr({
+ jQuery( "div" ).attr( {
"foo": "baz",
"zoo": "ping"
- }).each(function() {
- if ( this.getAttribute("foo") !== "baz" && this.getAttribute("zoo") !== "ping" ) {
+ } ).each( function() {
+ if ( this.getAttribute( "foo" ) !== "baz" && this.getAttribute( "zoo" ) !== "ping" ) {
pass = false;
}
- });
+ } );
assert.ok( pass, "Set Multiple Attributes" );
assert.equal(
- jQuery("#text1").attr({
+ jQuery( "#text1" ).attr( {
"value": function() {
- return this["id"];
- }}).attr("value"),
+ return this[ "id" ];
+ } } ).attr( "value" ),
"text1",
"Set attribute to computed value #1"
);
assert.equal(
- jQuery("#text1").attr({
- "title": function(i) {
+ jQuery( "#text1" ).attr( {
+ "title": function( i ) {
return i;
}
- }).attr("title"),
+ } ).attr( "title" ),
"0",
"Set attribute to computed value #2"
);
-});
+} );
QUnit.test( "attr(String, Object)", function( assert ) {
assert.expect( 71 );
@@ -257,12 +258,12 @@ QUnit.test( "attr(String, Object)", function( assert ) {
attributeNode, commentNode, textNode, obj,
table, td, j, type,
check, thrown, button, $radio, $radios, $svg,
- div = jQuery("div").attr("foo", "bar"),
+ div = jQuery( "div" ).attr( "foo", "bar" ),
i = 0,
fail = false;
for ( ; i < div.length; i++ ) {
- if ( div[ i ].getAttribute("foo") !== "bar" ) {
+ if ( div[ i ].getAttribute( "foo" ) !== "bar" ) {
fail = i;
break;
}
@@ -271,187 +272,187 @@ QUnit.test( "attr(String, Object)", function( assert ) {
assert.equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" );
assert.ok(
- jQuery("#foo").attr({
+ jQuery( "#foo" ).attr( {
"width": null
- }),
+ } ),
"Try to set an attribute to nothing"
);
- jQuery("#name").attr( "name", "something" );
- assert.equal( jQuery("#name").attr("name"), "something", "Set name attribute" );
- jQuery("#name").attr( "name", null );
- assert.equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
+ jQuery( "#name" ).attr( "name", "something" );
+ assert.equal( jQuery( "#name" ).attr( "name" ), "something", "Set name attribute" );
+ jQuery( "#name" ).attr( "name", null );
+ assert.equal( jQuery( "#name" ).attr( "name" ), undefined, "Remove name attribute" );
$input = jQuery( "<input>", {
name: "something",
id: "specified"
- });
- assert.equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
- assert.equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." );
+ } );
+ assert.equal( $input.attr( "name" ), "something", "Check element creation gets/sets the name attribute." );
+ assert.equal( $input.attr( "id" ), "specified", "Check element creation gets/sets the id attribute." );
// As of fixing #11115, we only guarantee boolean property update for checked and selected
- $input = jQuery("<input type='checkbox'/>").attr( "checked", true );
- assert.equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" );
- assert.equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" );
- $input = jQuery("<option/>").attr( "selected", true );
- assert.equal( $input.prop("selected"), true, "Setting selected updates property (verified by .prop)" );
- assert.equal( $input[0].selected, true, "Setting selected updates property (verified by native property)" );
-
- $input = jQuery("#check2");
+ $input = jQuery( "<input type='checkbox'/>" ).attr( "checked", true );
+ assert.equal( $input.prop( "checked" ), true, "Setting checked updates property (verified by .prop)" );
+ assert.equal( $input[ 0 ].checked, true, "Setting checked updates property (verified by native property)" );
+ $input = jQuery( "<option/>" ).attr( "selected", true );
+ assert.equal( $input.prop( "selected" ), true, "Setting selected updates property (verified by .prop)" );
+ assert.equal( $input[ 0 ].selected, true, "Setting selected updates property (verified by native property)" );
+
+ $input = jQuery( "#check2" );
$input.prop( "checked", true ).prop( "checked", false ).attr( "checked", true );
- assert.equal( $input.attr("checked"), "checked", "Set checked (verified by .attr)" );
+ assert.equal( $input.attr( "checked" ), "checked", "Set checked (verified by .attr)" );
$input.prop( "checked", false ).prop( "checked", true ).attr( "checked", false );
- assert.equal( $input.attr("checked"), undefined, "Remove checked (verified by .attr)" );
+ assert.equal( $input.attr( "checked" ), undefined, "Remove checked (verified by .attr)" );
- $input = jQuery("#text1").prop( "readOnly", true ).prop( "readOnly", false ).attr( "readonly", true );
- assert.equal( $input.attr("readonly"), "readonly", "Set readonly (verified by .attr)" );
+ $input = jQuery( "#text1" ).prop( "readOnly", true ).prop( "readOnly", false ).attr( "readonly", true );
+ assert.equal( $input.attr( "readonly" ), "readonly", "Set readonly (verified by .attr)" );
$input.prop( "readOnly", false ).prop( "readOnly", true ).attr( "readonly", false );
- assert.equal( $input.attr("readonly"), undefined, "Remove readonly (verified by .attr)" );
+ assert.equal( $input.attr( "readonly" ), undefined, "Remove readonly (verified by .attr)" );
- $input = jQuery("#check2").attr( "checked", true ).attr( "checked", false ).prop( "checked", true );
- assert.equal( $input[0].checked, true, "Set checked property (verified by native property)" );
- assert.equal( $input.prop("checked"), true, "Set checked property (verified by .prop)" );
- assert.equal( $input.attr("checked"), undefined, "Setting checked property doesn't affect checked attribute" );
+ $input = jQuery( "#check2" ).attr( "checked", true ).attr( "checked", false ).prop( "checked", true );
+ assert.equal( $input[ 0 ].checked, true, "Set checked property (verified by native property)" );
+ assert.equal( $input.prop( "checked" ), true, "Set checked property (verified by .prop)" );
+ assert.equal( $input.attr( "checked" ), undefined, "Setting checked property doesn't affect checked attribute" );
$input.attr( "checked", false ).attr( "checked", true ).prop( "checked", false );
- assert.equal( $input[0].checked, false, "Clear checked property (verified by native property)" );
- assert.equal( $input.prop("checked"), false, "Clear checked property (verified by .prop)" );
- assert.equal( $input.attr("checked"), "checked", "Clearing checked property doesn't affect checked attribute" );
+ assert.equal( $input[ 0 ].checked, false, "Clear checked property (verified by native property)" );
+ assert.equal( $input.prop( "checked" ), false, "Clear checked property (verified by .prop)" );
+ assert.equal( $input.attr( "checked" ), "checked", "Clearing checked property doesn't affect checked attribute" );
- $input = jQuery("#check2").attr( "checked", false ).attr( "checked", "checked" );
- assert.equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" );
+ $input = jQuery( "#check2" ).attr( "checked", false ).attr( "checked", "checked" );
+ assert.equal( $input.attr( "checked" ), "checked", "Set checked to 'checked' (verified by .attr)" );
- $radios = jQuery("#checkedtest").find("input[type='radio']");
- $radios.eq( 1 ).trigger("click");
- assert.equal( $radios.eq( 1 ).prop("checked"), true, "Second radio was checked when clicked" );
- assert.equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" );
+ $radios = jQuery( "#checkedtest" ).find( "input[type='radio']" );
+ $radios.eq( 1 ).trigger( "click" );
+ assert.equal( $radios.eq( 1 ).prop( "checked" ), true, "Second radio was checked when clicked" );
+ assert.equal( $radios.eq( 0 ).attr( "checked" ), "checked", "First radio is still [checked]" );
- $input = jQuery("#text1").attr( "readonly", false ).prop( "readOnly", true );
- assert.equal( $input[0].readOnly, true, "Set readonly property (verified by native property)" );
- assert.equal( $input.prop("readOnly"), true, "Set readonly property (verified by .prop)" );
+ $input = jQuery( "#text1" ).attr( "readonly", false ).prop( "readOnly", true );
+ assert.equal( $input[ 0 ].readOnly, true, "Set readonly property (verified by native property)" );
+ assert.equal( $input.prop( "readOnly" ), true, "Set readonly property (verified by .prop)" );
$input.attr( "readonly", true ).prop( "readOnly", false );
- assert.equal( $input[0].readOnly, false, "Clear readonly property (verified by native property)" );
- assert.equal( $input.prop("readOnly"), false, "Clear readonly property (verified by .prop)" );
+ assert.equal( $input[ 0 ].readOnly, false, "Clear readonly property (verified by native property)" );
+ assert.equal( $input.prop( "readOnly" ), false, "Clear readonly property (verified by .prop)" );
- $input = jQuery("#name").attr( "maxlength", "5" );
- assert.equal( $input[0].maxLength, 5, "Set maxlength (verified by native property)" );
+ $input = jQuery( "#name" ).attr( "maxlength", "5" );
+ assert.equal( $input[ 0 ].maxLength, 5, "Set maxlength (verified by native property)" );
$input.attr( "maxLength", "10" );
- assert.equal( $input[0].maxLength, 10, "Set maxlength (verified by native property)" );
+ assert.equal( $input[ 0 ].maxLength, 10, "Set maxlength (verified by native property)" );
// HTML5 boolean attributes
- $text = jQuery("#text1").attr({
+ $text = jQuery( "#text1" ).attr( {
"autofocus": true,
"required": true
- });
- assert.equal( $text.attr("autofocus"), "autofocus", "Reading autofocus attribute yields 'autofocus'" );
- assert.equal( $text.attr( "autofocus", false ).attr("autofocus"), undefined, "Setting autofocus to false removes it" );
- assert.equal( $text.attr("required"), "required", "Reading required attribute yields 'required'" );
- assert.equal( $text.attr( "required", false ).attr("required"), undefined, "Setting required attribute to false removes it" );
+ } );
+ assert.equal( $text.attr( "autofocus" ), "autofocus", "Reading autofocus attribute yields 'autofocus'" );
+ assert.equal( $text.attr( "autofocus", false ).attr( "autofocus" ), undefined, "Setting autofocus to false removes it" );
+ assert.equal( $text.attr( "required" ), "required", "Reading required attribute yields 'required'" );
+ assert.equal( $text.attr( "required", false ).attr( "required" ), undefined, "Setting required attribute to false removes it" );
- $details = jQuery("<details open></details>").appendTo("#qunit-fixture");
- assert.equal( $details.attr("open"), "open", "open attribute presence indicates true" );
- assert.equal( $details.attr( "open", false ).attr("open"), undefined, "Setting open attribute to false removes it" );
+ $details = jQuery( "<details open></details>" ).appendTo( "#qunit-fixture" );
+ assert.equal( $details.attr( "open" ), "open", "open attribute presence indicates true" );
+ assert.equal( $details.attr( "open", false ).attr( "open" ), undefined, "Setting open attribute to false removes it" );
$text.attr( "data-something", true );
- assert.equal( $text.attr("data-something"), "true", "Set data attributes");
- assert.equal( $text.data("something"), true, "Setting data attributes are not affected by boolean settings");
+ assert.equal( $text.attr( "data-something" ), "true", "Set data attributes" );
+ assert.equal( $text.data( "something" ), true, "Setting data attributes are not affected by boolean settings" );
$text.attr( "data-another", false );
- assert.equal( $text.attr("data-another"), "false", "Set data attributes");
- assert.equal( $text.data("another"), false, "Setting data attributes are not affected by boolean settings" );
- assert.equal( $text.attr( "aria-disabled", false ).attr("aria-disabled"), "false", "Setting aria attributes are not affected by boolean settings" );
- $text.removeData("something").removeData("another").removeAttr("aria-disabled");
+ assert.equal( $text.attr( "data-another" ), "false", "Set data attributes" );
+ assert.equal( $text.data( "another" ), false, "Setting data attributes are not affected by boolean settings" );
+ assert.equal( $text.attr( "aria-disabled", false ).attr( "aria-disabled" ), "false", "Setting aria attributes are not affected by boolean settings" );
+ $text.removeData( "something" ).removeData( "another" ).removeAttr( "aria-disabled" );
- jQuery("#foo").attr("contenteditable", true);
- assert.equal( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" );
+ jQuery( "#foo" ).attr( "contenteditable", true );
+ assert.equal( jQuery( "#foo" ).attr( "contenteditable" ), "true", "Enumerated attributes are set properly" );
- attributeNode = document.createAttribute("irrelevant");
- commentNode = document.createComment("some comment");
- textNode = document.createTextNode("some text");
+ attributeNode = document.createAttribute( "irrelevant" );
+ commentNode = document.createComment( "some comment" );
+ textNode = document.createTextNode( "some text" );
obj = {};
jQuery.each( [ commentNode, textNode, attributeNode ], function( i, elem ) {
var $elem = jQuery( elem );
$elem.attr( "nonexisting", "foo" );
- assert.strictEqual( $elem.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
- });
+ assert.strictEqual( $elem.attr( "nonexisting" ), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
+ } );
jQuery.each( [ window, document, obj, "#firstp" ], function( i, elem ) {
var oldVal = elem.nonexisting,
$elem = jQuery( elem );
- assert.strictEqual( $elem.attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." );
- assert.equal( $elem.attr( "nonexisting", "foo" ).attr("nonexisting"), "foo", "attr falls back to prop on unsupported arguments" );
+ assert.strictEqual( $elem.attr( "nonexisting" ), undefined, "attr works correctly for non existing attributes (bug #7500)." );
+ assert.equal( $elem.attr( "nonexisting", "foo" ).attr( "nonexisting" ), "foo", "attr falls back to prop on unsupported arguments" );
elem.nonexisting = oldVal;
- });
+ } );
// Register the property on the window for the previous assertion so it will be clean up
Globals.register( "nonexisting" );
- table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>");
- td = table.find("td").eq(0);
+ table = jQuery( "#table" ).append( "<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>" );
+ td = table.find( "td" ).eq( 0 );
td.attr( "rowspan", "2" );
- assert.equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" );
+ assert.equal( td[ 0 ][ "rowSpan" ], 2, "Check rowspan is correctly set" );
td.attr( "colspan", "2" );
- assert.equal( td[ 0 ]["colSpan"], 2, "Check colspan is correctly set" );
- table.attr("cellspacing", "2");
- assert.equal( table[ 0 ]["cellSpacing"], "2", "Check cellspacing is correctly set" );
+ assert.equal( td[ 0 ][ "colSpan" ], 2, "Check colspan is correctly set" );
+ table.attr( "cellspacing", "2" );
+ assert.equal( table[ 0 ][ "cellSpacing" ], "2", "Check cellspacing is correctly set" );
- assert.equal( jQuery("#area1").attr("value"), undefined, "Value attribute is distinct from value property." );
+ assert.equal( jQuery( "#area1" ).attr( "value" ), undefined, "Value attribute is distinct from value property." );
// for #1070
- jQuery("#name").attr( "someAttr", "0" );
- assert.equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of '0'" );
- jQuery("#name").attr( "someAttr", 0 );
- assert.equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" );
- jQuery("#name").attr( "someAttr", 1 );
- assert.equal( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" );
+ jQuery( "#name" ).attr( "someAttr", "0" );
+ assert.equal( jQuery( "#name" ).attr( "someAttr" ), "0", "Set attribute to a string of '0'" );
+ jQuery( "#name" ).attr( "someAttr", 0 );
+ assert.equal( jQuery( "#name" ).attr( "someAttr" ), "0", "Set attribute to the number 0" );
+ jQuery( "#name" ).attr( "someAttr", 1 );
+ assert.equal( jQuery( "#name" ).attr( "someAttr" ), "1", "Set attribute to the number 1" );
// using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
+ j = jQuery( "#nonnodes" ).contents();
j.attr( "name", "attrvalue" );
- assert.equal( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
- j.removeAttr("name");
+ assert.equal( j.attr( "name" ), "attrvalue", "Check node,textnode,comment for attr" );
+ j.removeAttr( "name" );
// Type
- type = jQuery("#check2").attr("type");
+ type = jQuery( "#check2" ).attr( "type" );
try {
- jQuery("#check2").attr( "type", "hidden" );
+ jQuery( "#check2" ).attr( "type", "hidden" );
assert.ok( true, "No exception thrown on input type change" );
- } catch( e ) {
+ } catch ( e ) {
assert.ok( true, "Exception thrown on input type change: " + e );
}
- check = document.createElement("input");
+ check = document.createElement( "input" );
thrown = true;
try {
jQuery( check ).attr( "type", "checkbox" );
- } catch( e ) {
+ } catch ( e ) {
thrown = false;
}
assert.ok( thrown, "Exception thrown when trying to change type property" );
- assert.equal( "checkbox", jQuery( check ).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
+ assert.equal( "checkbox", jQuery( check ).attr( "type" ), "Verify that you can change the type of an input element that isn't in the DOM" );
- check = jQuery("<input />");
+ check = jQuery( "<input />" );
thrown = true;
try {
check.attr( "type", "checkbox" );
- } catch( e ) {
+ } catch ( e ) {
thrown = false;
}
assert.ok( thrown, "Exception thrown when trying to change type property" );
- assert.equal( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
+ assert.equal( "checkbox", check.attr( "type" ), "Verify that you can change the type of an input element that isn't in the DOM" );
- button = jQuery("#button");
+ button = jQuery( "#button" );
try {
button.attr( "type", "submit" );
assert.ok( true, "No exception thrown on button type change" );
- } catch( e ) {
+ } catch ( e ) {
assert.ok( true, "Exception thrown on button type change: " + e );
}
$radio = jQuery( "<input>", {
"value": "sup",
"type": "radio"
- }).appendTo("#testForm");
+ } ).appendTo( "#testForm" );
assert.equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
// Setting attributes on svg elements (bug #3116)
@@ -460,16 +461,16 @@ QUnit.test( "attr(String, Object)", function( assert ) {
"<circle cx='200' cy='200' r='150' />" +
"</svg>"
- ).appendTo("body");
- assert.equal( $svg.attr( "cx", 100 ).attr("cx"), "100", "Set attribute on svg element" );
+ ).appendTo( "body" );
+ assert.equal( $svg.attr( "cx", 100 ).attr( "cx" ), "100", "Set attribute on svg element" );
$svg.remove();
// undefined values are chainable
- jQuery("#name").attr( "maxlength", "5" ).removeAttr("nonexisting");
- assert.equal( typeof jQuery("#name").attr( "maxlength", undefined ), "object", ".attr('attribute', undefined) is chainable (#5571)" );
- assert.equal( jQuery("#name").attr( "maxlength", undefined ).attr("maxlength"), "5", ".attr('attribute', undefined) does not change value (#5571)" );
- assert.equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
-});
+ jQuery( "#name" ).attr( "maxlength", "5" ).removeAttr( "nonexisting" );
+ assert.equal( typeof jQuery( "#name" ).attr( "maxlength", undefined ), "object", ".attr('attribute', undefined) is chainable (#5571)" );
+ assert.equal( jQuery( "#name" ).attr( "maxlength", undefined ).attr( "maxlength" ), "5", ".attr('attribute', undefined) does not change value (#5571)" );
+ assert.equal( jQuery( "#name" ).attr( "nonexisting", undefined ).attr( "nonexisting" ), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
+} );
QUnit.test( "attr - extending the boolean attrHandle", function( assert ) {
assert.expect( 1 );
@@ -483,18 +484,18 @@ QUnit.test( "attr - extending the boolean attrHandle", function( assert ) {
called = false;
jQuery( "input" ).attr( "checked" );
assert.ok( called, "The boolean attrHandle does not drop custom attrHandles" );
-});
+} );
QUnit.test( "attr(String, Object) - Loaded via XML document", function( assert ) {
assert.expect( 2 );
var xml = createDashboardXML(),
titles = [];
- jQuery( "tab", xml ).each(function() {
- titles.push( jQuery( this ).attr("title") );
- });
+ jQuery( "tab", xml ).each( function() {
+ titles.push( jQuery( this ).attr( "title" ) );
+ } );
assert.equal( titles[ 0 ], "Location", "attr() in XML context: Check first title" );
assert.equal( titles[ 1 ], "Users", "attr() in XML context: Check second title" );
-});
+} );
QUnit.test( "attr(String, Object) - Loaded via XML fragment", function( assert ) {
assert.expect( 2 );
@@ -502,121 +503,121 @@ QUnit.test( "attr(String, Object) - Loaded via XML fragment", function( assert )
$frag = jQuery( frag );
$frag.attr( "test", "some value" );
- assert.equal( $frag.attr("test"), "some value", "set attribute" );
+ assert.equal( $frag.attr( "test" ), "some value", "set attribute" );
$frag.attr( "test", null );
- assert.equal( $frag.attr("test"), undefined, "remove attribute" );
-});
+ assert.equal( $frag.attr( "test" ), undefined, "remove attribute" );
+} );
QUnit.test( "attr('tabindex')", function( assert ) {
assert.expect( 8 );
// elements not natively tabbable
- assert.equal( jQuery("#listWithTabIndex").attr("tabindex"), "5", "not natively tabbable, with tabindex set to 0" );
- assert.equal( jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set" );
+ assert.equal( jQuery( "#listWithTabIndex" ).attr( "tabindex" ), "5", "not natively tabbable, with tabindex set to 0" );
+ assert.equal( jQuery( "#divWithNoTabIndex" ).attr( "tabindex" ), undefined, "not natively tabbable, no tabindex set" );
// anchor with href
- assert.equal( jQuery("#linkWithNoTabIndex").attr("tabindex"), undefined, "anchor with href, no tabindex set" );
- assert.equal( jQuery("#linkWithTabIndex").attr("tabindex"), "2", "anchor with href, tabindex set to 2" );
- assert.equal( jQuery("#linkWithNegativeTabIndex").attr("tabindex"), "-1", "anchor with href, tabindex set to -1" );
+ assert.equal( jQuery( "#linkWithNoTabIndex" ).attr( "tabindex" ), undefined, "anchor with href, no tabindex set" );
+ assert.equal( jQuery( "#linkWithTabIndex" ).attr( "tabindex" ), "2", "anchor with href, tabindex set to 2" );
+ assert.equal( jQuery( "#linkWithNegativeTabIndex" ).attr( "tabindex" ), "-1", "anchor with href, tabindex set to -1" );
// anchor without href
- assert.equal( jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set" );
- assert.equal( jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), "1", "anchor without href, tabindex set to 2" );
- assert.equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), "-1", "anchor without href, no tabindex set" );
-});
+ assert.equal( jQuery( "#linkWithNoHrefWithNoTabIndex" ).attr( "tabindex" ), undefined, "anchor without href, no tabindex set" );
+ assert.equal( jQuery( "#linkWithNoHrefWithTabIndex" ).attr( "tabindex" ), "1", "anchor without href, tabindex set to 2" );
+ assert.equal( jQuery( "#linkWithNoHrefWithNegativeTabIndex" ).attr( "tabindex" ), "-1", "anchor without href, no tabindex set" );
+} );
QUnit.test( "attr('tabindex', value)", function( assert ) {
assert.expect( 9 );
- var element = jQuery("#divWithNoTabIndex");
- assert.equal( element.attr("tabindex"), undefined, "start with no tabindex" );
+ var element = jQuery( "#divWithNoTabIndex" );
+ assert.equal( element.attr( "tabindex" ), undefined, "start with no tabindex" );
// set a positive string
element.attr( "tabindex", "1" );
- assert.equal( element.attr("tabindex"), "1", "set tabindex to 1 (string)" );
+ assert.equal( element.attr( "tabindex" ), "1", "set tabindex to 1 (string)" );
// set a zero string
element.attr( "tabindex", "0" );
- assert.equal( element.attr("tabindex"), "0", "set tabindex to 0 (string)" );
+ assert.equal( element.attr( "tabindex" ), "0", "set tabindex to 0 (string)" );
// set a negative string
element.attr( "tabindex", "-1" );
- assert.equal( element.attr("tabindex"), "-1", "set tabindex to -1 (string)" );
+ assert.equal( element.attr( "tabindex" ), "-1", "set tabindex to -1 (string)" );
// set a positive number
element.attr( "tabindex", 1 );
- assert.equal( element.attr("tabindex"), "1", "set tabindex to 1 (number)" );
+ assert.equal( element.attr( "tabindex" ), "1", "set tabindex to 1 (number)" );
// set a zero number
element.attr( "tabindex", 0 );
- assert.equal(element.attr("tabindex"), "0", "set tabindex to 0 (number)");
+ assert.equal( element.attr( "tabindex" ), "0", "set tabindex to 0 (number)" );
// set a negative number
element.attr( "tabindex", -1 );
- assert.equal( element.attr("tabindex"), "-1", "set tabindex to -1 (number)" );
+ assert.equal( element.attr( "tabindex" ), "-1", "set tabindex to -1 (number)" );
- element = jQuery("#linkWithTabIndex");
- assert.equal( element.attr("tabindex"), "2", "start with tabindex 2" );
+ element = jQuery( "#linkWithTabIndex" );
+ assert.equal( element.attr( "tabindex" ), "2", "start with tabindex 2" );
element.attr( "tabindex", -1 );
- assert.equal( element.attr("tabindex"), "-1", "set negative tabindex" );
-});
+ assert.equal( element.attr( "tabindex" ), "-1", "set negative tabindex" );
+} );
QUnit.test( "removeAttr(String)", function( assert ) {
assert.expect( 12 );
var $first;
- assert.equal( jQuery("#mark").removeAttr("class").attr("class"), undefined, "remove class" );
- assert.equal( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" );
- assert.equal( jQuery("#foo").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute" );
- assert.equal( jQuery("#form").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" );
- assert.equal( jQuery("<div style='position: absolute'></div>").appendTo("#foo").removeAttr("style").prop("style").cssText, "", "Check removing style attribute (#9699 Webkit)" );
- assert.equal( jQuery("#fx-test-group").attr( "height", "3px" ).removeAttr("height").get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" );
+ assert.equal( jQuery( "#mark" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" );
+ assert.equal( jQuery( "#form" ).removeAttr( "id" ).attr( "id" ), undefined, "Remove id" );
+ assert.equal( jQuery( "#foo" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute" );
+ assert.equal( jQuery( "#form" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute on a form" );
+ assert.equal( jQuery( "<div style='position: absolute'></div>" ).appendTo( "#foo" ).removeAttr( "style" ).prop( "style" ).cssText, "", "Check removing style attribute (#9699 Webkit)" );
+ assert.equal( jQuery( "#fx-test-group" ).attr( "height", "3px" ).removeAttr( "height" ).get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" );
- jQuery("#check1").removeAttr("checked").prop( "checked", true ).removeAttr("checked");
- assert.equal( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" );
- jQuery("#text1").prop( "readOnly", true ).removeAttr("readonly");
- assert.equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" );
+ jQuery( "#check1" ).removeAttr( "checked" ).prop( "checked", true ).removeAttr( "checked" );
+ assert.equal( document.getElementById( "check1" ).checked, false, "removeAttr sets boolean properties to false" );
+ jQuery( "#text1" ).prop( "readOnly", true ).removeAttr( "readonly" );
+ assert.equal( document.getElementById( "text1" ).readOnly, false, "removeAttr sets boolean properties to false" );
- jQuery("#option2c").removeAttr("selected");
- assert.equal( jQuery("#option2d").attr("selected"), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)" );
+ jQuery( "#option2c" ).removeAttr( "selected" );
+ assert.equal( jQuery( "#option2d" ).attr( "selected" ), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)" );
try {
- $first = jQuery("#first").attr( "contenteditable", "true" ).removeAttr("contenteditable");
- assert.equal( $first.attr("contenteditable"), undefined, "Remove the contenteditable attribute" );
- } catch( e ) {
+ $first = jQuery( "#first" ).attr( "contenteditable", "true" ).removeAttr( "contenteditable" );
+ assert.equal( $first.attr( "contenteditable" ), undefined, "Remove the contenteditable attribute" );
+ } catch ( e ) {
assert.ok( false, "Removing contenteditable threw an error (#10429)" );
}
- $first = jQuery("<div Case='mixed'></div>");
- assert.equal( $first.attr("Case"), "mixed", "case of attribute doesn't matter" );
- $first.removeAttr("Case");
+ $first = jQuery( "<div Case='mixed'></div>" );
+ assert.equal( $first.attr( "Case" ), "mixed", "case of attribute doesn't matter" );
+ $first.removeAttr( "Case" );
assert.equal( $first.attr( "Case" ), undefined, "mixed-case attribute was removed" );
-});
+} );
QUnit.test( "removeAttr(String) in XML", function( assert ) {
assert.expect( 7 );
var xml = createDashboardXML(),
iwt = jQuery( "infowindowtab", xml );
- assert.equal( iwt.attr("normal"), "ab", "Check initial value" );
- iwt.removeAttr("Normal");
- assert.equal( iwt.attr("normal"), "ab", "Should still be there" );
- iwt.removeAttr("normal");
- assert.equal( iwt.attr("normal"), undefined, "Removed" );
+ assert.equal( iwt.attr( "normal" ), "ab", "Check initial value" );
+ iwt.removeAttr( "Normal" );
+ assert.equal( iwt.attr( "normal" ), "ab", "Should still be there" );
+ iwt.removeAttr( "normal" );
+ assert.equal( iwt.attr( "normal" ), undefined, "Removed" );
- assert.equal( iwt.attr("mixedCase"), "yes", "Check initial value" );
- assert.equal( iwt.attr("mixedcase"), undefined, "toLowerCase not work good" );
- iwt.removeAttr("mixedcase");
- assert.equal( iwt.attr("mixedCase"), "yes", "Should still be there" );
- iwt.removeAttr("mixedCase");
- assert.equal( iwt.attr("mixedCase"), undefined, "Removed" );
-});
+ assert.equal( iwt.attr( "mixedCase" ), "yes", "Check initial value" );
+ assert.equal( iwt.attr( "mixedcase" ), undefined, "toLowerCase not work good" );
+ iwt.removeAttr( "mixedcase" );
+ assert.equal( iwt.attr( "mixedCase" ), "yes", "Should still be there" );
+ iwt.removeAttr( "mixedCase" );
+ assert.equal( iwt.attr( "mixedCase" ), undefined, "Removed" );
+} );
QUnit.test( "removeAttr(Multi String, variable space width)", function( assert ) {
assert.expect( 8 );
- var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"),
+ var div = jQuery( "<div id='a' alt='b' title='c' rel='d'></div>" ),
tests = {
id: "a",
alt: "b",
@@ -626,46 +627,46 @@ QUnit.test( "removeAttr(Multi String, variable space width)", function( assert )
jQuery.each( tests, function( key, val ) {
assert.equal( div.attr( key ), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
- });
+ } );
div.removeAttr( "id alt title rel " );
jQuery.each( tests, function( key ) {
assert.equal( div.attr( key ), undefined, "Attribute `" + key + "` was removed" );
- });
-});
+ } );
+} );
QUnit.test( "prop(String, Object)", function( assert ) {
assert.expect( 17 );
- assert.equal( jQuery("#text1").prop("value"), "Test", "Check for value attribute" );
- assert.equal( jQuery("#text1").prop( "value", "Test2" ).prop("defaultValue"), "Test", "Check for defaultValue attribute" );
- assert.equal( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" );
- assert.equal( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" );
- assert.equal( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" );
- assert.equal( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." );
-
- assert.equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "Check retrieving tabindex" );
- jQuery("#text1").prop( "readonly", true );
- assert.equal( document.getElementById("text1").readOnly, true, "Check setting readOnly property with 'readonly'" );
- assert.equal( jQuery("#label-for").prop("for"), "action", "Check retrieving htmlFor" );
- jQuery("#text1").prop("class", "test");
- assert.equal( document.getElementById("text1").className, "test", "Check setting className with 'class'" );
- assert.equal( jQuery("#text1").prop("maxlength"), 30, "Check retrieving maxLength" );
- jQuery("#table").prop( "cellspacing", 1 );
- assert.equal( jQuery("#table").prop("cellSpacing"), "1", "Check setting and retrieving cellSpacing" );
- jQuery("#table").prop( "cellpadding", 1 );
- assert.equal( jQuery("#table").prop("cellPadding"), "1", "Check setting and retrieving cellPadding" );
- jQuery("#table").prop( "rowspan", 1 );
- assert.equal( jQuery("#table").prop("rowSpan"), 1, "Check setting and retrieving rowSpan" );
- jQuery("#table").prop( "colspan", 1 );
- assert.equal( jQuery("#table").prop("colSpan"), 1, "Check setting and retrieving colSpan" );
- jQuery("#table").prop( "usemap", 1 );
- assert.equal( jQuery("#table").prop("useMap"), 1, "Check setting and retrieving useMap" );
- jQuery("#table").prop( "frameborder", 1 );
- assert.equal( jQuery("#table").prop("frameBorder"), 1, "Check setting and retrieving frameBorder" );
-});
+ assert.equal( jQuery( "#text1" ).prop( "value" ), "Test", "Check for value attribute" );
+ assert.equal( jQuery( "#text1" ).prop( "value", "Test2" ).prop( "defaultValue" ), "Test", "Check for defaultValue attribute" );
+ assert.equal( jQuery( "#select2" ).prop( "selectedIndex" ), 3, "Check for selectedIndex attribute" );
+ assert.equal( jQuery( "#foo" ).prop( "nodeName" ).toUpperCase(), "DIV", "Check for nodeName attribute" );
+ assert.equal( jQuery( "#foo" ).prop( "tagName" ).toUpperCase(), "DIV", "Check for tagName attribute" );
+ assert.equal( jQuery( "<option/>" ).prop( "selected" ), false, "Check selected attribute on disconnected element." );
+
+ assert.equal( jQuery( "#listWithTabIndex" ).prop( "tabindex" ), 5, "Check retrieving tabindex" );
+ jQuery( "#text1" ).prop( "readonly", true );
+ assert.equal( document.getElementById( "text1" ).readOnly, true, "Check setting readOnly property with 'readonly'" );
+ assert.equal( jQuery( "#label-for" ).prop( "for" ), "action", "Check retrieving htmlFor" );
+ jQuery( "#text1" ).prop( "class", "test" );
+ assert.equal( document.getElementById( "text1" ).className, "test", "Check setting className with 'class'" );
+ assert.equal( jQuery( "#text1" ).prop( "maxlength" ), 30, "Check retrieving maxLength" );
+ jQuery( "#table" ).prop( "cellspacing", 1 );
+ assert.equal( jQuery( "#table" ).prop( "cellSpacing" ), "1", "Check setting and retrieving cellSpacing" );
+ jQuery( "#table" ).prop( "cellpadding", 1 );
+ assert.equal( jQuery( "#table" ).prop( "cellPadding" ), "1", "Check setting and retrieving cellPadding" );
+ jQuery( "#table" ).prop( "rowspan", 1 );
+ assert.equal( jQuery( "#table" ).prop( "rowSpan" ), 1, "Check setting and retrieving rowSpan" );
+ jQuery( "#table" ).prop( "colspan", 1 );
+ assert.equal( jQuery( "#table" ).prop( "colSpan" ), 1, "Check setting and retrieving colSpan" );
+ jQuery( "#table" ).prop( "usemap", 1 );
+ assert.equal( jQuery( "#table" ).prop( "useMap" ), 1, "Check setting and retrieving useMap" );
+ jQuery( "#table" ).prop( "frameborder", 1 );
+ assert.equal( jQuery( "#table" ).prop( "frameBorder" ), 1, "Check setting and retrieving frameBorder" );
+} );
QUnit.test( "prop(String, Object) on null/undefined", function( assert ) {
@@ -675,243 +676,243 @@ QUnit.test( "prop(String, Object) on null/undefined", function( assert ) {
body = document.body,
$body = jQuery( body );
- assert.ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" );
- body["foo"] = "bar";
- assert.equal( $body.prop("foo"), "bar", "Make sure the expando is preferred over the dom attribute" );
- body["foo"] = undefined;
- assert.ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
+ assert.ok( $body.prop( "nextSibling" ) === null, "Make sure a null expando returns null" );
+ body[ "foo" ] = "bar";
+ assert.equal( $body.prop( "foo" ), "bar", "Make sure the expando is preferred over the dom attribute" );
+ body[ "foo" ] = undefined;
+ assert.ok( $body.prop( "foo" ) === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
- select = document.createElement("select");
- optgroup = document.createElement("optgroup");
- option = document.createElement("option");
+ select = document.createElement( "select" );
+ optgroup = document.createElement( "optgroup" );
+ option = document.createElement( "option" );
optgroup.appendChild( option );
select.appendChild( optgroup );
- assert.equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
- assert.equal( jQuery( document ).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." );
+ assert.equal( jQuery( option ).prop( "selected" ), true, "Make sure that a single option is selected, even when in an optgroup." );
+ assert.equal( jQuery( document ).prop( "nodeName" ), "#document", "prop works correctly on document nodes (bug #7451)." );
- attributeNode = document.createAttribute("irrelevant");
- commentNode = document.createComment("some comment");
- textNode = document.createTextNode("some text");
+ attributeNode = document.createAttribute( "irrelevant" );
+ commentNode = document.createComment( "some comment" );
+ textNode = document.createTextNode( "some text" );
obj = {};
jQuery.each( [ document, attributeNode, commentNode, textNode, obj, "#firstp" ], function( i, ele ) {
- assert.strictEqual( jQuery( ele ).prop("nonexisting"), undefined, "prop works correctly for non existing attributes (bug #7500)." );
- });
+ assert.strictEqual( jQuery( ele ).prop( "nonexisting" ), undefined, "prop works correctly for non existing attributes (bug #7500)." );
+ } );
obj = {};
jQuery.each( [ document, obj ], function( i, ele ) {
var $ele = jQuery( ele );
$ele.prop( "nonexisting", "foo" );
- assert.equal( $ele.prop("nonexisting"), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." );
- });
- jQuery( document ).removeProp("nonexisting");
+ assert.equal( $ele.prop( "nonexisting" ), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." );
+ } );
+ jQuery( document ).removeProp( "nonexisting" );
- $form = jQuery("#form").prop( "enctype", "multipart/form-data" );
- assert.equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
-});
+ $form = jQuery( "#form" ).prop( "enctype", "multipart/form-data" );
+ assert.equal( $form.prop( "enctype" ), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
+} );
QUnit.test( "prop('tabindex')", function( assert ) {
assert.expect( 11 );
// inputs without tabIndex attribute
- assert.equal( jQuery("#inputWithoutTabIndex").prop("tabindex"), 0, "input without tabindex" );
- assert.equal( jQuery("#buttonWithoutTabIndex").prop("tabindex"), 0, "button without tabindex" );
- assert.equal( jQuery("#textareaWithoutTabIndex").prop("tabindex"), 0, "textarea without tabindex" );
+ assert.equal( jQuery( "#inputWithoutTabIndex" ).prop( "tabindex" ), 0, "input without tabindex" );
+ assert.equal( jQuery( "#buttonWithoutTabIndex" ).prop( "tabindex" ), 0, "button without tabindex" );
+ assert.equal( jQuery( "#textareaWithoutTabIndex" ).prop( "tabindex" ), 0, "textarea without tabindex" );
// elements not natively tabbable
- assert.equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0" );
- assert.equal( jQuery("#divWithNoTabIndex").prop("tabindex"), -1, "not natively tabbable, no tabindex set" );
+ assert.equal( jQuery( "#listWithTabIndex" ).prop( "tabindex" ), 5, "not natively tabbable, with tabindex set to 0" );
+ assert.equal( jQuery( "#divWithNoTabIndex" ).prop( "tabindex" ), -1, "not natively tabbable, no tabindex set" );
// anchor with href
- assert.equal( jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set" );
- assert.equal( jQuery("#linkWithTabIndex").prop("tabindex"), 2, "anchor with href, tabindex set to 2" );
- assert.equal( jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1" );
+ assert.equal( jQuery( "#linkWithNoTabIndex" ).prop( "tabindex" ), 0, "anchor with href, no tabindex set" );
+ assert.equal( jQuery( "#linkWithTabIndex" ).prop( "tabindex" ), 2, "anchor with href, tabindex set to 2" );
+ assert.equal( jQuery( "#linkWithNegativeTabIndex" ).prop( "tabindex" ), -1, "anchor with href, tabindex set to -1" );
// anchor without href
- assert.equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
- assert.equal( jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2" );
- assert.equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
-});
+ assert.equal( jQuery( "#linkWithNoHrefWithNoTabIndex" ).prop( "tabindex" ), -1, "anchor without href, no tabindex set" );
+ assert.equal( jQuery( "#linkWithNoHrefWithTabIndex" ).prop( "tabindex" ), 1, "anchor without href, tabindex set to 2" );
+ assert.equal( jQuery( "#linkWithNoHrefWithNegativeTabIndex" ).prop( "tabindex" ), -1, "anchor without href, no tabindex set" );
+} );
QUnit.test( "prop('tabindex', value)", function( assert ) {
assert.expect( 10 );
var clone,
- element = jQuery("#divWithNoTabIndex");
+ element = jQuery( "#divWithNoTabIndex" );
- assert.equal( element.prop("tabindex"), -1, "start with no tabindex" );
+ assert.equal( element.prop( "tabindex" ), -1, "start with no tabindex" );
// set a positive string
element.prop( "tabindex", "1" );
- assert.equal( element.prop("tabindex"), 1, "set tabindex to 1 (string)" );
+ assert.equal( element.prop( "tabindex" ), 1, "set tabindex to 1 (string)" );
// set a zero string
element.prop( "tabindex", "0" );
- assert.equal( element.prop("tabindex"), 0, "set tabindex to 0 (string)" );
+ assert.equal( element.prop( "tabindex" ), 0, "set tabindex to 0 (string)" );
// set a negative string
element.prop( "tabindex", "-1" );
- assert.equal( element.prop("tabindex"), -1, "set tabindex to -1 (string)" );
+ assert.equal( element.prop( "tabindex" ), -1, "set tabindex to -1 (string)" );
// set a positive number
element.prop( "tabindex", 1 );
- assert.equal( element.prop("tabindex"), 1, "set tabindex to 1 (number)" );
+ assert.equal( element.prop( "tabindex" ), 1, "set tabindex to 1 (number)" );
// set a zero number
element.prop( "tabindex", 0 );
- assert.equal( element.prop("tabindex"), 0, "set tabindex to 0 (number)" );
+ assert.equal( element.prop( "tabindex" ), 0, "set tabindex to 0 (number)" );
// set a negative number
element.prop( "tabindex", -1 );
- assert.equal( element.prop("tabindex"), -1, "set tabindex to -1 (number)" );
+ assert.equal( element.prop( "tabindex" ), -1, "set tabindex to -1 (number)" );
- element = jQuery("#linkWithTabIndex");
- assert.equal( element.prop("tabindex"), 2, "start with tabindex 2" );
+ element = jQuery( "#linkWithTabIndex" );
+ assert.equal( element.prop( "tabindex" ), 2, "start with tabindex 2" );
element.prop( "tabindex", -1 );
- assert.equal( element.prop("tabindex"), -1, "set negative tabindex" );
+ assert.equal( element.prop( "tabindex" ), -1, "set negative tabindex" );
clone = element.clone();
clone.prop( "tabindex", 1 );
- assert.equal( clone[ 0 ].getAttribute("tabindex"), "1", "set tabindex on cloned element" );
-});
+ assert.equal( clone[ 0 ].getAttribute( "tabindex" ), "1", "set tabindex on cloned element" );
+} );
QUnit.test( "removeProp(String)", function( assert ) {
assert.expect( 6 );
- var attributeNode = document.createAttribute("irrelevant"),
- commentNode = document.createComment("some comment"),
- textNode = document.createTextNode("some text"),
+ var attributeNode = document.createAttribute( "irrelevant" ),
+ commentNode = document.createComment( "some comment" ),
+ textNode = document.createTextNode( "some text" ),
obj = {};
assert.strictEqual(
- jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ]["nonexisting"],
+ jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ][ "nonexisting" ],
undefined,
"removeprop works correctly on DOM element nodes"
);
jQuery.each( [ document, obj ], function( i, ele ) {
var $ele = jQuery( ele );
- $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting");
- assert.strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
- });
+ $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" );
+ assert.strictEqual( ele[ "nonexisting" ], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
+ } );
jQuery.each( [ commentNode, textNode, attributeNode ], function( i, ele ) {
var $ele = jQuery( ele );
- $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting");
- assert.strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
- });
-});
+ $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" );
+ assert.strictEqual( ele[ "nonexisting" ], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
+ } );
+} );
QUnit.test( "val() after modification", function( assert ) {
assert.expect( 1 );
- document.getElementById("text1").value = "bla";
- assert.equal( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
-});
-
+ document.getElementById( "text1" ).value = "bla";
+ assert.equal( jQuery( "#text1" ).val(), "bla", "Check for modified value of input element" );
+} );
QUnit.test( "val()", function( assert ) {
assert.expect( 20 + ( jQuery.fn.serialize ? 6 : 0 ) );
var checks, $button;
- assert.equal( jQuery("#text1").val(), "Test", "Check for value of input element" );
+ assert.equal( jQuery( "#text1" ).val(), "Test", "Check for value of input element" );
+
// ticket #1714 this caused a JS error in IE
- assert.equal( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
- assert.ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
+ assert.equal( jQuery( "#first" ).val(), "", "Check a paragraph element to see if it has a value" );
+ assert.ok( jQuery( [] ).val() === undefined, "Check an empty jQuery object will return undefined from val" );
- assert.equal( jQuery("#select2").val(), "3", "Call val() on a single='single' select" );
+ assert.equal( jQuery( "#select2" ).val(), "3", "Call val() on a single='single' select" );
- assert.deepEqual( jQuery("#select3").val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
+ assert.deepEqual( jQuery( "#select3" ).val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
- assert.equal( jQuery("#option3c").val(), "2", "Call val() on a option element with value" );
+ assert.equal( jQuery( "#option3c" ).val(), "2", "Call val() on a option element with value" );
- assert.equal( jQuery("#option3a").val(), "", "Call val() on a option element with empty value" );
+ assert.equal( jQuery( "#option3a" ).val(), "", "Call val() on a option element with empty value" );
- assert.equal( jQuery("#option3e").val(), "no value", "Call val() on a option element with no value attribute" );
+ assert.equal( jQuery( "#option3e" ).val(), "no value", "Call val() on a option element with no value attribute" );
- assert.equal( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" );
+ assert.equal( jQuery( "#option3a" ).val(), "", "Call val() on a option element with no value attribute" );
- jQuery("#select3").val("");
- assert.deepEqual( jQuery("#select3").val(), [""], "Call val() on a multiple='multiple' select" );
+ jQuery( "#select3" ).val( "" );
+ assert.deepEqual( jQuery( "#select3" ).val(), [ "" ], "Call val() on a multiple='multiple' select" );
- assert.deepEqual( jQuery("#select4").val(), [], "Call val() on multiple='multiple' select with all disabled options" );
+ assert.deepEqual( jQuery( "#select4" ).val(), [], "Call val() on multiple='multiple' select with all disabled options" );
- jQuery("#select4 optgroup").add("#select4 > [disabled]").attr( "disabled", false );
- assert.deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" );
+ jQuery( "#select4 optgroup" ).add( "#select4 > [disabled]" ).attr( "disabled", false );
+ assert.deepEqual( jQuery( "#select4" ).val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" );
- jQuery("#select4").attr( "disabled", true );
- assert.deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" );
+ jQuery( "#select4" ).attr( "disabled", true );
+ assert.deepEqual( jQuery( "#select4" ).val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" );
- assert.equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
+ assert.equal( jQuery( "#select5" ).val(), "3", "Check value on ambiguous select." );
- jQuery("#select5").val( 1 );
- assert.equal( jQuery("#select5").val(), "1", "Check value on ambiguous select." );
+ jQuery( "#select5" ).val( 1 );
+ assert.equal( jQuery( "#select5" ).val(), "1", "Check value on ambiguous select." );
- jQuery("#select5").val( 3 );
- assert.equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
+ jQuery( "#select5" ).val( 3 );
+ assert.equal( jQuery( "#select5" ).val(), "3", "Check value on ambiguous select." );
assert.strictEqual(
- jQuery("<select name='select12584' id='select12584'><option value='1' disabled='disabled'>1</option></select>").val(),
+ jQuery( "<select name='select12584' id='select12584'><option value='1' disabled='disabled'>1</option></select>" ).val(),
null,
"Select-one with only option disabled (#12584)"
);
if ( jQuery.fn.serialize ) {
- checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
+ checks = jQuery( "<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>" ).appendTo( "#form" );
assert.deepEqual( checks.serialize(), "", "Get unchecked values." );
assert.equal( checks.eq( 3 ).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
- checks.val([ "2" ]);
+ checks.val( [ "2" ] );
assert.deepEqual( checks.serialize(), "test=2", "Get a single checked value." );
- checks.val([ "1", "" ]);
+ checks.val( [ "1", "" ] );
assert.deepEqual( checks.serialize(), "test=1&test=", "Get multiple checked values." );
- checks.val([ "", "2" ]);
+ checks.val( [ "", "2" ] );
assert.deepEqual( checks.serialize(), "test=2&test=", "Get multiple checked values." );
- checks.val([ "1", "on" ]);
+ checks.val( [ "1", "on" ] );
assert.deepEqual( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
checks.remove();
}
- $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
+ $button = jQuery( "<button value='foobar'>text</button>" ).insertAfter( "#button" );
assert.equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" );
- assert.equal( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" );
+ assert.equal( $button.val( "baz" ).html(), "text", "Setting the value does not change innerHTML" );
- assert.equal( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" );
-});
+ assert.equal( jQuery( "<option/>" ).val( "test" ).attr( "value" ), "test", "Setting value sets the value attribute" );
+} );
-QUnit.test("val() with non-matching values on dropdown list", function( assert ) {
+QUnit.test( "val() with non-matching values on dropdown list", function( assert ) {
assert.expect( 3 );
- jQuery("#select5").val( "" );
- assert.equal( jQuery("#select5").val(), null, "Non-matching set on select-one" );
+ jQuery( "#select5" ).val( "" );
+ assert.equal( jQuery( "#select5" ).val(), null, "Non-matching set on select-one" );
- var select6 = jQuery("<select multiple id=\"select6\"><option value=\"1\">A</option><option value=\"2\">B</option></select>").appendTo("#form");
- jQuery(select6).val( "nothing" );
- assert.equal( jQuery(select6).val(), null, "Non-matching set (single value) on select-multiple" );
+ var select6 = jQuery( "<select multiple id=\"select6\"><option value=\"1\">A</option><option value=\"2\">B</option></select>" ).appendTo( "#form" );
+ jQuery( select6 ).val( "nothing" );
+ assert.equal( jQuery( select6 ).val(), null, "Non-matching set (single value) on select-multiple" );
- jQuery(select6).val( ["nothing1", "nothing2"] );
- assert.equal( jQuery(select6).val(), null, "Non-matching set (array of values) on select-multiple" );
+ jQuery( select6 ).val( [ "nothing1", "nothing2" ] );
+ assert.equal( jQuery( select6 ).val(), null, "Non-matching set (array of values) on select-multiple" );
select6.remove();
-});
+} );
-if ( "value" in document.createElement("meter") &&
- "value" in document.createElement("progress") ) {
+if ( "value" in document.createElement( "meter" ) &&
+ "value" in document.createElement( "progress" ) ) {
QUnit.test( "val() respects numbers without exception (Bug #9319)", function( assert ) {
assert.expect( 4 );
- var $meter = jQuery("<meter min='0' max='10' value='5.6'></meter>"),
- $progress = jQuery("<progress max='10' value='1.5'></progress>");
+ var $meter = jQuery( "<meter min='0' max='10' value='5.6'></meter>" ),
+ $progress = jQuery( "<progress max='10' value='1.5'></progress>" );
try {
assert.equal( typeof $meter.val(), "number", "meter, returns a number and does not throw exception" );
@@ -920,47 +921,47 @@ if ( "value" in document.createElement("meter") &&
assert.equal( typeof $progress.val(), "number", "progress, returns a number and does not throw exception" );
assert.equal( $progress.val(), $progress[ 0 ].value, "progress, api matches host and does not throw exception" );
- } catch( e ) {}
+ } catch ( e ) {}
$meter.remove();
$progress.remove();
- });
+ } );
}
var testVal = function( valueObj, assert ) {
assert.expect( 9 );
- jQuery("#text1").val( valueObj("test") );
- assert.equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( "test" ) );
+ assert.equal( document.getElementById( "text1" ).value, "test", "Check for modified (via val(String)) value of input element" );
- jQuery("#text1").val( valueObj( undefined ) );
- assert.equal( document.getElementById("text1").value, "", "Check for modified (via val(undefined)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( undefined ) );
+ assert.equal( document.getElementById( "text1" ).value, "", "Check for modified (via val(undefined)) value of input element" );
- jQuery("#text1").val( valueObj( 67 ) );
- assert.equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( 67 ) );
+ assert.equal( document.getElementById( "text1" ).value, "67", "Check for modified (via val(Number)) value of input element" );
- jQuery("#text1").val( valueObj( null ) );
- assert.equal( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( null ) );
+ assert.equal( document.getElementById( "text1" ).value, "", "Check for modified (via val(null)) value of input element" );
var j,
$select = jQuery( "<select multiple><option value='1'/><option value='2'/></select>" ),
- $select1 = jQuery("#select1");
+ $select1 = jQuery( "#select1" );
- $select1.val( valueObj("3") );
+ $select1.val( valueObj( "3" ) );
assert.equal( $select1.val(), "3", "Check for modified (via val(String)) value of select element" );
$select1.val( valueObj( 2 ) );
assert.equal( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" );
- $select1.append("<option value='4'>four</option>");
+ $select1.append( "<option value='4'>four</option>" );
$select1.val( valueObj( 4 ) );
assert.equal( $select1.val(), "4", "Should be possible to set the val() to a newly created option" );
// using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
+ j = jQuery( "#nonnodes" ).contents();
j.val( valueObj( "asdf" ) );
assert.equal( j.val(), "asdf", "Check node,textnode,comment with val()" );
- j.removeAttr("value");
+ j.removeAttr( "value" );
$select.val( valueObj( [ "1", "2" ] ) );
assert.deepEqual( $select.val(), [ "1", "2" ], "Should set array of values" );
@@ -968,407 +969,406 @@ var testVal = function( valueObj, assert ) {
QUnit.test( "val(String/Number)", function( assert ) {
testVal( bareObj, assert );
-});
+} );
QUnit.test( "val(Function)", function( assert ) {
testVal( functionReturningObj, assert );
-});
+} );
QUnit.test( "val(Array of Numbers) (Bug #7123)", function( assert ) {
assert.expect( 4 );
- jQuery("#form").append("<input type='checkbox' name='arrayTest' value='1' /><input type='checkbox' name='arrayTest' value='2' /><input type='checkbox' name='arrayTest' value='3' checked='checked' /><input type='checkbox' name='arrayTest' value='4' />");
- var elements = jQuery("input[name=arrayTest]").val([ 1, 2 ]);
+ jQuery( "#form" ).append( "<input type='checkbox' name='arrayTest' value='1' /><input type='checkbox' name='arrayTest' value='2' /><input type='checkbox' name='arrayTest' value='3' checked='checked' /><input type='checkbox' name='arrayTest' value='4' />" );
+ var elements = jQuery( "input[name=arrayTest]" ).val( [ 1, 2 ] );
assert.ok( elements[ 0 ].checked, "First element was checked" );
assert.ok( elements[ 1 ].checked, "Second element was checked" );
assert.ok( !elements[ 2 ].checked, "Third element was unchecked" );
assert.ok( !elements[ 3 ].checked, "Fourth element remained unchecked" );
elements.remove();
-});
+} );
QUnit.test( "val(Function) with incoming value", function( assert ) {
assert.expect( 10 );
- var oldVal = jQuery("#text1").val();
+ var oldVal = jQuery( "#text1" ).val();
- jQuery("#text1").val(function( i, val ) {
+ jQuery( "#text1" ).val( function( i, val ) {
assert.equal( val, oldVal, "Make sure the incoming value is correct." );
return "test";
- });
+ } );
- assert.equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
+ assert.equal( document.getElementById( "text1" ).value, "test", "Check for modified (via val(String)) value of input element" );
- oldVal = jQuery("#text1").val();
+ oldVal = jQuery( "#text1" ).val();
- jQuery("#text1").val(function( i, val ) {
+ jQuery( "#text1" ).val( function( i, val ) {
assert.equal( val, oldVal, "Make sure the incoming value is correct." );
return 67;
- });
+ } );
- assert.equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
+ assert.equal( document.getElementById( "text1" ).value, "67", "Check for modified (via val(Number)) value of input element" );
- oldVal = jQuery("#select1").val();
+ oldVal = jQuery( "#select1" ).val();
- jQuery("#select1").val(function( i, val ) {
+ jQuery( "#select1" ).val( function( i, val ) {
assert.equal( val, oldVal, "Make sure the incoming value is correct." );
return "3";
- });
+ } );
- assert.equal( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
+ assert.equal( jQuery( "#select1" ).val(), "3", "Check for modified (via val(String)) value of select element" );
- oldVal = jQuery("#select1").val();
+ oldVal = jQuery( "#select1" ).val();
- jQuery("#select1").val(function( i, val ) {
+ jQuery( "#select1" ).val( function( i, val ) {
assert.equal( val, oldVal, "Make sure the incoming value is correct." );
return 2;
- });
+ } );
- assert.equal( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
+ assert.equal( jQuery( "#select1" ).val(), "2", "Check for modified (via val(Number)) value of select element" );
- jQuery("#select1").append("<option value='4'>four</option>");
+ jQuery( "#select1" ).append( "<option value='4'>four</option>" );
- oldVal = jQuery("#select1").val();
+ oldVal = jQuery( "#select1" ).val();
- jQuery("#select1").val(function( i, val ) {
+ jQuery( "#select1" ).val( function( i, val ) {
assert.equal( val, oldVal, "Make sure the incoming value is correct." );
return 4;
- });
+ } );
- assert.equal( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
-});
+ assert.equal( jQuery( "#select1" ).val(), "4", "Should be possible to set the val() to a newly created option" );
+} );
// testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only)
QUnit.test( "val(select) after form.reset() (Bug #2551)", function( assert ) {
assert.expect( 3 );
- jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#qunit-fixture");
+ jQuery( "<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>" ).appendTo( "#qunit-fixture" );
- jQuery("#kkk").val("gf");
+ jQuery( "#kkk" ).val( "gf" );
- document["kk"].reset();
+ document[ "kk" ].reset();
- assert.equal( jQuery("#kkk")[ 0 ].value, "cf", "Check value of select after form reset." );
- assert.equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );
+ assert.equal( jQuery( "#kkk" )[ 0 ].value, "cf", "Check value of select after form reset." );
+ assert.equal( jQuery( "#kkk" ).val(), "cf", "Check value of select after form reset." );
// re-verify the multi-select is not broken (after form.reset) by our fix for single-select
- assert.deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple='multiple' select" );
+ assert.deepEqual( jQuery( "#select3" ).val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
- jQuery("#kk").remove();
-});
+ jQuery( "#kk" ).remove();
+} );
var testAddClass = function( valueObj, assert ) {
assert.expect( 9 );
var pass, j, i,
- div = jQuery("#qunit-fixture div");
- div.addClass( valueObj("test") );
+ div = jQuery( "#qunit-fixture div" );
+ div.addClass( valueObj( "test" ) );
pass = true;
for ( i = 0; i < div.length; i++ ) {
- if ( !~div.get( i ).className.indexOf("test") ) {
+ if ( !~div.get( i ).className.indexOf( "test" ) ) {
pass = false;
}
}
assert.ok( pass, "Add Class" );
// using contents will get regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
- j.addClass( valueObj("asdf") );
- assert.ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
+ j = jQuery( "#nonnodes" ).contents();
+ j.addClass( valueObj( "asdf" ) );
+ assert.ok( j.hasClass( "asdf" ), "Check node,textnode,comment for addClass" );
- div = jQuery("<div/>");
+ div = jQuery( "<div/>" );
- div.addClass( valueObj("test") );
- assert.equal( div.attr("class"), "test", "Make sure there's no extra whitespace." );
+ div.addClass( valueObj( "test" ) );
+ assert.equal( div.attr( "class" ), "test", "Make sure there's no extra whitespace." );
div.attr( "class", " foo" );
- div.addClass( valueObj("test") );
- assert.equal( div.attr("class"), "foo test", "Make sure there's no extra whitespace." );
+ div.addClass( valueObj( "test" ) );
+ assert.equal( div.attr( "class" ), "foo test", "Make sure there's no extra whitespace." );
div.attr( "class", "foo" );
- div.addClass( valueObj("bar baz") );
- assert.equal( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." );
+ div.addClass( valueObj( "bar baz" ) );
+ assert.equal( div.attr( "class" ), "foo bar baz", "Make sure there isn't too much trimming." );
div.removeClass();
- div.addClass( valueObj("foo") ).addClass( valueObj("foo") );
- assert.equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." );
+ div.addClass( valueObj( "foo" ) ).addClass( valueObj( "foo" ) );
+ assert.equal( div.attr( "class" ), "foo", "Do not add the same class twice in separate calls." );
- div.addClass( valueObj("fo") );
- assert.equal( div.attr("class"), "foo fo", "Adding a similar class does not get interrupted." );
- div.removeClass().addClass("wrap2");
- assert.ok( div.addClass("wrap").hasClass("wrap"), "Can add similarly named classes");
+ div.addClass( valueObj( "fo" ) );
+ assert.equal( div.attr( "class" ), "foo fo", "Adding a similar class does not get interrupted." );
+ div.removeClass().addClass( "wrap2" );
+ assert.ok( div.addClass( "wrap" ).hasClass( "wrap" ), "Can add similarly named classes" );
div.removeClass();
- div.addClass( valueObj("bar bar") );
- assert.equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." );
+ div.addClass( valueObj( "bar bar" ) );
+ assert.equal( div.attr( "class" ), "bar", "Do not add the same class twice in the same call." );
};
QUnit.test( "addClass(String)", function( assert ) {
testAddClass( bareObj, assert );
-});
+} );
QUnit.test( "addClass(Function)", function( assert ) {
testAddClass( functionReturningObj, assert );
-});
+} );
QUnit.test( "addClass(Function) with incoming value", function( assert ) {
assert.expect( 52 );
var pass, i,
- div = jQuery("#qunit-fixture div"),
- old = div.map(function() {
- return jQuery(this).attr("class") || "";
- });
+ div = jQuery( "#qunit-fixture div" ),
+ old = div.map( function() {
+ return jQuery( this ).attr( "class" ) || "";
+ } );
- div.addClass(function( i, val ) {
+ div.addClass( function( i, val ) {
if ( this.id !== "_firebugConsole" ) {
assert.equal( val, old[ i ], "Make sure the incoming value is correct." );
return "test";
}
- });
+ } );
pass = true;
for ( i = 0; i < div.length; i++ ) {
- if ( div.get(i).className.indexOf("test") === -1 ) {
+ if ( div.get( i ).className.indexOf( "test" ) === -1 ) {
pass = false;
}
}
assert.ok( pass, "Add Class" );
-});
+} );
var testRemoveClass = function( valueObj, assert ) {
assert.expect( 8 );
- var $set = jQuery("#qunit-fixture div"),
- div = document.createElement("div");
+ var $set = jQuery( "#qunit-fixture div" ),
+ div = document.createElement( "div" );
- $set.addClass("test").removeClass( valueObj("test") );
+ $set.addClass( "test" ).removeClass( valueObj( "test" ) );
- assert.ok( !$set.is(".test"), "Remove Class" );
+ assert.ok( !$set.is( ".test" ), "Remove Class" );
- $set.addClass("test").addClass("foo").addClass("bar");
- $set.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") );
+ $set.addClass( "test" ).addClass( "foo" ).addClass( "bar" );
+ $set.removeClass( valueObj( "test" ) ).removeClass( valueObj( "bar" ) ).removeClass( valueObj( "foo" ) );
- assert.ok( !$set.is(".test,.bar,.foo"), "Remove multiple classes" );
+ assert.ok( !$set.is( ".test,.bar,.foo" ), "Remove multiple classes" );
// Make sure that a null value doesn't cause problems
- $set.eq( 0 ).addClass("expected").removeClass( valueObj( null ) );
- assert.ok( $set.eq( 0 ).is(".expected"), "Null value passed to removeClass" );
+ $set.eq( 0 ).addClass( "expected" ).removeClass( valueObj( null ) );
+ assert.ok( $set.eq( 0 ).is( ".expected" ), "Null value passed to removeClass" );
- $set.eq( 0 ).addClass("expected").removeClass( valueObj("") );
- assert.ok( $set.eq( 0 ).is(".expected"), "Empty string passed to removeClass" );
+ $set.eq( 0 ).addClass( "expected" ).removeClass( valueObj( "" ) );
+ assert.ok( $set.eq( 0 ).is( ".expected" ), "Empty string passed to removeClass" );
// using contents will get regular, text, and comment nodes
- $set = jQuery("#nonnodes").contents();
- $set.removeClass( valueObj("asdf") );
- assert.ok( !$set.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
-
+ $set = jQuery( "#nonnodes" ).contents();
+ $set.removeClass( valueObj( "asdf" ) );
+ assert.ok( !$set.hasClass( "asdf" ), "Check node,textnode,comment for removeClass" );
- jQuery( div ).removeClass( valueObj("foo") );
- assert.strictEqual( jQuery( div ).attr("class"), undefined, "removeClass doesn't create a class attribute" );
+ jQuery( div ).removeClass( valueObj( "foo" ) );
+ assert.strictEqual( jQuery( div ).attr( "class" ), undefined, "removeClass doesn't create a class attribute" );
div.className = " test foo ";
- jQuery( div ).removeClass( valueObj("foo") );
+ jQuery( div ).removeClass( valueObj( "foo" ) );
assert.equal( div.className, "test", "Make sure remaining className is trimmed." );
div.className = " test ";
- jQuery( div ).removeClass( valueObj("test") );
+ jQuery( div ).removeClass( valueObj( "test" ) );
assert.equal( div.className, "", "Make sure there is nothing left after everything is removed." );
};
QUnit.test( "removeClass(String) - simple", function( assert ) {
testRemoveClass( bareObj, assert );
-});
+} );
QUnit.test( "removeClass(Function) - simple", function( assert ) {
testRemoveClass( functionReturningObj, assert );
-});
+} );
QUnit.test( "removeClass(Function) with incoming value", function( assert ) {
assert.expect( 52 );
- var $divs = jQuery("#qunit-fixture div").addClass("test"), old = $divs.map(function() {
- return jQuery( this ).attr("class");
- });
+ var $divs = jQuery( "#qunit-fixture div" ).addClass( "test" ), old = $divs.map( function() {
+ return jQuery( this ).attr( "class" );
+ } );
- $divs.removeClass(function( i, val ) {
+ $divs.removeClass( function( i, val ) {
if ( this.id !== "_firebugConsole" ) {
assert.equal( val, old[ i ], "Make sure the incoming value is correct." );
return "test";
}
- });
+ } );
- assert.ok( !$divs.is(".test"), "Remove Class" );
-});
+ assert.ok( !$divs.is( ".test" ), "Remove Class" );
+} );
QUnit.test( "removeClass() removes duplicates", function( assert ) {
assert.expect( 1 );
- var $div = jQuery( jQuery.parseHTML("<div class='x x x'></div>") );
+ var $div = jQuery( jQuery.parseHTML( "<div class='x x x'></div>" ) );
- $div.removeClass("x");
+ $div.removeClass( "x" );
- assert.ok( !$div.hasClass("x"), "Element with multiple same classes does not escape the wrath of removeClass()" );
-});
+ assert.ok( !$div.hasClass( "x" ), "Element with multiple same classes does not escape the wrath of removeClass()" );
+} );
-QUnit.test("removeClass(undefined) is a no-op", function( assert ) {
+QUnit.test( "removeClass(undefined) is a no-op", function( assert ) {
assert.expect( 1 );
- var $div = jQuery("<div class='base second'></div>");
+ var $div = jQuery( "<div class='base second'></div>" );
$div.removeClass( undefined );
- assert.ok( $div.hasClass("base") && $div.hasClass("second"), "Element still has classes after removeClass(undefined)" );
-});
+ assert.ok( $div.hasClass( "base" ) && $div.hasClass( "second" ), "Element still has classes after removeClass(undefined)" );
+} );
var testToggleClass = function( valueObj, assert ) {
assert.expect( 17 );
- var e = jQuery("#firstp");
- assert.ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass( valueObj("test") );
- assert.ok( e.is(".test"), "Assert class present" );
- e.toggleClass( valueObj("test") );
- assert.ok( !e.is(".test"), "Assert class not present" );
+ var e = jQuery( "#firstp" );
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
+ e.toggleClass( valueObj( "test" ) );
+ assert.ok( e.is( ".test" ), "Assert class present" );
+ e.toggleClass( valueObj( "test" ) );
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
// class name with a boolean
- e.toggleClass( valueObj("test"), false );
- assert.ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass( valueObj("test"), true );
- assert.ok( e.is(".test"), "Assert class present" );
- e.toggleClass( valueObj("test"), false );
- assert.ok( !e.is(".test"), "Assert class not present" );
+ e.toggleClass( valueObj( "test" ), false );
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
+ e.toggleClass( valueObj( "test" ), true );
+ assert.ok( e.is( ".test" ), "Assert class present" );
+ e.toggleClass( valueObj( "test" ), false );
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
// multiple class names
- e.addClass("testA testB");
- assert.ok( e.is(".testA.testB"), "Assert 2 different classes present" );
- e.toggleClass( valueObj("testB testC") );
- assert.ok( (e.is(".testA.testC") && !e.is(".testB")), "Assert 1 class added, 1 class removed, and 1 class kept" );
- e.toggleClass( valueObj("testA testC") );
- assert.ok( (!e.is(".testA") && !e.is(".testB") && !e.is(".testC")), "Assert no class present" );
+ e.addClass( "testA testB" );
+ assert.ok( e.is( ".testA.testB" ), "Assert 2 different classes present" );
+ e.toggleClass( valueObj( "testB testC" ) );
+ assert.ok( ( e.is( ".testA.testC" ) && !e.is( ".testB" ) ), "Assert 1 class added, 1 class removed, and 1 class kept" );
+ e.toggleClass( valueObj( "testA testC" ) );
+ assert.ok( ( !e.is( ".testA" ) && !e.is( ".testB" ) && !e.is( ".testC" ) ), "Assert no class present" );
// toggleClass storage
e.toggleClass( true );
assert.ok( e[ 0 ].className === "", "Assert class is empty (data was empty)" );
- e.addClass("testD testE");
- assert.ok( e.is(".testD.testE"), "Assert class present" );
+ e.addClass( "testD testE" );
+ assert.ok( e.is( ".testD.testE" ), "Assert class present" );
e.toggleClass();
- assert.ok( !e.is(".testD.testE"), "Assert class not present" );
- assert.ok( jQuery._data(e[ 0 ], "__className__") === "testD testE", "Assert data was stored" );
+ assert.ok( !e.is( ".testD.testE" ), "Assert class not present" );
+ assert.ok( jQuery._data( e[ 0 ], "__className__" ) === "testD testE", "Assert data was stored" );
e.toggleClass();
- assert.ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
+ assert.ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" );
e.toggleClass( false );
- assert.ok( !e.is(".testD.testE"), "Assert class not present" );
+ assert.ok( !e.is( ".testD.testE" ), "Assert class not present" );
e.toggleClass( true );
- assert.ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
+ assert.ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" );
e.toggleClass();
e.toggleClass( false );
e.toggleClass();
- assert.ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
+ assert.ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" );
// Cleanup
- e.removeClass("testD");
+ e.removeClass( "testD" );
QUnit.expectJqData( this, e[ 0 ], "__className__" );
};
QUnit.test( "toggleClass(String|boolean|undefined[, boolean])", function( assert ) {
testToggleClass( bareObj, assert );
-});
+} );
QUnit.test( "toggleClass(Function[, boolean])", function( assert ) {
testToggleClass( functionReturningObj, assert );
-});
+} );
QUnit.test( "toggleClass(Function[, boolean]) with incoming value", function( assert ) {
assert.expect( 14 );
- var e = jQuery("#firstp"),
- old = e.attr("class") || "";
+ var e = jQuery( "#firstp" ),
+ old = e.attr( "class" ) || "";
- assert.ok( !e.is(".test"), "Assert class not present" );
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
- e.toggleClass(function( i, val ) {
+ e.toggleClass( function( i, val ) {
assert.equal( old, val, "Make sure the incoming value is correct." );
return "test";
- });
- assert.ok( e.is(".test"), "Assert class present" );
+ } );
+ assert.ok( e.is( ".test" ), "Assert class present" );
- old = e.attr("class");
+ old = e.attr( "class" );
- e.toggleClass(function( i, val ) {
+ e.toggleClass( function( i, val ) {
assert.equal( old, val, "Make sure the incoming value is correct." );
return "test";
- });
- assert.ok( !e.is(".test"), "Assert class not present" );
+ } );
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
- old = e.attr("class") || "";
+ old = e.attr( "class" ) || "";
// class name with a boolean
- e.toggleClass(function( i, val, state ) {
+ e.toggleClass( function( i, val, state ) {
assert.equal( old, val, "Make sure the incoming value is correct." );
assert.equal( state, false, "Make sure that the state is passed in." );
return "test";
}, false );
- assert.ok( !e.is(".test"), "Assert class not present" );
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
- old = e.attr("class") || "";
+ old = e.attr( "class" ) || "";
- e.toggleClass(function( i, val, state ) {
+ e.toggleClass( function( i, val, state ) {
assert.equal( old, val, "Make sure the incoming value is correct." );
assert.equal( state, true, "Make sure that the state is passed in." );
return "test";
}, true );
- assert.ok( e.is(".test"), "Assert class present" );
+ assert.ok( e.is( ".test" ), "Assert class present" );
- old = e.attr("class");
+ old = e.attr( "class" );
- e.toggleClass(function( i, val, state ) {
+ e.toggleClass( function( i, val, state ) {
assert.equal( old, val, "Make sure the incoming value is correct." );
assert.equal( state, false, "Make sure that the state is passed in." );
return "test";
}, false );
- assert.ok( !e.is(".test"), "Assert class not present" );
-});
+ assert.ok( !e.is( ".test" ), "Assert class not present" );
+} );
QUnit.test( "addClass, removeClass, hasClass", function( assert ) {
assert.expect( 17 );
- var jq = jQuery("<p>Hi</p>"), x = jq[ 0 ];
+ var jq = jQuery( "<p>Hi</p>" ), x = jq[ 0 ];
- jq.addClass("hi");
+ jq.addClass( "hi" );
assert.equal( x.className, "hi", "Check single added class" );
- jq.addClass("foo bar");
+ jq.addClass( "foo bar" );
assert.equal( x.className, "hi foo bar", "Check more added classes" );
jq.removeClass();
assert.equal( x.className, "", "Remove all classes" );
- jq.addClass("hi foo bar");
- jq.removeClass("foo");
+ jq.addClass( "hi foo bar" );
+ jq.removeClass( "foo" );
assert.equal( x.className, "hi bar", "Check removal of one class" );
- assert.ok( jq.hasClass("hi"), "Check has1" );
- assert.ok( jq.hasClass("bar"), "Check has2" );
-
- jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
-
- assert.ok( jq.hasClass("class1"), "Check hasClass with line feed" );
- assert.ok( jq.is(".class1"), "Check is with line feed" );
- assert.ok( jq.hasClass("class2"), "Check hasClass with tab" );
- assert.ok( jq.is(".class2"), "Check is with tab" );
- assert.ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
- assert.ok( jq.hasClass("class4"), "Check hasClass with carriage return" );
- assert.ok( jq.is(".class4"), "Check is with carriage return" );
-
- jq.removeClass("class2");
- assert.ok( jq.hasClass("class2") === false, "Check the class has been properly removed" );
- jq.removeClass("cla");
- assert.ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
- jq.removeClass("cla.ss3");
- assert.ok( jq.hasClass("cla.ss3") === false, "Check the dotted class has been removed" );
- jq.removeClass("class4");
- assert.ok( jq.hasClass("class4") === false, "Check the class has been properly removed" );
-});
+ assert.ok( jq.hasClass( "hi" ), "Check has1" );
+ assert.ok( jq.hasClass( "bar" ), "Check has2" );
+
+ jq = jQuery( "<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>" );
+
+ assert.ok( jq.hasClass( "class1" ), "Check hasClass with line feed" );
+ assert.ok( jq.is( ".class1" ), "Check is with line feed" );
+ assert.ok( jq.hasClass( "class2" ), "Check hasClass with tab" );
+ assert.ok( jq.is( ".class2" ), "Check is with tab" );
+ assert.ok( jq.hasClass( "cla.ss3" ), "Check hasClass with dot" );
+ assert.ok( jq.hasClass( "class4" ), "Check hasClass with carriage return" );
+ assert.ok( jq.is( ".class4" ), "Check is with carriage return" );
+
+ jq.removeClass( "class2" );
+ assert.ok( jq.hasClass( "class2" ) === false, "Check the class has been properly removed" );
+ jq.removeClass( "cla" );
+ assert.ok( jq.hasClass( "cla.ss3" ), "Check the dotted class has not been removed" );
+ jq.removeClass( "cla.ss3" );
+ assert.ok( jq.hasClass( "cla.ss3" ) === false, "Check the dotted class has been removed" );
+ jq.removeClass( "class4" );
+ assert.ok( jq.hasClass( "class4" ) === false, "Check the class has been properly removed" );
+} );
QUnit.test( "addClass, removeClass, hasClass on many elements", function( assert ) {
assert.expect( 19 );
@@ -1411,17 +1411,17 @@ QUnit.test( "addClass, removeClass, hasClass on many elements", function( assert
assert.ok( !jQuery( "<p class='hi0'>p0</p><p class='hi1'>p1</p><p class='hi2'>p2</p>" ).hasClass( "hi" ),
"Did not find a class when not present" );
-});
+} );
QUnit.test( "contents().hasClass() returns correct values", function( assert ) {
assert.expect( 2 );
- var $div = jQuery("<div><span class='foo'></span><!-- comment -->text</div>"),
+ var $div = jQuery( "<div><span class='foo'></span><!-- comment -->text</div>" ),
$contents = $div.contents();
- assert.ok( $contents.hasClass("foo"), "Found 'foo' in $contents" );
- assert.ok( !$contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" );
-});
+ assert.ok( $contents.hasClass( "foo" ), "Found 'foo' in $contents" );
+ assert.ok( !$contents.hasClass( "undefined" ), "Did not find 'undefined' in $contents (correctly)" );
+} );
QUnit.test( "hasClass correctly interprets non-space separators (#13835)", function( assert ) {
assert.expect( 4 );
@@ -1435,23 +1435,23 @@ QUnit.test( "hasClass correctly interprets non-space separators (#13835)", funct
},
classes = jQuery.map( map, function( separator, label ) {
return " " + separator + label + separator + " ";
- }),
+ } ),
$div = jQuery( "<div class='" + classes + "'></div>" );
jQuery.each( map, function( label ) {
assert.ok( $div.hasClass( label ), label.replace( "-", " " ) );
- });
-});
+ } );
+} );
QUnit.test( "coords returns correct values in IE6/IE7, see #10828", function( assert ) {
assert.expect( 1 );
var area,
- map = jQuery("<map />");
+ map = jQuery( "<map />" );
- area = map.html("<area shape='rect' coords='0,0,0,0' href='#' alt='a' />").find("area");
- assert.equal( area.attr("coords"), "0,0,0,0", "did not retrieve coords correctly" );
-});
+ area = map.html( "<area shape='rect' coords='0,0,0,0' href='#' alt='a' />" ).find( "area" );
+ assert.equal( area.attr( "coords" ), "0,0,0,0", "did not retrieve coords correctly" );
+} );
QUnit.test( "should not throw at $(option).val() (#14686)", function( assert ) {
assert.expect( 1 );
@@ -1462,12 +1462,12 @@ QUnit.test( "should not throw at $(option).val() (#14686)", function( assert ) {
} catch ( _ ) {
assert.ok( false );
}
-});
+} );
QUnit.test( "option value not trimmed when setting via parent select", function( assert ) {
assert.expect( 1 );
assert.equal( jQuery( "<select><option> 2</option></select>" ).val( "2" ).val(), "2" );
-});
+} );
QUnit.test( "Insignificant white space returned for $(option).val() (#14858)", function( assert ) {
expect ( 3 );
@@ -1480,7 +1480,7 @@ QUnit.test( "Insignificant white space returned for $(option).val() (#14858)", f
val = jQuery( "<option> test </option>" ).val();
assert.equal( val.length, 4, "insignificant white-space returned for value" );
-});
+} );
QUnit.test( "SVG class manipulation (gh-2199)", function( assert ) {
assert.expect( 12 );
@@ -1489,7 +1489,7 @@ QUnit.test( "SVG class manipulation (gh-2199)", function( assert ) {
return document.createElementNS( "http://www.w3.org/2000/svg", nodeName );
}
- jQuery.each([
+ jQuery.each( [
"svg",
"rect",
"g"
@@ -1507,5 +1507,5 @@ QUnit.test( "SVG class manipulation (gh-2199)", function( assert ) {
elem.toggleClass( "awesome" );
assert.ok( !elem.hasClass( "awesome" ), "SVG element (" + this + ") toggles the class off" );
- });
-});
+ } );
+} );
diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js
index af33174d4..c6c379ded 100644
--- a/test/unit/callbacks.js
+++ b/test/unit/callbacks.js
@@ -1,8 +1,8 @@
QUnit.module( "callbacks", {
teardown: moduleTeardown
-});
+} );
-(function() {
+( function() {
var output,
addToOutput = function( string ) {
@@ -10,9 +10,9 @@ var output,
output += string;
};
},
- outputA = addToOutput("A"),
- outputB = addToOutput("B"),
- outputC = addToOutput("C"),
+ outputA = addToOutput( "A" ),
+ outputB = addToOutput( "B" ),
+ outputC = addToOutput( "C" ),
tests = {
"": "XABC X XABCABCC X XBB X XABA X XX",
"once": "XABC X X X X X XABA X XX",
@@ -54,11 +54,11 @@ jQuery.each( tests, function( strFlags, resultString ) {
if ( this.length ) {
objectFlags[ this ] = true;
}
- });
+ } );
jQuery.each( filters, function( filterLabel ) {
- jQuery.each({
+ jQuery.each( {
"string": strFlags,
"object": objectFlags
}, function( flagsTypes, flags ) {
@@ -76,20 +76,20 @@ jQuery.each( tests, function( strFlags, resultString ) {
assert.strictEqual( cblist.locked(), false, ".locked() initially false" );
assert.strictEqual( cblist.disabled(), false, ".disabled() initially false" );
assert.strictEqual( cblist.fired(), false, ".fired() initially false" );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
assert.strictEqual( cblist.fired(), false, ".fired() still false after .add" );
cblist.fire( "A" );
assert.strictEqual( output, "XA", "Basic binding and firing" );
assert.strictEqual( cblist.fired(), true, ".fired() detects firing" );
output = "X";
cblist.disable();
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
assert.strictEqual( output, "X", "Adding a callback after disabling" );
- cblist.fire("A");
+ cblist.fire( "A" );
assert.strictEqual( output, "X", "Firing after disabling" );
assert.strictEqual( cblist.disabled(), true, ".disabled() becomes true" );
assert.strictEqual( cblist.locked(), true, "disabling locks" );
@@ -113,20 +113,20 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Basic binding and firing (context, arguments)
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function() {
+ cblist.add( function() {
assert.equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" );
- });
+ } );
cblist.fireWith( window, [ "A", "B" ] );
assert.strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
// fireWith with no arguments
output = "";
cblist = jQuery.Callbacks( flags );
- cblist.add(function() {
+ cblist.add( function() {
assert.equal( this, window, "fireWith with no arguments (context is window)" );
assert.strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
- });
+ } );
cblist.fireWith();
// Basic binding, removing and firing
@@ -150,17 +150,17 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Locking
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
cblist.lock();
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
- cblist.fire("A");
- cblist.add(function( str ) {
+ } );
+ cblist.fire( "A" );
+ cblist.add( function( str ) {
output += str;
- });
+ } );
assert.strictEqual( output, "X", "Lock early" );
assert.strictEqual( cblist.locked(), true, "Locking reflected in accessor" );
@@ -168,16 +168,16 @@ jQuery.each( tests, function( strFlags, resultString ) {
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( cblist.lock );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
cblist.fire( "A" );
assert.strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" );
// Ordering
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function() {
+ cblist.add( function() {
cblist.add( outputC );
outputA();
}, outputB );
@@ -186,7 +186,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Add and fire again
output = "X";
- cblist.add(function() {
+ cblist.add( function() {
cblist.add( outputC );
outputA();
}, outputB );
@@ -199,23 +199,23 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Multiple fire
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
- cblist.fire("A");
+ } );
+ cblist.fire( "A" );
assert.strictEqual( output, "XA", "Multiple fire (first fire)" );
output = "X";
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
assert.strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
output = "X";
- cblist.fire("B");
+ cblist.fire( "B" );
assert.strictEqual( output, results.shift(), "Multiple fire (second fire)" );
output = "X";
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
assert.strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
// Return false
@@ -244,12 +244,12 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add( handler );
cblist.fire();
assert.strictEqual( output, results.shift(), "No callback iteration" );
- });
- });
- });
-});
+ } );
+ } );
+ } );
+} );
-})();
+} )();
QUnit.test( "jQuery.Callbacks( options ) - options are copied", function( assert ) {
@@ -263,25 +263,25 @@ QUnit.test( "jQuery.Callbacks( options ) - options are copied", function( assert
fn = function() {
assert.ok( !( count++ ), "called once" );
};
- options["unique"] = false;
+ options[ "unique" ] = false;
cb.add( fn, fn );
cb.fire();
-});
+} );
QUnit.test( "jQuery.Callbacks.fireWith - arguments are copied", function( assert ) {
assert.expect( 1 );
- var cb = jQuery.Callbacks("memory"),
- args = ["hello"];
+ var cb = jQuery.Callbacks( "memory" ),
+ args = [ "hello" ];
cb.fireWith( null, args );
args[ 0 ] = "world";
- cb.add(function( hello ) {
+ cb.add( function( hello ) {
assert.strictEqual( hello, "hello", "arguments are copied internally" );
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Callbacks.remove - should remove all instances", function( assert ) {
@@ -295,8 +295,8 @@ QUnit.test( "jQuery.Callbacks.remove - should remove all instances", function( a
cb.add( fn, fn, function() {
assert.ok( true, "end of test" );
- }).remove( fn ).fire();
-});
+ } ).remove( fn ).fire();
+} );
QUnit.test( "jQuery.Callbacks.has", function( assert ) {
@@ -312,36 +312,36 @@ QUnit.test( "jQuery.Callbacks.has", function( assert ) {
function getC() {
return "C";
}
- cb.add(getA, getB, getC);
+ cb.add( getA, getB, getC );
assert.strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" );
- assert.strictEqual( cb.has(getA), true, "Check if a specific callback function is in the Callbacks list" );
+ assert.strictEqual( cb.has( getA ), true, "Check if a specific callback function is in the Callbacks list" );
- cb.remove(getB);
- assert.strictEqual( cb.has(getB), false, "Remove a specific callback function and make sure its no longer there" );
- assert.strictEqual( cb.has(getA), true, "Remove a specific callback function and make sure other callback function is still there" );
+ cb.remove( getB );
+ assert.strictEqual( cb.has( getB ), false, "Remove a specific callback function and make sure its no longer there" );
+ assert.strictEqual( cb.has( getA ), true, "Remove a specific callback function and make sure other callback function is still there" );
cb.empty();
assert.strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" );
- assert.strictEqual( cb.has(getA), false, "Check for a specific function in an empty() list" );
+ assert.strictEqual( cb.has( getA ), false, "Check for a specific function in an empty() list" );
- cb.add(getA, getB, function(){
+ cb.add( getA, getB, function() {
assert.strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" );
- assert.strictEqual( cb.has(getA), true, "Check if list has a specific callback from within a callback function" );
- }).fire();
+ assert.strictEqual( cb.has( getA ), true, "Check if list has a specific callback from within a callback function" );
+ } ).fire();
assert.strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" );
cb.disable();
assert.strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" );
- assert.strictEqual( cb.has(getA), false, "Check for a specific function in a disabled() list" );
+ assert.strictEqual( cb.has( getA ), false, "Check for a specific function in a disabled() list" );
- cb = jQuery.Callbacks("unique");
- cb.add(getA);
- cb.add(getA);
+ cb = jQuery.Callbacks( "unique" );
+ cb.add( getA );
+ cb.add( getA );
assert.strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" );
cb.lock();
assert.strictEqual( cb.has(), false, "locked() list is empty and returns false" );
-});
+} );
QUnit.test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function( assert ) {
@@ -350,7 +350,7 @@ QUnit.test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow
jQuery.Callbacks().add( "hello world" );
assert.ok( true, "no stack overflow" );
-});
+} );
QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function( assert ) {
@@ -365,4 +365,4 @@ QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", fun
cb.add( shot );
cb.fire();
assert.ok( !fired, "Disabled callback function didn't fire" );
-});
+} );
diff --git a/test/unit/core.js b/test/unit/core.js
index 1a6cf5e3c..d9ec725c9 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1,7 +1,7 @@
-QUnit.module("core", { teardown: moduleTeardown });
+QUnit.module( "core", { teardown: moduleTeardown } );
-QUnit.test("Basic requirements", function( assert ) {
- assert.expect(7);
+QUnit.test( "Basic requirements", function( assert ) {
+ assert.expect( 7 );
assert.ok( Array.prototype.push, "Array.push()" );
assert.ok( Function.prototype.apply, "Function.apply()" );
assert.ok( document.getElementById, "getElementById" );
@@ -9,15 +9,15 @@ QUnit.test("Basic requirements", function( assert ) {
assert.ok( RegExp, "RegExp" );
assert.ok( jQuery, "jQuery" );
assert.ok( $, "$" );
-});
+} );
-QUnit.test("jQuery()", function( assert ) {
+QUnit.test( "jQuery()", function( assert ) {
var elem, i,
- obj = jQuery("div"),
- code = jQuery("<code/>"),
- img = jQuery("<img/>"),
- div = jQuery("<div/><hr/><code/><b/>"),
+ obj = jQuery( "div" ),
+ code = jQuery( "<code/>" ),
+ img = jQuery( "<img/>" ),
+ div = jQuery( "<div/><hr/><code/><b/>" ),
exec = false,
expected = 23,
attrObj = {
@@ -30,19 +30,19 @@ QUnit.test("jQuery()", function( assert ) {
// few here but beware of modular builds where these methods may be excluded.
if ( jQuery.fn.click ) {
expected++;
- attrObj["click"] = function() { ok( exec, "Click executed." ); };
+ attrObj[ "click" ] = function() { ok( exec, "Click executed." ); };
}
if ( jQuery.fn.width ) {
expected++;
- attrObj["width"] = 10;
+ attrObj[ "width" ] = 10;
}
if ( jQuery.fn.offset ) {
expected++;
- attrObj["offset"] = { "top": 1, "left": 1 };
+ attrObj[ "offset" ] = { "top": 1, "left": 1 };
}
if ( jQuery.fn.css ) {
expected += 2;
- attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
+ attrObj[ "css" ] = { "paddingLeft": 1, "paddingRight": 1 };
}
if ( jQuery.fn.attr ) {
expected++;
@@ -53,10 +53,10 @@ QUnit.test("jQuery()", function( assert ) {
// Basic constructor's behavior
assert.equal( jQuery().length, 0, "jQuery() === jQuery([])" );
- assert.equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
- assert.equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
- assert.equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
- assert.deepEqual( jQuery(obj).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" );
+ assert.equal( jQuery( undefined ).length, 0, "jQuery(undefined) === jQuery([])" );
+ assert.equal( jQuery( null ).length, 0, "jQuery(null) === jQuery([])" );
+ assert.equal( jQuery( "" ).length, 0, "jQuery('') === jQuery([])" );
+ assert.deepEqual( jQuery( obj ).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" );
// Invalid #id goes to Sizzle which will throw an error (gh-1682)
try {
@@ -66,7 +66,7 @@ QUnit.test("jQuery()", function( assert ) {
}
// can actually yield more than one, when iframes are included, the window is an array as well
- assert.equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
+ assert.equal( jQuery( window ).length, 1, "Correct number of elements generated for jQuery(window)" );
/*
// disabled since this test was doing nothing. i tried to fix it but i'm not sure
@@ -95,84 +95,84 @@ QUnit.test("jQuery()", function( assert ) {
assert.equal( div.length, 4, "Correct number of elements generated for div hr code b" );
assert.equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
- assert.equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
+ assert.equal( jQuery( [ 1,2,3 ] ).get( 1 ), 2, "Test passing an array to the factory" );
- assert.equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
+ assert.equal( jQuery( document.body ).get( 0 ), jQuery( "body" ).get( 0 ), "Test passing an html node to the factory" );
- elem = jQuery(" <em>hello</em>")[0];
+ elem = jQuery( " <em>hello</em>" )[ 0 ];
assert.equal( elem.nodeName.toLowerCase(), "em", "leading space" );
- elem = jQuery("\n\n<em>world</em>")[0];
+ elem = jQuery( "\n\n<em>world</em>" )[ 0 ];
assert.equal( elem.nodeName.toLowerCase(), "em", "leading newlines" );
- elem = jQuery("<div/>", attrObj );
+ elem = jQuery( "<div/>", attrObj );
if ( jQuery.fn.width ) {
- assert.equal( elem[0].style.width, "10px", "jQuery() quick setter width");
+ assert.equal( elem[ 0 ].style.width, "10px", "jQuery() quick setter width" );
}
if ( jQuery.fn.offset ) {
- assert.equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
+ assert.equal( elem[ 0 ].style.top, "1px", "jQuery() quick setter offset" );
}
if ( jQuery.fn.css ) {
- assert.equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
- assert.equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
+ assert.equal( elem[ 0 ].style.paddingLeft, "1px", "jQuery quick setter css" );
+ assert.equal( elem[ 0 ].style.paddingRight, "1px", "jQuery quick setter css" );
}
if ( jQuery.fn.attr ) {
- assert.equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
+ assert.equal( elem[ 0 ].getAttribute( "desired" ), "very", "jQuery quick setter attr" );
}
- assert.equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
- assert.equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
- assert.equal( elem[0].className, "test2", "jQuery() quick setter class");
- assert.equal( elem[0].id, "test3", "jQuery() quick setter id");
+ assert.equal( elem[ 0 ].childNodes.length, 1, "jQuery quick setter text" );
+ assert.equal( elem[ 0 ].firstChild.nodeValue, "test", "jQuery quick setter text" );
+ assert.equal( elem[ 0 ].className, "test2", "jQuery() quick setter class" );
+ assert.equal( elem[ 0 ].id, "test3", "jQuery() quick setter id" );
exec = true;
- elem.trigger("click");
+ elem.trigger( "click" );
// manually clean up detached elements
elem.remove();
for ( i = 0; i < 3; ++i ) {
- elem = jQuery("<input type='text' value='TEST' />");
+ elem = jQuery( "<input type='text' value='TEST' />" );
}
- assert.equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
+ assert.equal( elem[ 0 ].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
elem = jQuery( "<input type='hidden'>", {} );
assert.strictEqual( elem[ 0 ].ownerDocument, document,
"Empty attributes object is not interpreted as a document (trac-8950)" );
-});
+} );
-QUnit.test("jQuery(selector, context)", function( assert ) {
- assert.expect(3);
- assert.deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
- assert.deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
- assert.deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
-});
+QUnit.test( "jQuery(selector, context)", function( assert ) {
+ assert.expect( 3 );
+ assert.deepEqual( jQuery( "div p", "#qunit-fixture" ).get(), q( "sndp", "en", "sap" ), "Basic selector with string as context" );
+ assert.deepEqual( jQuery( "div p", q( "qunit-fixture" )[ 0 ] ).get(), q( "sndp", "en", "sap" ), "Basic selector with element as context" );
+ assert.deepEqual( jQuery( "div p", jQuery( "#qunit-fixture" ) ).get(), q( "sndp", "en", "sap" ), "Basic selector with jQuery object as context" );
+} );
QUnit.test( "globalEval", function( assert ) {
assert.expect( 3 );
- Globals.register("globalEvalTest");
+ Globals.register( "globalEvalTest" );
- jQuery.globalEval("globalEvalTest = 1;");
+ jQuery.globalEval( "globalEvalTest = 1;" );
assert.equal( window.globalEvalTest, 1, "Test variable assignments are global" );
- jQuery.globalEval("var globalEvalTest = 2;");
+ jQuery.globalEval( "var globalEvalTest = 2;" );
assert.equal( window.globalEvalTest, 2, "Test variable declarations are global" );
- jQuery.globalEval("this.globalEvalTest = 3;");
+ jQuery.globalEval( "this.globalEvalTest = 3;" );
assert.equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
-});
+} );
QUnit.test( "globalEval with 'use strict'", function( assert ) {
assert.expect( 1 );
- Globals.register("strictEvalTest");
+ Globals.register( "strictEvalTest" );
- jQuery.globalEval("'use strict'; var strictEvalTest = 1;");
+ jQuery.globalEval( "'use strict'; var strictEvalTest = 1;" );
assert.equal( window.strictEvalTest, 1, "Test variable declarations are global (strict mode)" );
-});
+} );
QUnit.test( "globalEval execution after script injection (#7862)", function( assert ) {
assert.expect( 1 );
@@ -185,41 +185,41 @@ QUnit.test( "globalEval execution after script injection (#7862)", function( ass
now = jQuery.now();
document.body.appendChild( script );
- jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";");
+ jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";" );
assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
-});
+} );
// This is not run in AMD mode
if ( jQuery.noConflict ) {
- QUnit.test("noConflict", function( assert ) {
- assert.expect(7);
+ QUnit.test( "noConflict", function( assert ) {
+ assert.expect( 7 );
var $$ = jQuery;
assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
- assert.strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
- assert.strictEqual( window["$"], original$, "Make sure $ was reverted." );
+ assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." );
+ assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
jQuery = $ = $$;
- assert.strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
- assert.strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
- assert.strictEqual( window["$"], original$, "Make sure $ was reverted." );
- assert.ok( $$().pushStack([]), "Make sure that jQuery still works." );
+ assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" );
+ assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." );
+ assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
+ assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." );
- window["jQuery"] = jQuery = $$;
- });
+ window[ "jQuery" ] = jQuery = $$;
+ } );
}
-QUnit.test("trim", function( assert ) {
- assert.expect(13);
+QUnit.test( "trim", function( assert ) {
+ assert.expect( 13 );
- var nbsp = String.fromCharCode(160);
+ var nbsp = String.fromCharCode( 160 );
- assert.equal( jQuery.trim("hello "), "hello", "trailing space" );
- assert.equal( jQuery.trim(" hello"), "hello", "leading space" );
- assert.equal( jQuery.trim(" hello "), "hello", "space on both sides" );
- assert.equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", "&nbsp;" );
+ assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" );
+ assert.equal( jQuery.trim( " hello" ), "hello", "leading space" );
+ assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
+ assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", "&nbsp;" );
assert.equal( jQuery.trim(), "", "Nothing in." );
assert.equal( jQuery.trim( undefined ), "", "Undefined" );
@@ -227,88 +227,88 @@ QUnit.test("trim", function( assert ) {
assert.equal( jQuery.trim( 5 ), "5", "Number" );
assert.equal( jQuery.trim( false ), "false", "Boolean" );
- assert.equal( jQuery.trim(" "), "", "space should be trimmed" );
- assert.equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" );
- assert.equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" );
- assert.equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" );
-});
+ assert.equal( jQuery.trim( " " ), "", "space should be trimmed" );
+ assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
+ assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
+ assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
+} );
-QUnit.test("type", function( assert ) {
+QUnit.test( "type", function( assert ) {
assert.expect( 28 );
- assert.equal( jQuery.type(null), "null", "null" );
- assert.equal( jQuery.type(undefined), "undefined", "undefined" );
- assert.equal( jQuery.type(true), "boolean", "Boolean" );
- assert.equal( jQuery.type(false), "boolean", "Boolean" );
- assert.equal( jQuery.type(Boolean(true)), "boolean", "Boolean" );
- assert.equal( jQuery.type(0), "number", "Number" );
- assert.equal( jQuery.type(1), "number", "Number" );
- assert.equal( jQuery.type(Number(1)), "number", "Number" );
- assert.equal( jQuery.type(""), "string", "String" );
- assert.equal( jQuery.type("a"), "string", "String" );
- assert.equal( jQuery.type(String("a")), "string", "String" );
- assert.equal( jQuery.type({}), "object", "Object" );
- assert.equal( jQuery.type(/foo/), "regexp", "RegExp" );
- assert.equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" );
- assert.equal( jQuery.type([1]), "array", "Array" );
- assert.equal( jQuery.type(new Date()), "date", "Date" );
- assert.equal( jQuery.type(new Function("return;")), "function", "Function" );
- assert.equal( jQuery.type(function(){}), "function", "Function" );
- assert.equal( jQuery.type(new Error()), "error", "Error" );
- assert.equal( jQuery.type(window), "object", "Window" );
- assert.equal( jQuery.type(document), "object", "Document" );
- assert.equal( jQuery.type(document.body), "object", "Element" );
- assert.equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
- assert.equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
+ assert.equal( jQuery.type( null ), "null", "null" );
+ assert.equal( jQuery.type( undefined ), "undefined", "undefined" );
+ assert.equal( jQuery.type( true ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( false ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( Boolean( true ) ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( 0 ), "number", "Number" );
+ assert.equal( jQuery.type( 1 ), "number", "Number" );
+ assert.equal( jQuery.type( Number( 1 ) ), "number", "Number" );
+ assert.equal( jQuery.type( "" ), "string", "String" );
+ assert.equal( jQuery.type( "a" ), "string", "String" );
+ assert.equal( jQuery.type( String( "a" ) ), "string", "String" );
+ assert.equal( jQuery.type( {} ), "object", "Object" );
+ assert.equal( jQuery.type( /foo/ ), "regexp", "RegExp" );
+ assert.equal( jQuery.type( new RegExp( "asdf" ) ), "regexp", "RegExp" );
+ assert.equal( jQuery.type( [ 1 ] ), "array", "Array" );
+ assert.equal( jQuery.type( new Date() ), "date", "Date" );
+ assert.equal( jQuery.type( new Function( "return;" ) ), "function", "Function" );
+ assert.equal( jQuery.type( function() {} ), "function", "Function" );
+ assert.equal( jQuery.type( new Error() ), "error", "Error" );
+ assert.equal( jQuery.type( window ), "object", "Window" );
+ assert.equal( jQuery.type( document ), "object", "Document" );
+ assert.equal( jQuery.type( document.body ), "object", "Element" );
+ assert.equal( jQuery.type( document.createTextNode( "foo" ) ), "object", "TextNode" );
+ assert.equal( jQuery.type( document.getElementsByTagName( "*" ) ), "object", "NodeList" );
// Avoid Lint complaints
var MyString = String,
MyNumber = Number,
MyBoolean = Boolean,
MyObject = Object;
- assert.equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" );
- assert.equal( jQuery.type(new MyNumber(1)), "number", "Number" );
- assert.equal( jQuery.type(new MyString("a")), "string", "String" );
- assert.equal( jQuery.type(new MyObject()), "object", "Object" );
-});
+ assert.equal( jQuery.type( new MyBoolean( true ) ), "boolean", "Boolean" );
+ assert.equal( jQuery.type( new MyNumber( 1 ) ), "number", "Number" );
+ assert.equal( jQuery.type( new MyString( "a" ) ), "string", "String" );
+ assert.equal( jQuery.type( new MyObject() ), "object", "Object" );
+} );
-QUnit.asyncTest("isPlainObject", function( assert ) {
- assert.expect(15);
+QUnit.asyncTest( "isPlainObject", function( assert ) {
+ assert.expect( 15 );
var pass, iframe, doc,
fn = function() {};
// The use case that we want to match
- assert.ok( jQuery.isPlainObject({}), "{}" );
+ assert.ok( jQuery.isPlainObject( {} ), "{}" );
// Not objects shouldn't be matched
- assert.ok( !jQuery.isPlainObject(""), "string" );
- assert.ok( !jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number" );
- assert.ok( !jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean" );
- assert.ok( !jQuery.isPlainObject(null), "null" );
- assert.ok( !jQuery.isPlainObject(undefined), "undefined" );
+ assert.ok( !jQuery.isPlainObject( "" ), "string" );
+ assert.ok( !jQuery.isPlainObject( 0 ) && !jQuery.isPlainObject( 1 ), "number" );
+ assert.ok( !jQuery.isPlainObject( true ) && !jQuery.isPlainObject( false ), "boolean" );
+ assert.ok( !jQuery.isPlainObject( null ), "null" );
+ assert.ok( !jQuery.isPlainObject( undefined ), "undefined" );
// Arrays shouldn't be matched
- assert.ok( !jQuery.isPlainObject([]), "array" );
+ assert.ok( !jQuery.isPlainObject( [] ), "array" );
// Instantiated objects shouldn't be matched
- assert.ok( !jQuery.isPlainObject(new Date()), "new Date" );
+ assert.ok( !jQuery.isPlainObject( new Date() ), "new Date" );
// Functions shouldn't be matched
- assert.ok( !jQuery.isPlainObject(fn), "fn" );
+ assert.ok( !jQuery.isPlainObject( fn ), "fn" );
// Again, instantiated objects shouldn't be matched
- assert.ok( !jQuery.isPlainObject(new fn()), "new fn (no methods)" );
+ assert.ok( !jQuery.isPlainObject( new fn() ), "new fn (no methods)" );
// Makes the function a little more realistic
// (and harder to detect, incidentally)
- fn.prototype["someMethod"] = function(){};
+ fn.prototype[ "someMethod" ] = function() {};
// Again, instantiated objects shouldn't be matched
- assert.ok( !jQuery.isPlainObject(new fn()), "new fn" );
+ assert.ok( !jQuery.isPlainObject( new fn() ), "new fn" );
// DOM Element
- assert.ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" );
+ assert.ok( !jQuery.isPlainObject( document.createElement( "div" ) ), "DOM Element" );
// Window
assert.ok( !jQuery.isPlainObject( window ), "window" );
@@ -321,27 +321,27 @@ QUnit.asyncTest("isPlainObject", function( assert ) {
assert.ok( pass, "Does not throw exceptions on host objects" );
// Objects from other windows should be matched
- Globals.register("iframeDone");
+ Globals.register( "iframeDone" );
window.iframeDone = function( otherObject, detail ) {
window.iframeDone = undefined;
iframe.parentNode.removeChild( iframe );
- assert.ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
+ assert.ok( jQuery.isPlainObject( new otherObject() ), "new otherObject" + ( detail ? " - " + detail : "" ) );
QUnit.start();
};
try {
- iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
+ iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) );
doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
- doc.write("<body onload='window.parent.iframeDone(Object);'>");
+ doc.write( "<body onload='window.parent.iframeDone(Object);'>" );
doc.close();
- } catch(e) {
+ } catch ( e ) {
window.iframeDone( Object, "iframes not supported" );
}
-});
+} );
-QUnit.test("isFunction", function( assert ) {
- assert.expect(19);
+QUnit.test( "isFunction", function( assert ) {
+ assert.expect( 19 );
var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
@@ -353,31 +353,31 @@ QUnit.test("isFunction", function( assert ) {
assert.ok( !jQuery.isFunction( 0 ), "0 Value" );
// Check built-ins
- assert.ok( jQuery.isFunction(String), "String Function("+String+")" );
- assert.ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
- assert.ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
- assert.ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
+ assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" );
+ assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" );
+ assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" );
+ assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" );
// When stringified, this could be misinterpreted
mystr = "function";
- assert.ok( !jQuery.isFunction(mystr), "Function String" );
+ assert.ok( !jQuery.isFunction( mystr ), "Function String" );
// When stringified, this could be misinterpreted
myarr = [ "function" ];
- assert.ok( !jQuery.isFunction(myarr), "Function Array" );
+ assert.ok( !jQuery.isFunction( myarr ), "Function Array" );
// When stringified, this could be misinterpreted
myfunction = { "function": "test" };
- assert.ok( !jQuery.isFunction(myfunction), "Function Object" );
+ assert.ok( !jQuery.isFunction( myfunction ), "Function Object" );
// Make sure normal functions still work
- fn = function(){};
- assert.ok( jQuery.isFunction(fn), "Normal Function" );
+ fn = function() {};
+ assert.ok( jQuery.isFunction( fn ), "Normal Function" );
- obj = document.createElement("object");
+ obj = document.createElement( "object" );
// Firefox says this is a function
- assert.ok( !jQuery.isFunction(obj), "Object Element" );
+ assert.ok( !jQuery.isFunction( obj ), "Object Element" );
// Since 1.3, this isn't supported (#2968)
//ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
@@ -385,14 +385,14 @@ QUnit.test("isFunction", function( assert ) {
nodes = document.body.childNodes;
// Safari says this is a function
- assert.ok( !jQuery.isFunction(nodes), "childNodes Property" );
+ assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" );
first = document.body.firstChild;
// Normal elements are reported ok everywhere
- assert.ok( !jQuery.isFunction(first), "A normal DOM Element" );
+ assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" );
- input = document.createElement("input");
+ input = document.createElement( "input" );
input.type = "text";
document.body.appendChild( input );
@@ -401,30 +401,30 @@ QUnit.test("isFunction", function( assert ) {
document.body.removeChild( input );
- a = document.createElement("a");
+ a = document.createElement( "a" );
a.href = "some-function";
document.body.appendChild( a );
// This serializes with the word 'function' in it
- assert.ok( !jQuery.isFunction(a), "Anchor Element" );
+ assert.ok( !jQuery.isFunction( a ), "Anchor Element" );
document.body.removeChild( a );
// Recursive function calls have lengths and array-like properties
- function callme(callback){
- function fn(response){
- callback(response);
+ function callme( callback ) {
+ function fn( response ) {
+ callback( response );
}
- assert.ok( jQuery.isFunction(fn), "Recursive Function Call" );
+ assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" );
- fn({ some: "data" });
+ fn( { some: "data" } );
}
- callme(function(){
- callme(function(){});
- });
-});
+ callme( function() {
+ callme( function() {} );
+ } );
+} );
QUnit.test( "isNumeric", function( assert ) {
assert.expect( 38 );
@@ -473,345 +473,349 @@ QUnit.test( "isNumeric", function( assert ) {
assert.equal( t( {} ), false, "Empty object" );
assert.equal( t( [] ), false, "Empty array" );
assert.equal( t( [ 42 ] ), false, "Array with one number" );
- assert.equal( t( function(){} ), false, "Instance of a function" );
+ assert.equal( t( function() {} ), false, "Instance of a function" );
assert.equal( t( new Date() ), false, "Instance of a Date" );
-});
+} );
-QUnit.test("isXMLDoc - HTML", function( assert ) {
- assert.expect(4);
+QUnit.test( "isXMLDoc - HTML", function( assert ) {
+ assert.expect( 4 );
assert.ok( !jQuery.isXMLDoc( document ), "HTML document" );
assert.ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" );
assert.ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" );
var body,
- iframe = document.createElement("iframe");
+ iframe = document.createElement( "iframe" );
document.body.appendChild( iframe );
try {
- body = jQuery(iframe).contents()[0];
+ body = jQuery( iframe ).contents()[ 0 ];
try {
assert.ok( !jQuery.isXMLDoc( body ), "Iframe body element" );
- } catch(e) {
+ } catch ( e ) {
assert.ok( false, "Iframe body element exception" );
}
- } catch(e) {
+ } catch ( e ) {
assert.ok( true, "Iframe body element - iframe not working correctly" );
}
document.body.removeChild( iframe );
-});
+} );
-QUnit.test("XSS via location.hash", function( assert ) {
- assert.expect(1);
+QUnit.test( "XSS via location.hash", function( assert ) {
+ assert.expect( 1 );
QUnit.stop();
- jQuery["_check9521"] = function(x){
+ jQuery[ "_check9521" ] = function( x ) {
assert.ok( x, "script called from #id-like selector with inline handler" );
- jQuery("#check9521").remove();
- delete jQuery["_check9521"];
+ jQuery( "#check9521" ).remove();
+ delete jQuery[ "_check9521" ];
QUnit.start();
};
try {
+
// This throws an error because it's processed like an id
- jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo("#qunit-fixture");
- } catch (err) {
- jQuery["_check9521"](true);
+ jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo( "#qunit-fixture" );
+ } catch ( err ) {
+ jQuery[ "_check9521" ]( true );
}
-});
+} );
-QUnit.test("isXMLDoc - XML", function( assert ) {
- assert.expect(3);
+QUnit.test( "isXMLDoc - XML", function( assert ) {
+ assert.expect( 3 );
var xml = createDashboardXML();
assert.ok( jQuery.isXMLDoc( xml ), "XML document" );
assert.ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
- assert.ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
-});
+ assert.ok( jQuery.isXMLDoc( jQuery( "tab", xml )[ 0 ] ), "XML Tab Element" );
+} );
-QUnit.test("isWindow", function( assert ) {
+QUnit.test( "isWindow", function( assert ) {
assert.expect( 14 );
- assert.ok( jQuery.isWindow(window), "window" );
- assert.ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
+ assert.ok( jQuery.isWindow( window ), "window" );
+ assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" );
assert.ok( !jQuery.isWindow(), "empty" );
- assert.ok( !jQuery.isWindow(null), "null" );
- assert.ok( !jQuery.isWindow(undefined), "undefined" );
- assert.ok( !jQuery.isWindow(document), "document" );
- assert.ok( !jQuery.isWindow(document.documentElement), "documentElement" );
- assert.ok( !jQuery.isWindow(""), "string" );
- assert.ok( !jQuery.isWindow(1), "number" );
- assert.ok( !jQuery.isWindow(true), "boolean" );
- assert.ok( !jQuery.isWindow({}), "object" );
- assert.ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
- assert.ok( !jQuery.isWindow(/window/), "regexp" );
- assert.ok( !jQuery.isWindow(function(){}), "function" );
-});
-
-QUnit.test("jQuery('html')", function( assert ) {
+ assert.ok( !jQuery.isWindow( null ), "null" );
+ assert.ok( !jQuery.isWindow( undefined ), "undefined" );
+ assert.ok( !jQuery.isWindow( document ), "document" );
+ assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" );
+ assert.ok( !jQuery.isWindow( "" ), "string" );
+ assert.ok( !jQuery.isWindow( 1 ), "number" );
+ assert.ok( !jQuery.isWindow( true ), "boolean" );
+ assert.ok( !jQuery.isWindow( {} ), "object" );
+ assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" );
+ assert.ok( !jQuery.isWindow( /window/ ), "regexp" );
+ assert.ok( !jQuery.isWindow( function() {} ), "function" );
+} );
+
+QUnit.test( "jQuery('html')", function( assert ) {
assert.expect( 18 );
var s, div, j;
- jQuery["foo"] = false;
- s = jQuery("<script>jQuery.foo='test';</script>")[0];
+ jQuery[ "foo" ] = false;
+ s = jQuery( "<script>jQuery.foo='test';</script>" )[ 0 ];
assert.ok( s, "Creating a script" );
- assert.ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" );
- jQuery("body").append("<script>jQuery.foo='test';</script>");
- assert.ok( jQuery["foo"], "Executing a scripts contents in the right context" );
+ assert.ok( !jQuery[ "foo" ], "Make sure the script wasn't executed prematurely" );
+ jQuery( "body" ).append( "<script>jQuery.foo='test';</script>" );
+ assert.ok( jQuery[ "foo" ], "Executing a scripts contents in the right context" );
// Test multi-line HTML
- div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0];
+ div = jQuery( "<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>" )[ 0 ];
assert.equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." );
assert.equal( div.firstChild.nodeType, 3, "Text node." );
assert.equal( div.lastChild.nodeType, 3, "Text node." );
- assert.equal( div.childNodes[1].nodeType, 1, "Paragraph." );
- assert.equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." );
+ assert.equal( div.childNodes[ 1 ].nodeType, 1, "Paragraph." );
+ assert.equal( div.childNodes[ 1 ].firstChild.nodeType, 3, "Paragraph text." );
- assert.ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
+ assert.ok( jQuery( "<link rel='stylesheet'/>" )[ 0 ], "Creating a link" );
- assert.ok( !jQuery("<script/>")[0].parentNode, "Create a script" );
+ assert.ok( !jQuery( "<script/>" )[ 0 ].parentNode, "Create a script" );
- assert.ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." );
+ assert.ok( jQuery( "<input/>" ).attr( "type", "hidden" ), "Create an input and set the type." );
- j = jQuery("<span>hi</span> there <!-- mon ami -->");
+ j = jQuery( "<span>hi</span> there <!-- mon ami -->" );
assert.ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
- assert.ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
+ assert.ok( !jQuery( "<option>test</option>" )[ 0 ].selected, "Make sure that options are auto-selected #2050" );
- assert.ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
- assert.ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
+ assert.ok( jQuery( "<div></div>" )[ 0 ], "Create a div with closing tag." );
+ assert.ok( jQuery( "<table></table>" )[ 0 ], "Create a table with closing tag." );
assert.equal( jQuery( "element[attribute='<div></div>']" ).length, 0,
"When html is within brackets, do not recognize as html." );
+
//equal( jQuery( "element[attribute=<div></div>]" ).length, 0,
// "When html is within brackets, do not recognize as html." );
assert.equal( jQuery( "element:not(<div></div>)" ).length, 0,
"When html is within parens, do not recognize as html." );
assert.equal( jQuery( "\\<div\\>" ).length, 0, "Ignore escaped html characters" );
-});
+} );
-QUnit.test("jQuery(tag-hyphenated elements) gh-1987", function( assert ) {
+QUnit.test( "jQuery(tag-hyphenated elements) gh-1987", function( assert ) {
assert.expect( 17 );
- jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) {
- var j = jQuery("<" + name + "-d></" + name + "-d>");
- assert.ok( j[0], "Create a tag-hyphenated elements" );
- assert.ok( jQuery.nodeName(j[0], name.toUpperCase() + "-D"), "Tag-hyphenated element has expected node name" );
- });
+ jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) {
+ var j = jQuery( "<" + name + "-d></" + name + "-d>" );
+ assert.ok( j[ 0 ], "Create a tag-hyphenated elements" );
+ assert.ok( jQuery.nodeName( j[ 0 ], name.toUpperCase() + "-D" ), "Tag-hyphenated element has expected node name" );
+ } );
- var j = jQuery("<tr-multiple-hyphens></tr-multiple-hyphens>");
- assert.ok( jQuery.nodeName(j[0], "TR-MULTIPLE-HYPHENS"), "Element with multiple hyphens in its tag has expected node name" );
-});
+ var j = jQuery( "<tr-multiple-hyphens></tr-multiple-hyphens>" );
+ assert.ok( jQuery.nodeName( j[ 0 ], "TR-MULTIPLE-HYPHENS" ), "Element with multiple hyphens in its tag has expected node name" );
+} );
-QUnit.test("jQuery('massive html #7990')", function( assert ) {
+QUnit.test( "jQuery('massive html #7990')", function( assert ) {
assert.expect( 3 );
var i,
li = "<li>very very very very large html string</li>",
- html = ["<ul>"];
+ html = [ "<ul>" ];
for ( i = 0; i < 30000; i += 1 ) {
- html[html.length] = li;
+ html[ html.length ] = li;
}
- html[html.length] = "</ul>";
- html = jQuery(html.join(""))[0];
- assert.equal( html.nodeName.toLowerCase(), "ul");
- assert.equal( html.firstChild.nodeName.toLowerCase(), "li");
+ html[ html.length ] = "</ul>";
+ html = jQuery( html.join( "" ) )[ 0 ];
+ assert.equal( html.nodeName.toLowerCase(), "ul" );
+ assert.equal( html.firstChild.nodeName.toLowerCase(), "li" );
assert.equal( html.childNodes.length, 30000 );
-});
+} );
-QUnit.test("jQuery('html', context)", function( assert ) {
- assert.expect(1);
+QUnit.test( "jQuery('html', context)", function( assert ) {
+ assert.expect( 1 );
- var $div = jQuery("<div/>")[0],
- $span = jQuery("<span/>", $div);
- assert.equal($span.length, 1, "verify a span created with a div context works, #1763");
-});
+ var $div = jQuery( "<div/>" )[ 0 ],
+ $span = jQuery( "<span/>", $div );
+ assert.equal( $span.length, 1, "verify a span created with a div context works, #1763" );
+} );
-QUnit.test("jQuery(selector, xml).text(str) - loaded via xml document", function( assert ) {
- assert.expect(2);
+QUnit.test( "jQuery(selector, xml).text(str) - loaded via xml document", function( assert ) {
+ assert.expect( 2 );
var xml = createDashboardXML(),
+
// tests for #1419 where ie was a problem
- tab = jQuery("tab", xml).eq(0);
+ tab = jQuery( "tab", xml ).eq( 0 );
assert.equal( tab.text(), "blabla", "verify initial text correct" );
- tab.text("newtext");
+ tab.text( "newtext" );
assert.equal( tab.text(), "newtext", "verify new text correct" );
-});
+} );
-QUnit.test("end()", function( assert ) {
- assert.expect(3);
- assert.equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "check for end" );
- assert.ok( jQuery("#yahoo").end(), "check for end with nothing to end" );
+QUnit.test( "end()", function( assert ) {
+ assert.expect( 3 );
+ assert.equal( "Yahoo", jQuery( "#yahoo" ).parent().end().text(), "check for end" );
+ assert.ok( jQuery( "#yahoo" ).end(), "check for end with nothing to end" );
- var x = jQuery("#yahoo");
+ var x = jQuery( "#yahoo" );
x.parent();
- assert.equal( "Yahoo", jQuery("#yahoo").text(), "check for non-destructive behaviour" );
-});
-
-QUnit.test("length", function( assert ) {
- assert.expect(1);
- assert.equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
-});
-
-QUnit.test("get()", function( assert ) {
- assert.expect(1);
- assert.deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
-});
-
-QUnit.test("toArray()", function( assert ) {
- assert.expect(1);
- assert.deepEqual( jQuery("#qunit-fixture p").toArray(),
- q("firstp","ap","sndp","en","sap","first"),
+ assert.equal( "Yahoo", jQuery( "#yahoo" ).text(), "check for non-destructive behaviour" );
+} );
+
+QUnit.test( "length", function( assert ) {
+ assert.expect( 1 );
+ assert.equal( jQuery( "#qunit-fixture p" ).length, 6, "Get Number of Elements Found" );
+} );
+
+QUnit.test( "get()", function( assert ) {
+ assert.expect( 1 );
+ assert.deepEqual( jQuery( "#qunit-fixture p" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Get All Elements" );
+} );
+
+QUnit.test( "toArray()", function( assert ) {
+ assert.expect( 1 );
+ assert.deepEqual( jQuery( "#qunit-fixture p" ).toArray(),
+ q( "firstp", "ap", "sndp", "en", "sap", "first" ),
"Convert jQuery object to an Array" );
-});
+} );
-QUnit.test("inArray()", function( assert ) {
- assert.expect(19);
+QUnit.test( "inArray()", function( assert ) {
+ assert.expect( 19 );
var selections = {
- p: q("firstp", "sap", "ap", "first"),
- em: q("siblingnext", "siblingfirst"),
- div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"),
- a: q("mark", "groups", "google", "simon1"),
+ p: q( "firstp", "sap", "ap", "first" ),
+ em: q( "siblingnext", "siblingfirst" ),
+ div: q( "qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo" ),
+ a: q( "mark", "groups", "google", "simon1" ),
empty: []
},
tests = {
- p: { elem: jQuery("#ap")[0], index: 2 },
- em: { elem: jQuery("#siblingfirst")[0], index: 1 },
- div: { elem: jQuery("#nothiddendiv")[0], index: 1 },
- a: { elem: jQuery("#simon1")[0], index: 3 }
+ p: { elem: jQuery( "#ap" )[ 0 ], index: 2 },
+ em: { elem: jQuery( "#siblingfirst" )[ 0 ], index: 1 },
+ div: { elem: jQuery( "#nothiddendiv" )[ 0 ], index: 1 },
+ a: { elem: jQuery( "#simon1" )[ 0 ], index: 3 }
},
falseTests = {
- p: jQuery("#liveSpan1")[0],
- em: jQuery("#nothiddendiv")[0],
+ p: jQuery( "#liveSpan1" )[ 0 ],
+ em: jQuery( "#nothiddendiv" )[ 0 ],
empty: ""
};
jQuery.each( tests, function( key, obj ) {
assert.equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" );
+
// Third argument (fromIndex)
assert.equal( !!~jQuery.inArray( obj.elem, selections[ key ], 5 ), false, "elem is NOT in the array of selections given a starting index greater than its position" );
assert.equal( !!~jQuery.inArray( obj.elem, selections[ key ], 1 ), true, "elem is in the array of selections given a starting index less than or equal to its position" );
assert.equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" );
- });
+ } );
jQuery.each( falseTests, function( key, elem ) {
assert.equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" );
- });
+ } );
-});
+} );
-QUnit.test("get(Number)", function( assert ) {
- assert.expect(2);
- assert.equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
- assert.strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
-});
+QUnit.test( "get(Number)", function( assert ) {
+ assert.expect( 2 );
+ assert.equal( jQuery( "#qunit-fixture p" ).get( 0 ), document.getElementById( "firstp" ), "Get A Single Element" );
+ assert.strictEqual( jQuery( "#firstp" ).get( 1 ), undefined, "Try get with index larger elements count" );
+} );
-QUnit.test("get(-Number)",function( assert ) {
- assert.expect(2);
- assert.equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
- assert.strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
-});
+QUnit.test( "get(-Number)", function( assert ) {
+ assert.expect( 2 );
+ assert.equal( jQuery( "p" ).get( -1 ), document.getElementById( "first" ), "Get a single element with negative index" );
+ assert.strictEqual( jQuery( "#firstp" ).get( -2 ), undefined, "Try get with index negative index larger then elements count" );
+} );
-QUnit.test("each(Function)", function( assert ) {
- assert.expect(1);
+QUnit.test( "each(Function)", function( assert ) {
+ assert.expect( 1 );
var div, pass, i;
- div = jQuery("div");
- div.each(function(){this.foo = "zoo";});
+ div = jQuery( "div" );
+ div.each( function() {this.foo = "zoo";} );
pass = true;
for ( i = 0; i < div.length; i++ ) {
- if ( div.get(i).foo !== "zoo" ) {
+ if ( div.get( i ).foo !== "zoo" ) {
pass = false;
}
}
assert.ok( pass, "Execute a function, Relative" );
-});
+} );
-QUnit.test("slice()", function( assert ) {
- assert.expect(7);
+QUnit.test( "slice()", function( assert ) {
+ assert.expect( 7 );
- var $links = jQuery("#ap a");
+ var $links = jQuery( "#ap a" );
- assert.deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" );
- assert.deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" );
- assert.deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" );
- assert.deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" );
+ assert.deepEqual( $links.slice( 1, 2 ).get(), q( "groups" ), "slice(1,2)" );
+ assert.deepEqual( $links.slice( 1 ).get(), q( "groups", "anchor1", "mark" ), "slice(1)" );
+ assert.deepEqual( $links.slice( 0, 3 ).get(), q( "google", "groups", "anchor1" ), "slice(0,3)" );
+ assert.deepEqual( $links.slice( -1 ).get(), q( "mark" ), "slice(-1)" );
- assert.deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" );
- assert.deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" );
- assert.deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" );
-});
+ assert.deepEqual( $links.eq( 1 ).get(), q( "groups" ), "eq(1)" );
+ assert.deepEqual( $links.eq( "2" ).get(), q( "anchor1" ), "eq('2')" );
+ assert.deepEqual( $links.eq( -1 ).get(), q( "mark" ), "eq(-1)" );
+} );
-QUnit.test("first()/last()", function( assert ) {
- assert.expect(4);
+QUnit.test( "first()/last()", function( assert ) {
+ assert.expect( 4 );
- var $links = jQuery("#ap a"), $none = jQuery("asdf");
+ var $links = jQuery( "#ap a" ), $none = jQuery( "asdf" );
- assert.deepEqual( $links.first().get(), q("google"), "first()" );
- assert.deepEqual( $links.last().get(), q("mark"), "last()" );
+ assert.deepEqual( $links.first().get(), q( "google" ), "first()" );
+ assert.deepEqual( $links.last().get(), q( "mark" ), "last()" );
assert.deepEqual( $none.first().get(), [], "first() none" );
assert.deepEqual( $none.last().get(), [], "last() none" );
-});
+} );
-QUnit.test("map()", function( assert ) {
+QUnit.test( "map()", function( assert ) {
assert.expect( 2 );
assert.deepEqual(
- jQuery("#ap").map(function() {
- return jQuery( this ).find("a").get();
- }).get(),
+ jQuery( "#ap" ).map( function() {
+ return jQuery( this ).find( "a" ).get();
+ } ).get(),
q( "google", "groups", "anchor1", "mark" ),
"Array Map"
);
assert.deepEqual(
- jQuery("#ap > a").map(function() {
+ jQuery( "#ap > a" ).map( function() {
return this.parentNode;
- }).get(),
- q( "ap","ap","ap" ),
+ } ).get(),
+ q( "ap", "ap", "ap" ),
"Single Map"
);
-});
+} );
-QUnit.test("jQuery.map", function( assert ) {
+QUnit.test( "jQuery.map", function( assert ) {
assert.expect( 25 );
var i, label, result, callback;
result = jQuery.map( [ 3, 4, 5 ], function( v, k ) {
return k;
- });
- assert.equal( result.join(""), "012", "Map the keys from an array" );
+ } );
+ assert.equal( result.join( "" ), "012", "Map the keys from an array" );
result = jQuery.map( [ 3, 4, 5 ], function( v ) {
return v;
- });
- assert.equal( result.join(""), "345", "Map the values from an array" );
+ } );
+ assert.equal( result.join( "" ), "345", "Map the values from an array" );
result = jQuery.map( { a: 1, b: 2 }, function( v, k ) {
return k;
- });
- assert.equal( result.join(""), "ab", "Map the keys from an object" );
+ } );
+ assert.equal( result.join( "" ), "ab", "Map the keys from an object" );
result = jQuery.map( { a: 1, b: 2 }, function( v ) {
return v;
- });
- assert.equal( result.join(""), "12", "Map the values from an object" );
+ } );
+ assert.equal( result.join( "" ), "12", "Map the values from an object" );
result = jQuery.map( [ "a", undefined, null, "b" ], function( v ) {
return v;
- });
- assert.equal( result.join(""), "ab", "Array iteration does not include undefined/null results" );
+ } );
+ assert.equal( result.join( "" ), "ab", "Array iteration does not include undefined/null results" );
result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v ) {
return v;
- });
- assert.equal( result.join(""), "ab", "Object iteration does not include undefined/null results" );
+ } );
+ assert.equal( result.join( "" ), "ab", "Object iteration does not include undefined/null results" );
result = {
Zero: function() {},
@@ -850,7 +854,7 @@ QUnit.test("jQuery.map", function( assert ) {
"sparse Array": Array( 4 ),
"length: 1 plain object": { length: 1, "0": true },
"length: 2 plain object": { length: 2, "0": true, "1": true },
- NodeList: document.getElementsByTagName("html")
+ NodeList: document.getElementsByTagName( "html" )
};
callback = function( v, k ) {
if ( result[ label ] ) {
@@ -866,22 +870,22 @@ QUnit.test("jQuery.map", function( assert ) {
result = false;
jQuery.map( { length: 0 }, function() {
result = true;
- });
+ } );
assert.ok( !result, "length: 0 plain object treated like array" );
result = false;
- jQuery.map( document.getElementsByTagName("asdf"), function() {
+ jQuery.map( document.getElementsByTagName( "asdf" ), function() {
result = true;
- });
+ } );
assert.ok( !result, "empty NodeList treated like array" );
- result = jQuery.map( Array(4), function( v, k ){
- return k % 2 ? k : [k,k,k];
- });
- assert.equal( result.join(""), "00012223", "Array results flattened (#2616)" );
-});
+ result = jQuery.map( Array( 4 ), function( v, k ) {
+ return k % 2 ? k : [ k,k,k ];
+ } );
+ assert.equal( result.join( "" ), "00012223", "Array results flattened (#2616)" );
+} );
-QUnit.test("jQuery.merge()", function( assert ) {
+QUnit.test( "jQuery.merge()", function( assert ) {
assert.expect( 10 );
assert.deepEqual(
@@ -915,7 +919,7 @@ QUnit.test("jQuery.merge()", function( assert ) {
// Fixed at [5998], #3641
assert.deepEqual(
jQuery.merge( [ -2, -1 ], [ 0, 1, 2 ] ),
- [ -2, -1 , 0, 1, 2 ],
+ [ -2, -1, 0, 1, 2 ],
"Second array including a zero (falsy)"
);
@@ -937,34 +941,34 @@ QUnit.test("jQuery.merge()", function( assert ) {
);
assert.deepEqual(
- jQuery.merge( [], document.getElementById("lengthtest").getElementsByTagName("input") ),
- [ document.getElementById("length"), document.getElementById("idTest") ],
+ jQuery.merge( [], document.getElementById( "lengthtest" ).getElementsByTagName( "input" ) ),
+ [ document.getElementById( "length" ), document.getElementById( "idTest" ) ],
"Second NodeList"
);
-});
+} );
-QUnit.test("jQuery.grep()", function( assert ) {
- assert.expect(8);
+QUnit.test( "jQuery.grep()", function( assert ) {
+ assert.expect( 8 );
var searchCriterion = function( value ) {
return value % 2 === 0;
};
assert.deepEqual( jQuery.grep( [], searchCriterion ), [], "Empty array" );
- assert.deepEqual( jQuery.grep( new Array(4), searchCriterion ), [], "Sparse array" );
+ assert.deepEqual( jQuery.grep( new Array( 4 ), searchCriterion ), [], "Sparse array" );
assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ), [ 2, 4, 6 ], "Satisfying elements present" );
- assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion ), [], "Satisfying elements absent" );
+ assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion ), [], "Satisfying elements absent" );
assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ), [ 1, 3, 5 ], "Satisfying elements present and grep inverted" );
- assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion, true ), [1, 3, 5, 7], "Satisfying elements absent and grep inverted" );
+ assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, true ), [ 1, 3, 5, 7 ], "Satisfying elements absent and grep inverted" );
assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ), [ 2, 4, 6 ], "Satisfying elements present but grep explicitly uninverted" );
assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ), [], "Satisfying elements absent and grep explicitly uninverted" );
-});
+} );
-QUnit.test("jQuery.extend(Object, Object)", function( assert ) {
- assert.expect(28);
+QUnit.test( "jQuery.extend(Object, Object)", function( assert ) {
+ assert.expect( 28 );
var empty, optionsWithLength, optionsWithDate, myKlass,
customObject, optionsWithCustomObject, MyNumber, ret,
@@ -978,87 +982,87 @@ QUnit.test("jQuery.extend(Object, Object)", function( assert ) {
deep2 = { "foo": { "baz": true }, "foo2": document },
deep2copy = { "foo": { "baz": true }, "foo2": document },
deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document },
- arr = [1, 2, 3],
+ arr = [ 1, 2, 3 ],
nestedarray = { "arr": arr };
- jQuery.extend(settings, options);
+ jQuery.extend( settings, options );
assert.deepEqual( settings, merged, "Check if extended: settings must be extended" );
assert.deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
- jQuery.extend(settings, null, options);
+ jQuery.extend( settings, null, options );
assert.deepEqual( settings, merged, "Check if extended: settings must be extended" );
assert.deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
- jQuery.extend(true, deep1, deep2);
- assert.deepEqual( deep1["foo"], deepmerged["foo"], "Check if foo: settings must be extended" );
- assert.deepEqual( deep2["foo"], deep2copy["foo"], "Check if not deep2: options must not be modified" );
- assert.equal( deep1["foo2"], document, "Make sure that a deep clone was not attempted on the document" );
+ jQuery.extend( true, deep1, deep2 );
+ assert.deepEqual( deep1[ "foo" ], deepmerged[ "foo" ], "Check if foo: settings must be extended" );
+ assert.deepEqual( deep2[ "foo" ], deep2copy[ "foo" ], "Check if not deep2: options must not be modified" );
+ assert.equal( deep1[ "foo2" ], document, "Make sure that a deep clone was not attempted on the document" );
- assert.ok( jQuery.extend(true, {}, nestedarray)["arr"] !== arr, "Deep extend of object must clone child array" );
+ assert.ok( jQuery.extend( true, {}, nestedarray )[ "arr" ] !== arr, "Deep extend of object must clone child array" );
// #5991
- assert.ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array have to be an Array" );
- assert.ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object have to be an plain object" );
+ assert.ok( jQuery.isArray( jQuery.extend( true, { "arr": {} }, nestedarray )[ "arr" ] ), "Cloned array have to be an Array" );
+ assert.ok( jQuery.isPlainObject( jQuery.extend( true, { "arr": arr }, { "arr": {} } )[ "arr" ] ), "Cloned object have to be an plain object" );
empty = {};
optionsWithLength = { "foo": { "length": -1 } };
- jQuery.extend(true, empty, optionsWithLength);
- assert.deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" );
+ jQuery.extend( true, empty, optionsWithLength );
+ assert.deepEqual( empty[ "foo" ], optionsWithLength[ "foo" ], "The length property must copy correctly" );
empty = {};
optionsWithDate = { "foo": { "date": new Date() } };
- jQuery.extend(true, empty, optionsWithDate);
- assert.deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" );
+ jQuery.extend( true, empty, optionsWithDate );
+ assert.deepEqual( empty[ "foo" ], optionsWithDate[ "foo" ], "Dates copy correctly" );
/** @constructor */
myKlass = function() {};
customObject = new myKlass();
optionsWithCustomObject = { "foo": { "date": customObject } };
empty = {};
- jQuery.extend(true, empty, optionsWithCustomObject);
- assert.ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" );
+ jQuery.extend( true, empty, optionsWithCustomObject );
+ assert.ok( empty[ "foo" ] && empty[ "foo" ][ "date" ] === customObject, "Custom objects copy correctly (no methods)" );
// Makes the class a little more realistic
- myKlass.prototype = { "someMethod": function(){} };
+ myKlass.prototype = { "someMethod": function() {} };
empty = {};
- jQuery.extend(true, empty, optionsWithCustomObject);
- assert.ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" );
+ jQuery.extend( true, empty, optionsWithCustomObject );
+ assert.ok( empty[ "foo" ] && empty[ "foo" ][ "date" ] === customObject, "Custom objects copy correctly" );
MyNumber = Number;
- ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } );
- assert.ok( parseInt(ret.foo, 10) === 5, "Wrapped numbers copy correctly" );
+ ret = jQuery.extend( true, { "foo": 4 }, { "foo": new MyNumber( 5 ) } );
+ assert.ok( parseInt( ret.foo, 10 ) === 5, "Wrapped numbers copy correctly" );
nullUndef;
- nullUndef = jQuery.extend({}, options, { "xnumber2": null });
- assert.ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied");
+ nullUndef = jQuery.extend( {}, options, { "xnumber2": null } );
+ assert.ok( nullUndef[ "xnumber2" ] === null, "Check to make sure null values are copied" );
- nullUndef = jQuery.extend({}, options, { "xnumber2": undefined });
- assert.ok( nullUndef["xnumber2"] === options["xnumber2"], "Check to make sure undefined values are not copied");
+ nullUndef = jQuery.extend( {}, options, { "xnumber2": undefined } );
+ assert.ok( nullUndef[ "xnumber2" ] === options[ "xnumber2" ], "Check to make sure undefined values are not copied" );
- nullUndef = jQuery.extend({}, options, { "xnumber0": null });
- assert.ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted");
+ nullUndef = jQuery.extend( {}, options, { "xnumber0": null } );
+ assert.ok( nullUndef[ "xnumber0" ] === null, "Check to make sure null values are inserted" );
target = {};
recursive = { foo:target, bar:5 };
- jQuery.extend(true, target, recursive);
+ jQuery.extend( true, target, recursive );
assert.deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
- ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
+ ret = jQuery.extend( true, { foo: [] }, { foo: [ 0 ] } ); // 1907
assert.equal( ret.foo.length, 1, "Check to make sure a value with coercion 'false' copies over when necessary to fix #1907" );
- ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
+ ret = jQuery.extend( true, { foo: "1,2,3" }, { foo: [ 1, 2, 3 ] } );
assert.ok( typeof ret.foo !== "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" );
- ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
+ ret = jQuery.extend( true, { foo:"bar" }, { foo:null } );
assert.ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
obj = { foo:null };
- jQuery.extend(true, obj, { foo:"notnull" } );
+ jQuery.extend( true, obj, { foo:"notnull" } );
assert.equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
function func() {}
- jQuery.extend(func, { key: "value" } );
+ jQuery.extend( func, { key: "value" } );
assert.equal( func.key, "value", "Verify a function can be extended" );
defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
@@ -1069,19 +1073,21 @@ QUnit.test("jQuery.extend(Object, Object)", function( assert ) {
options2Copy = { xstring2: "xx", xxx: "newstringx" };
merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
- settings = jQuery.extend({}, defaults, options1, options2);
+ settings = jQuery.extend( {}, defaults, options1, options2 );
assert.deepEqual( settings, merged2, "Check if extended: settings must be extended" );
assert.deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
assert.deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
assert.deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
-});
+} );
-QUnit.test("jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed by object", function( assert ) {
- assert.expect(2);
+QUnit.test( "jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed by object", function( assert ) {
+ assert.expect( 2 );
var result, initial = {
+
// This will make "copyIsArray" true
array: [ 1, 2, 3, 4 ],
+
// If "copyIsArray" doesn't get reset to false, the check
// will evaluate true and enter the array copy block
// instead of the object copy block. Since the ternary in the
@@ -1095,9 +1101,9 @@ QUnit.test("jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed
assert.deepEqual( result, initial, "The [result] and [initial] have equal shape and values" );
assert.ok( !jQuery.isArray( result.object ), "result.object wasn't paved with an empty array" );
-});
+} );
-QUnit.test("jQuery.each(Object,Function)", function( assert ) {
+QUnit.test( "jQuery.each(Object,Function)", function( assert ) {
assert.expect( 23 );
var i, label, seen, callback;
@@ -1105,13 +1111,13 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) {
seen = {};
jQuery.each( [ 3, 4, 5 ], function( k, v ) {
seen[ k ] = v;
- });
+ } );
assert.deepEqual( seen, { "0": 3, "1": 4, "2": 5 }, "Array iteration" );
seen = {};
jQuery.each( { name: "name", lang: "lang" }, function( k, v ) {
seen[ k ] = v;
- });
+ } );
assert.deepEqual( seen, { name: "name", lang: "lang" }, "Object iteration" );
seen = [];
@@ -1120,14 +1126,14 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) {
if ( k === 1 ) {
return false;
}
- });
- assert.deepEqual( seen, [ 1, 2 ] , "Broken array iteration" );
+ } );
+ assert.deepEqual( seen, [ 1, 2 ], "Broken array iteration" );
seen = [];
- jQuery.each( {"a": 1, "b": 2,"c": 3 }, function( k, v ) {
+ jQuery.each( { "a": 1, "b": 2,"c": 3 }, function( k, v ) {
seen.push( v );
return false;
- });
+ } );
assert.deepEqual( seen, [ 1 ], "Broken object iteration" );
seen = {
@@ -1167,7 +1173,7 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) {
"sparse Array": Array( 4 ),
"length: 1 plain object": { length: 1, "0": true },
"length: 2 plain object": { length: 2, "0": true, "1": true },
- NodeList: document.getElementsByTagName("html")
+ NodeList: document.getElementsByTagName( "html" )
};
callback = function( k ) {
if ( seen[ label ] ) {
@@ -1184,23 +1190,23 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) {
seen = false;
jQuery.each( { length: 0 }, function() {
seen = true;
- });
+ } );
assert.ok( !seen, "length: 0 plain object treated like array" );
seen = false;
- jQuery.each( document.getElementsByTagName("asdf"), function() {
+ jQuery.each( document.getElementsByTagName( "asdf" ), function() {
seen = true;
- });
+ } );
assert.ok( !seen, "empty NodeList treated like array" );
i = 0;
jQuery.each( document.styleSheets, function() {
i++;
- });
+ } );
assert.equal( i, document.styleSheets.length, "Iteration over document.styleSheets" );
-});
+} );
-QUnit.test("jQuery.each/map(undefined/null,Function)", function( assert ) {
+QUnit.test( "jQuery.each/map(undefined/null,Function)", function( assert ) {
assert.expect( 1 );
try {
@@ -1212,7 +1218,7 @@ QUnit.test("jQuery.each/map(undefined/null,Function)", function( assert ) {
} catch ( e ) {
assert.ok( false, "each/map must accept null and undefined values" );
}
-});
+} );
QUnit.test( "JIT compilation does not interfere with length retrieval (gh-2145)", function( assert ) {
assert.expect( 4 );
@@ -1230,74 +1236,74 @@ QUnit.test( "JIT compilation does not interfere with length retrieval (gh-2145)"
jQuery.each( { 1: "1", 2: "2", 3: "3" }, function( index ) {
assert.equal( ++i, index, "Iteration over object with solely " +
"numeric indices (gh-2145 JIT iOS 8 bug)" );
- });
+ } );
assert.equal( i, 3, "Iteration over object with solely " +
"numeric indices (gh-2145 JIT iOS 8 bug)" );
-});
+} );
-QUnit.test("jQuery.makeArray", function( assert ){
- assert.expect(15);
+QUnit.test( "jQuery.makeArray", function( assert ) {
+ assert.expect( 15 );
- assert.equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
+ assert.equal( jQuery.makeArray( jQuery( "html>*" ) )[ 0 ].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
- assert.equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
+ assert.equal( jQuery.makeArray( document.getElementsByName( "PWD" ) ).slice( 0, 1 )[ 0 ].name, "PWD", "Pass makeArray a nodelist" );
- assert.equal( (function() { return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
+ assert.equal( ( function() { return jQuery.makeArray( arguments ); } )( 1, 2 ).join( "" ), "12", "Pass makeArray an arguments array" );
- assert.equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
+ assert.equal( jQuery.makeArray( [ 1,2,3 ] ).join( "" ), "123", "Pass makeArray a real array" );
assert.equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
- assert.equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
+ assert.equal( jQuery.makeArray( 0 )[ 0 ], 0, "Pass makeArray a number" );
- assert.equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
+ assert.equal( jQuery.makeArray( "foo" )[ 0 ], "foo", "Pass makeArray a string" );
- assert.equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
+ assert.equal( jQuery.makeArray( true )[ 0 ].constructor, Boolean, "Pass makeArray a boolean" );
- assert.equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
+ assert.equal( jQuery.makeArray( document.createElement( "div" ) )[ 0 ].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
- assert.equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
+ assert.equal( jQuery.makeArray( { length:2, 0:"a", 1:"b" } ).join( "" ), "ab", "Pass makeArray an array like map (with length)" );
- assert.ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
+ assert.ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice( 0, 1 )[ 0 ].nodeName, "Pass makeArray a childNodes array" );
// function, is tricky as it has length
- assert.equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
+ assert.equal( jQuery.makeArray( function() { return 1;} )[ 0 ](), 1, "Pass makeArray a function" );
//window, also has length
- assert.equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
+ assert.equal( jQuery.makeArray( window )[ 0 ], window, "Pass makeArray the window" );
- assert.equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
+ assert.equal( jQuery.makeArray( /a/ )[ 0 ].constructor, RegExp, "Pass makeArray a regex" );
// Some nodes inherit traits of nodelists
- assert.ok( jQuery.makeArray(document.getElementById("form")).length >= 13,
+ assert.ok( jQuery.makeArray( document.getElementById( "form" ) ).length >= 13,
"Pass makeArray a form (treat as elements)" );
-});
+} );
-QUnit.test("jQuery.inArray", function( assert ){
- assert.expect(3);
+QUnit.test( "jQuery.inArray", function( assert ) {
+ assert.expect( 3 );
- assert.equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
+ assert.equal( jQuery.inArray( 0, false ), -1, "Search in 'false' as array returns -1 and doesn't throw exception" );
- assert.equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
+ assert.equal( jQuery.inArray( 0, null ), -1, "Search in 'null' as array returns -1 and doesn't throw exception" );
- assert.equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
-});
+ assert.equal( jQuery.inArray( 0, undefined ), -1, "Search in 'undefined' as array returns -1 and doesn't throw exception" );
+} );
-QUnit.test("jQuery.isEmptyObject", function( assert ){
- assert.expect(2);
+QUnit.test( "jQuery.isEmptyObject", function( assert ) {
+ assert.expect( 2 );
- assert.equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
- assert.equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
+ assert.equal( true, jQuery.isEmptyObject( {} ), "isEmptyObject on empty object literal" );
+ assert.equal( false, jQuery.isEmptyObject( { a:1 } ), "isEmptyObject on non-empty object literal" );
// What about this ?
// equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
-});
+} );
-QUnit.test("jQuery.proxy", function( assert ){
+QUnit.test( "jQuery.proxy", function( assert ) {
assert.expect( 9 );
var test2, test3, test4, fn, cb,
- test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); },
+ test = function() { equal( this, thisObject, "Make sure that scope is set properly." ); },
thisObject = { foo: "bar", method: test };
// Make sure normal works
@@ -1313,15 +1319,15 @@ QUnit.test("jQuery.proxy", function( assert ){
assert.equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
// Partial application
- test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
+ test2 = function( a ) { equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
jQuery.proxy( test2, null, "pre-applied" )();
// Partial application w/ normal arguments
- test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
+ test3 = function( a, b ) { equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
jQuery.proxy( test3, null, "pre-applied" )( "normal" );
// Test old syntax
- test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
+ test4 = { "meth": function( a ) { equal( a, "boom", "Ensure old syntax works." ); } };
jQuery.proxy( test4, "meth" )( "boom" );
// jQuery 1.9 improved currying with `this` object
@@ -1331,9 +1337,9 @@ QUnit.test("jQuery.proxy", function( assert ){
};
cb = jQuery.proxy( fn, null, "arg1", "arg2" );
cb.call( thisObject, "arg3" );
-});
+} );
-QUnit.test("jQuery.parseHTML", function( assert ) {
+QUnit.test( "jQuery.parseHTML", function( assert ) {
assert.expect( 23 );
var html, nodes;
@@ -1346,91 +1352,91 @@ QUnit.test("jQuery.parseHTML", function( assert ) {
assert.deepEqual( jQuery.parseHTML( true ), [], "Boolean true" );
assert.deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" );
assert.deepEqual( jQuery.parseHTML( "" ), [], "Empty string" );
- assert.throws(function() {
- jQuery.parseHTML( "<div></div>", document.getElementById("form") );
- }, "Passing an element as the context raises an exception (context should be a document)");
+ assert.throws( function() {
+ jQuery.parseHTML( "<div></div>", document.getElementById( "form" ) );
+ }, "Passing an element as the context raises an exception (context should be a document)" );
- nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML );
+ nodes = jQuery.parseHTML( jQuery( "body" )[ 0 ].innerHTML );
assert.ok( nodes.length > 4, "Parse a large html string" );
assert.equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
html = "<script>undefined()</script>";
assert.equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
- assert.equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
+ assert.equal( jQuery.parseHTML( html, true )[ 0 ].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
html += "<div></div>";
- assert.equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
- assert.equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve script position");
+ assert.equal( jQuery.parseHTML( html )[ 0 ].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
+ assert.equal( jQuery.parseHTML( html, true )[ 0 ].nodeName.toLowerCase(), "script", "Preserve script position" );
- assert.equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" );
- assert.equal( jQuery.parseHTML( "\t<div></div>" )[0].nodeValue, "\t", "Preserve leading whitespace" );
+ assert.equal( jQuery.parseHTML( "text" )[ 0 ].nodeType, 3, "Parsing text returns a text node" );
+ assert.equal( jQuery.parseHTML( "\t<div></div>" )[ 0 ].nodeValue, "\t", "Preserve leading whitespace" );
- assert.equal( jQuery.parseHTML(" <div/> ")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
+ assert.equal( jQuery.parseHTML( " <div/> " )[ 0 ].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
html = jQuery.parseHTML( "<div>test div</div>" );
assert.equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
assert.equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" );
- assert.equal( jQuery.parseHTML("<span><span>").length, 1, "Incorrect html-strings should not break anything" );
- assert.equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11,
+ assert.equal( jQuery.parseHTML( "<span><span>" ).length, 1, "Incorrect html-strings should not break anything" );
+ assert.equal( jQuery.parseHTML( "<td><td>" )[ 1 ].parentNode.nodeType, 11,
"parentNode should be documentFragment for wrapMap (variable in manipulation module) elements too" );
- assert.ok( jQuery.parseHTML("<#if><tr><p>This is a test.</p></tr><#/if>") || true, "Garbage input should not cause error" );
-});
+ assert.ok( jQuery.parseHTML( "<#if><tr><p>This is a test.</p></tr><#/if>" ) || true, "Garbage input should not cause error" );
+} );
if ( jQuery.support.createHTMLDocument ) {
- QUnit.asyncTest("jQuery.parseHTML", function( assert ) {
+ QUnit.asyncTest( "jQuery.parseHTML", function( assert ) {
expect ( 1 );
- Globals.register("parseHTMLError");
+ Globals.register( "parseHTMLError" );
- jQuery.globalEval("parseHTMLError = false;");
+ jQuery.globalEval( "parseHTMLError = false;" );
jQuery.parseHTML( "<img src=x onerror='parseHTMLError = true'>" );
- window.setTimeout(function() {
+ window.setTimeout( function() {
QUnit.start();
assert.equal( window.parseHTMLError, false, "onerror eventhandler has not been called." );
- }, 2000);
- });
+ }, 2000 );
+ } );
}
-QUnit.test("jQuery.parseJSON", function( assert ) {
+QUnit.test( "jQuery.parseJSON", function( assert ) {
assert.expect( 20 );
assert.strictEqual( jQuery.parseJSON( null ), null, "primitive null" );
- assert.strictEqual( jQuery.parseJSON("0.88"), 0.88, "Number" );
+ assert.strictEqual( jQuery.parseJSON( "0.88" ), 0.88, "Number" );
assert.strictEqual(
- jQuery.parseJSON("\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \""),
+ jQuery.parseJSON( "\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \"" ),
" \" \\ / \b \f \n \r \t ~ \u263A ",
"String escapes"
);
- assert.deepEqual( jQuery.parseJSON("{}"), {}, "Empty object" );
- assert.deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object" );
- assert.deepEqual( jQuery.parseJSON("[0]"), [ 0 ], "Simple array" );
+ assert.deepEqual( jQuery.parseJSON( "{}" ), {}, "Empty object" );
+ assert.deepEqual( jQuery.parseJSON( "{\"test\":1}" ), { "test": 1 }, "Plain object" );
+ assert.deepEqual( jQuery.parseJSON( "[0]" ), [ 0 ], "Simple array" );
assert.deepEqual(
- jQuery.parseJSON("[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]"),
+ jQuery.parseJSON( "[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]" ),
[ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ],
"Array of all data types"
);
assert.deepEqual(
jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," +
- "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }"),
- { string: "", number: 42, object: {}, array: [[]], "boolean": [ true, false ], "null": null },
+ "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }" ),
+ { string: "", number: 42, object: {}, array: [ [] ], "boolean": [ true, false ], "null": null },
"Dictionary of all data types"
);
- assert.deepEqual( jQuery.parseJSON("\n{\"test\":1}\t"), { "test": 1 },
+ assert.deepEqual( jQuery.parseJSON( "\n{\"test\":1}\t" ), { "test": 1 },
"Leading and trailing whitespace are ignored" );
- assert.throws(function() {
+ assert.throws( function() {
jQuery.parseJSON();
}, null, "Undefined raises an error" );
- assert.throws(function() {
+ assert.throws( function() {
jQuery.parseJSON( "" );
}, null, "Empty string raises an error" );
- assert.throws(function() {
- jQuery.parseJSON("''");
+ assert.throws( function() {
+ jQuery.parseJSON( "''" );
}, null, "Single-quoted string raises an error" );
/*
@@ -1450,38 +1456,38 @@ QUnit.test("jQuery.parseJSON", function( assert ) {
}, null, "Number with no integer component raises an error" );
*/
- assert.throws(function() {
- var result = jQuery.parseJSON("0101");
+ assert.throws( function() {
+ var result = jQuery.parseJSON( "0101" );
// Support: IE9+
// Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers
if ( result === 101 ) {
- throw new Error("close enough");
+ throw new Error( "close enough" );
}
}, null, "Leading-zero number raises an error or is parsed as decimal" );
- assert.throws(function() {
- jQuery.parseJSON("{a:1}");
+ assert.throws( function() {
+ jQuery.parseJSON( "{a:1}" );
}, null, "Unquoted property raises an error" );
- assert.throws(function() {
- jQuery.parseJSON("{'a':1}");
+ assert.throws( function() {
+ jQuery.parseJSON( "{'a':1}" );
}, null, "Single-quoted property raises an error" );
- assert.throws(function() {
- jQuery.parseJSON("[,]");
+ assert.throws( function() {
+ jQuery.parseJSON( "[,]" );
}, null, "Array element elision raises an error" );
- assert.throws(function() {
- jQuery.parseJSON("{},[]");
+ assert.throws( function() {
+ jQuery.parseJSON( "{},[]" );
}, null, "Comma expression raises an error" );
- assert.throws(function() {
- jQuery.parseJSON("[]\n,{}");
+ assert.throws( function() {
+ jQuery.parseJSON( "[]\n,{}" );
}, null, "Newline-containing comma expression raises an error" );
- assert.throws(function() {
- jQuery.parseJSON("\"\"\n\"\"");
+ assert.throws( function() {
+ jQuery.parseJSON( "\"\"\n\"\"" );
}, null, "Automatic semicolon insertion raises an error" );
- assert.strictEqual( jQuery.parseJSON([ 0 ]), 0, "Input cast to string" );
-});
+ assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" );
+} );
-QUnit.test("jQuery.parseXML", function( assert ){
+QUnit.test( "jQuery.parseXML", function( assert ) {
assert.expect( 8 );
var xml, tmp;
@@ -1492,13 +1498,13 @@ QUnit.test("jQuery.parseXML", function( assert ){
tmp = tmp.getElementsByTagName( "b" )[ 0 ];
assert.ok( !!tmp, "<b> present in document" );
assert.strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" );
- } catch (e) {
+ } catch ( e ) {
assert.strictEqual( e, undefined, "unexpected error" );
}
try {
xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" );
assert.ok( false, "invalid xml not detected" );
- } catch( e ) {
+ } catch ( e ) {
assert.strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" );
}
try {
@@ -1510,12 +1516,12 @@ QUnit.test("jQuery.parseXML", function( assert ){
assert.strictEqual( xml, null, "null string => null document" );
xml = jQuery.parseXML( true );
assert.strictEqual( xml, null, "non-string => null document" );
- } catch( e ) {
+ } catch ( e ) {
assert.ok( false, "empty input throws exception" );
}
-});
+} );
-QUnit.test("jQuery.camelCase()", function( assert ) {
+QUnit.test( "jQuery.camelCase()", function( assert ) {
var tests = {
"foo-bar": "fooBar",
@@ -1527,12 +1533,12 @@ QUnit.test("jQuery.camelCase()", function( assert ) {
"-ms-take": "msTake"
};
- assert.expect(7);
+ assert.expect( 7 );
jQuery.each( tests, function( key, val ) {
assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
- });
-});
+ } );
+} );
testIframeWithCallback(
"Conditional compilation compatibility (#13274)",
diff --git a/test/unit/css.js b/test/unit/css.js
index c28afd6fa..f91c50940 100644
--- a/test/unit/css.js
+++ b/test/unit/css.js
@@ -1,85 +1,85 @@
if ( jQuery.css ) {
-QUnit.module("css", { teardown: moduleTeardown });
+QUnit.module( "css", { teardown: moduleTeardown } );
-QUnit.test("css(String|Hash)", function( assert ) {
+QUnit.test( "css(String|Hash)", function( assert ) {
assert.expect( 42 );
- assert.equal( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"" );
+ assert.equal( jQuery( "#qunit-fixture" ).css( "display" ), "block", "Check for css property \"display\"" );
var $child, div, div2, width, height, child, prctval, checkval, old;
- $child = jQuery("#nothiddendivchild").css({ "width": "20%", "height": "20%" });
- assert.notEqual( $child.css("width"), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" );
- assert.notEqual( $child.css("height"), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" );
+ $child = jQuery( "#nothiddendivchild" ).css( { "width": "20%", "height": "20%" } );
+ assert.notEqual( $child.css( "width" ), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" );
+ assert.notEqual( $child.css( "height" ), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" );
div = jQuery( "<div/>" );
// These should be "auto" (or some better value)
// temporarily provide "0px" for backwards compat
- assert.equal( div.css("width"), "0px", "Width on disconnected node." );
- assert.equal( div.css("height"), "0px", "Height on disconnected node." );
+ assert.equal( div.css( "width" ), "0px", "Width on disconnected node." );
+ assert.equal( div.css( "height" ), "0px", "Height on disconnected node." );
- div.css({ "width": 4, "height": 4 });
+ div.css( { "width": 4, "height": 4 } );
- assert.equal( div.css("width"), "4px", "Width on disconnected node." );
- assert.equal( div.css("height"), "4px", "Height on disconnected node." );
+ assert.equal( div.css( "width" ), "4px", "Width on disconnected node." );
+ assert.equal( div.css( "height" ), "4px", "Height on disconnected node." );
- div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
+ div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>" ).appendTo( "body" );
- assert.equal( div2.find("input").css("height"), "20px", "Height on hidden input." );
- assert.equal( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
- assert.equal( div2.find("div").css("height"), "20px", "Height on hidden div." );
+ assert.equal( div2.find( "input" ).css( "height" ), "20px", "Height on hidden input." );
+ assert.equal( div2.find( "textarea" ).css( "height" ), "20px", "Height on hidden textarea." );
+ assert.equal( div2.find( "div" ).css( "height" ), "20px", "Height on hidden div." );
div2.remove();
// handle negative numbers by setting to zero #11604
- jQuery("#nothiddendiv").css( {"width": 1, "height": 1} );
-
- width = parseFloat(jQuery("#nothiddendiv").css("width"));
- height = parseFloat(jQuery("#nothiddendiv").css("height"));
- jQuery("#nothiddendiv").css({ "overflow":"hidden", "width": -1, "height": -1 });
- assert.equal( parseFloat(jQuery("#nothiddendiv").css("width")), 0, "Test negative width set to 0");
- assert.equal( parseFloat(jQuery("#nothiddendiv").css("height")), 0, "Test negative height set to 0");
-
- assert.equal( jQuery("<div style='display: none;'/>").css("display"), "none", "Styles on disconnected nodes");
-
- jQuery("#floatTest").css({"float": "right"});
- assert.equal( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right");
- jQuery("#floatTest").css({"font-size": "30px"});
- assert.equal( jQuery("#floatTest").css("font-size"), "30px", "Modified CSS font-size: Assert font-size is 30px");
- jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
- jQuery("#foo").css({"opacity": n});
-
- assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
- jQuery("#foo").css({"opacity": parseFloat(n)});
- assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
- });
- jQuery("#foo").css({"opacity": ""});
- assert.equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
+ jQuery( "#nothiddendiv" ).css( { "width": 1, "height": 1 } );
+
+ width = parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) );
+ height = parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) );
+ jQuery( "#nothiddendiv" ).css( { "overflow":"hidden", "width": -1, "height": -1 } );
+ assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ), 0, "Test negative width set to 0" );
+ assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ), 0, "Test negative height set to 0" );
+
+ assert.equal( jQuery( "<div style='display: none;'/>" ).css( "display" ), "none", "Styles on disconnected nodes" );
+
+ jQuery( "#floatTest" ).css( { "float": "right" } );
+ assert.equal( jQuery( "#floatTest" ).css( "float" ), "right", "Modified CSS float using \"float\": Assert float is right" );
+ jQuery( "#floatTest" ).css( { "font-size": "30px" } );
+ assert.equal( jQuery( "#floatTest" ).css( "font-size" ), "30px", "Modified CSS font-size: Assert font-size is 30px" );
+ jQuery.each( "0,0.25,0.5,0.75,1".split( "," ), function( i, n ) {
+ jQuery( "#foo" ).css( { "opacity": n } );
+
+ assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" );
+ jQuery( "#foo" ).css( { "opacity": parseFloat( n ) } );
+ assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" );
+ } );
+ jQuery( "#foo" ).css( { "opacity": "" } );
+ assert.equal( jQuery( "#foo" ).css( "opacity" ), "1", "Assert opacity is 1 when set to an empty String" );
- assert.equal( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
- jQuery("#empty").css({ "opacity": "1" });
- assert.equal( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
+ assert.equal( jQuery( "#empty" ).css( "opacity" ), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
+ jQuery( "#empty" ).css( { "opacity": "1" } );
+ assert.equal( jQuery( "#empty" ).css( "opacity" ), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
- div = jQuery("#nothiddendiv");
- child = jQuery("#nothiddendivchild");
+ div = jQuery( "#nothiddendiv" );
+ child = jQuery( "#nothiddendivchild" );
- assert.equal( parseInt(div.css("fontSize"), 10), 16, "Verify fontSize px set." );
- assert.equal( parseInt(div.css("font-size"), 10), 16, "Verify fontSize px set." );
- assert.equal( parseInt(child.css("fontSize"), 10), 16, "Verify fontSize px set." );
- assert.equal( parseInt(child.css("font-size"), 10), 16, "Verify fontSize px set." );
+ assert.equal( parseInt( div.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." );
+ assert.equal( parseInt( div.css( "font-size" ), 10 ), 16, "Verify fontSize px set." );
+ assert.equal( parseInt( child.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." );
+ assert.equal( parseInt( child.css( "font-size" ), 10 ), 16, "Verify fontSize px set." );
- child.css("height", "100%");
- assert.equal( child[0].style.height, "100%", "Make sure the height is being set correctly." );
+ child.css( "height", "100%" );
+ assert.equal( child[ 0 ].style.height, "100%", "Make sure the height is being set correctly." );
- child.attr("class", "em");
- assert.equal( parseInt(child.css("fontSize"), 10), 32, "Verify fontSize em set." );
+ child.attr( "class", "em" );
+ assert.equal( parseInt( child.css( "fontSize" ), 10 ), 32, "Verify fontSize em set." );
// Have to verify this as the result depends upon the browser's CSS
// support for font-size percentages
- child.attr("class", "prct");
- prctval = parseInt(child.css("fontSize"), 10);
+ child.attr( "class", "prct" );
+ prctval = parseInt( child.css( "fontSize" ), 10 );
checkval = 0;
if ( prctval === 16 || prctval === 24 ) {
checkval = prctval;
@@ -87,123 +87,123 @@ QUnit.test("css(String|Hash)", function( assert ) {
assert.equal( prctval, checkval, "Verify fontSize % set." );
- assert.equal( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
+ assert.equal( typeof child.css( "width" ), "string", "Make sure that a string width is returned from css('width')." );
- old = child[0].style.height;
+ old = child[ 0 ].style.height;
// Test NaN
- child.css("height", parseFloat("zoo"));
- assert.equal( child[0].style.height, old, "Make sure height isn't changed on NaN." );
+ child.css( "height", parseFloat( "zoo" ) );
+ assert.equal( child[ 0 ].style.height, old, "Make sure height isn't changed on NaN." );
// Test null
- child.css("height", null);
- assert.equal( child[0].style.height, old, "Make sure height isn't changed on null." );
+ child.css( "height", null );
+ assert.equal( child[ 0 ].style.height, old, "Make sure height isn't changed on null." );
- old = child[0].style.fontSize;
+ old = child[ 0 ].style.fontSize;
// Test NaN
- child.css("font-size", parseFloat("zoo"));
- assert.equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
+ child.css( "font-size", parseFloat( "zoo" ) );
+ assert.equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
// Test null
- child.css("font-size", null);
- assert.equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
+ child.css( "font-size", null );
+ assert.equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on null." );
assert.strictEqual( child.css( "x-fake" ), undefined, "Make sure undefined is returned from css(nonexistent)." );
- div = jQuery( "<div/>" ).css({ position: "absolute", "z-index": 1000 }).appendTo( "#qunit-fixture" );
+ div = jQuery( "<div/>" ).css( { position: "absolute", "z-index": 1000 } ).appendTo( "#qunit-fixture" );
assert.strictEqual( div.css( "z-index" ), "1000",
"Make sure that a string z-index is returned from css('z-index') (#14432)." );
-});
+} );
QUnit.test( "css() explicit and relative values", function( assert ) {
assert.expect( 29 );
- var $elem = jQuery("#nothiddendiv");
+ var $elem = jQuery( "#nothiddendiv" );
- $elem.css({ "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 });
- assert.equal( $elem.css("width"), "1px", "Initial css set or width/height works (hash)" );
- assert.equal( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" );
- assert.equal( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" );
+ $elem.css( { "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 } );
+ assert.equal( $elem.css( "width" ), "1px", "Initial css set or width/height works (hash)" );
+ assert.equal( $elem.css( "paddingLeft" ), "1px", "Initial css set of paddingLeft works (hash)" );
+ assert.equal( $elem.css( "opacity" ), "1", "Initial css set of opacity works (hash)" );
- $elem.css({ width: "+=9" });
- assert.equal( $elem.css("width"), "10px", "'+=9' on width (hash)" );
+ $elem.css( { width: "+=9" } );
+ assert.equal( $elem.css( "width" ), "10px", "'+=9' on width (hash)" );
- $elem.css({ "width": "-=9" });
- assert.equal( $elem.css("width"), "1px", "'-=9' on width (hash)" );
+ $elem.css( { "width": "-=9" } );
+ assert.equal( $elem.css( "width" ), "1px", "'-=9' on width (hash)" );
- $elem.css({ "width": "+=9px" });
- assert.equal( $elem.css("width"), "10px", "'+=9px' on width (hash)" );
+ $elem.css( { "width": "+=9px" } );
+ assert.equal( $elem.css( "width" ), "10px", "'+=9px' on width (hash)" );
- $elem.css({ "width": "-=9px" });
- assert.equal( $elem.css("width"), "1px", "'-=9px' on width (hash)" );
+ $elem.css( { "width": "-=9px" } );
+ assert.equal( $elem.css( "width" ), "1px", "'-=9px' on width (hash)" );
$elem.css( "width", "+=9" );
- assert.equal( $elem.css("width"), "10px", "'+=9' on width (params)" );
+ assert.equal( $elem.css( "width" ), "10px", "'+=9' on width (params)" );
$elem.css( "width", "-=9" ) ;
- assert.equal( $elem.css("width"), "1px", "'-=9' on width (params)" );
+ assert.equal( $elem.css( "width" ), "1px", "'-=9' on width (params)" );
$elem.css( "width", "+=9px" );
- assert.equal( $elem.css("width"), "10px", "'+=9px' on width (params)" );
+ assert.equal( $elem.css( "width" ), "10px", "'+=9px' on width (params)" );
$elem.css( "width", "-=9px" );
- assert.equal( $elem.css("width"), "1px", "'-=9px' on width (params)" );
+ assert.equal( $elem.css( "width" ), "1px", "'-=9px' on width (params)" );
$elem.css( "width", "-=-9px" );
- assert.equal( $elem.css("width"), "10px", "'-=-9px' on width (params)" );
+ assert.equal( $elem.css( "width" ), "10px", "'-=-9px' on width (params)" );
$elem.css( "width", "+=-9px" );
- assert.equal( $elem.css("width"), "1px", "'+=-9px' on width (params)" );
+ assert.equal( $elem.css( "width" ), "1px", "'+=-9px' on width (params)" );
- $elem.css({ "paddingLeft": "+=4" });
- assert.equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "+=4" } );
+ assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (hash)" );
- $elem.css({ "paddingLeft": "-=4" });
- assert.equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "-=4" } );
+ assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (hash)" );
- $elem.css({ "paddingLeft": "+=4px" });
- assert.equal( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "+=4px" } );
+ assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on paddingLeft (hash)" );
- $elem.css({ "paddingLeft": "-=4px" });
- assert.equal( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "-=4px" } );
+ assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on paddingLeft (hash)" );
- $elem.css({ "padding-left": "+=4" });
- assert.equal( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" );
+ $elem.css( { "padding-left": "+=4" } );
+ assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on padding-left (hash)" );
- $elem.css({ "padding-left": "-=4" });
- assert.equal( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" );
+ $elem.css( { "padding-left": "-=4" } );
+ assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on padding-left (hash)" );
- $elem.css({ "padding-left": "+=4px" });
- assert.equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" );
+ $elem.css( { "padding-left": "+=4px" } );
+ assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (hash)" );
- $elem.css({ "padding-left": "-=4px" });
- assert.equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" );
+ $elem.css( { "padding-left": "-=4px" } );
+ assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (hash)" );
$elem.css( "paddingLeft", "+=4" );
- assert.equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" );
+ assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (params)" );
$elem.css( "paddingLeft", "-=4" );
- assert.equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" );
+ assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (params)" );
$elem.css( "padding-left", "+=4px" );
- assert.equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" );
+ assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (params)" );
$elem.css( "padding-left", "-=4px" );
- assert.equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" );
+ assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (params)" );
- $elem.css({ "opacity": "-=0.5" });
- assert.equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" );
+ $elem.css( { "opacity": "-=0.5" } );
+ assert.equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (hash)" );
- $elem.css({ "opacity": "+=0.5" });
- assert.equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" );
+ $elem.css( { "opacity": "+=0.5" } );
+ assert.equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (hash)" );
$elem.css( "opacity", "-=0.5" );
- assert.equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" );
+ assert.equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (params)" );
$elem.css( "opacity", "+=0.5" );
- assert.equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" );
-});
+ assert.equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (params)" );
+} );
QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) {
assert.expect( 17 );
@@ -240,12 +240,12 @@ QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) {
"pc": parseFloat( $child.css( prop, "100pc" ).css( prop ) ) / 100,
"cm": parseFloat( $child.css( prop, "100cm" ).css( prop ) ) / 100,
"mm": parseFloat( $child.css( prop, "100mm" ).css( prop ) ) / 100,
- "%" : parseFloat( $child.css( prop, "100%" ).css( prop ) ) / 100
+ "%": parseFloat( $child.css( prop, "100%" ).css( prop ) ) / 100
};
};
- jQuery( "#nothiddendiv" ).css({ height: 1, padding: 0, width: 400 });
- $child.css({ height: 1, padding: 0 });
+ jQuery( "#nothiddendiv" ).css( { height: 1, padding: 0, width: 400 } );
+ $child.css( { height: 1, padding: 0 } );
getUnits( "width" );
cssCurrent = parseFloat( $child.css( "width", "50%" ).css( "width" ) );
@@ -269,44 +269,44 @@ QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) {
add( "lineHeight", 1, "cm" );
add( "lineHeight", -20, "mm" );
add( "lineHeight", 50, "%" );
-});
+} );
-QUnit.test("css(String, Object)", function( assert ) {
+QUnit.test( "css(String, Object)", function( assert ) {
assert.expect( 19 );
var j, div, display, ret, success;
- jQuery("#floatTest").css("float", "left");
- assert.equal( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left");
- jQuery("#floatTest").css("font-size", "20px");
- assert.equal( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px");
+ jQuery( "#floatTest" ).css( "float", "left" );
+ assert.equal( jQuery( "#floatTest" ).css( "float" ), "left", "Modified CSS float using \"float\": Assert float is left" );
+ jQuery( "#floatTest" ).css( "font-size", "20px" );
+ assert.equal( jQuery( "#floatTest" ).css( "font-size" ), "20px", "Modified CSS font-size: Assert font-size is 20px" );
- jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
- jQuery("#foo").css("opacity", n);
- assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
- jQuery("#foo").css("opacity", parseFloat(n));
- assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
- });
- jQuery("#foo").css("opacity", "");
- assert.equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
+ jQuery.each( "0,0.25,0.5,0.75,1".split( "," ), function( i, n ) {
+ jQuery( "#foo" ).css( "opacity", n );
+ assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" );
+ jQuery( "#foo" ).css( "opacity", parseFloat( n ) );
+ assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" );
+ } );
+ jQuery( "#foo" ).css( "opacity", "" );
+ assert.equal( jQuery( "#foo" ).css( "opacity" ), "1", "Assert opacity is 1 when set to an empty String" );
// using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
- j.css("overflow", "visible");
- assert.equal( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
- assert.equal( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
+ j = jQuery( "#nonnodes" ).contents();
+ j.css( "overflow", "visible" );
+ assert.equal( j.css( "overflow" ), "visible", "Check node,textnode,comment css works" );
+ assert.equal( jQuery( "#t2037 .hidden" ).css( "display" ), "none", "Make sure browser thinks it is hidden" );
- div = jQuery("#nothiddendiv");
- display = div.css("display");
- ret = div.css("display", undefined);
+ div = jQuery( "#nothiddendiv" );
+ display = div.css( "display" );
+ ret = div.css( "display", undefined );
assert.equal( ret, div, "Make sure setting undefined returns the original set." );
- assert.equal( div.css("display"), display, "Make sure that the display wasn't changed." );
+ assert.equal( div.css( "display" ), display, "Make sure that the display wasn't changed." );
success = true;
try {
jQuery( "#foo" ).css( "backgroundColor", "rgba(0, 0, 0, 0.1)" );
}
- catch (e) {
+ catch ( e ) {
success = false;
}
assert.ok( success, "Setting RGBA values does not throw Error (#5509)" );
@@ -314,7 +314,7 @@ QUnit.test("css(String, Object)", function( assert ) {
jQuery( "#foo" ).css( "font", "7px/21px sans-serif" );
assert.strictEqual( jQuery( "#foo" ).css( "line-height" ), "21px",
"Set font shorthand property (#14759)" );
-});
+} );
QUnit.test( "css(String, Object) with negative values", function( assert ) {
assert.expect( 4 );
@@ -329,7 +329,7 @@ QUnit.test( "css(String, Object) with negative values", function( assert ) {
jQuery( "#nothiddendiv" ).css( "left", "-20px" );
assert.equal( jQuery( "#nothiddendiv" ).css( "top" ), "-20px", "Ensure negative top values work." );
assert.equal( jQuery( "#nothiddendiv" ).css( "left" ), "-20px", "Ensure negative left values work." );
-});
+} );
QUnit.test( "css(Array)", function( assert ) {
assert.expect( 2 );
@@ -341,179 +341,179 @@ QUnit.test( "css(Array)", function( assert ) {
expectedSingle = {
"width": "16px"
},
- elem = jQuery("<div></div>").appendTo("#qunit-fixture");
+ elem = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
- assert.deepEqual( elem.css( expectedMany ).css([ "overflow", "width" ]), expectedMany, "Getting multiple element array" );
- assert.deepEqual( elem.css( expectedSingle ).css([ "width" ]), expectedSingle, "Getting single element array" );
-});
+ assert.deepEqual( elem.css( expectedMany ).css( [ "overflow", "width" ] ), expectedMany, "Getting multiple element array" );
+ assert.deepEqual( elem.css( expectedSingle ).css( [ "width" ] ), expectedSingle, "Getting single element array" );
+} );
-QUnit.test("css(String, Function)", function( assert ) {
- assert.expect(3);
+QUnit.test( "css(String, Function)", function( assert ) {
+ assert.expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
+ jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
- "<div class='cssFunction'></div></div>")
- .appendTo("body");
+ "<div class='cssFunction'></div></div>" )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css("font-size", function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( "font-size", function() {
+ var size = sizes[ index ];
index++;
return size;
- });
+ } );
index = 0;
- jQuery("#cssFunctionTest div").each(function() {
- var computedSize = jQuery(this).css("font-size"),
- expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).each( function() {
+ var computedSize = jQuery( this ).css( "font-size" ),
+ expectedSize = sizes[ index ];
assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
- });
+ } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-QUnit.test("css(String, Function) with incoming value", function( assert ) {
- assert.expect(3);
+QUnit.test( "css(String, Function) with incoming value", function( assert ) {
+ assert.expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
+ jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
- "<div class='cssFunction'></div></div>")
- .appendTo("body");
+ "<div class='cssFunction'></div></div>" )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css("font-size", function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( "font-size", function() {
+ var size = sizes[ index ];
index++;
return size;
- });
+ } );
index = 0;
- jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
- var expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( "font-size", function( i, computedSize ) {
+ var expectedSize = sizes[ index ];
assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
return computedSize;
- });
+ } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-QUnit.test("css(Object) where values are Functions", function( assert ) {
- assert.expect(3);
+QUnit.test( "css(Object) where values are Functions", function( assert ) {
+ assert.expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
+ jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
- "<div class='cssFunction'></div></div>")
- .appendTo("body");
+ "<div class='cssFunction'></div></div>" )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css({"fontSize": function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() {
+ var size = sizes[ index ];
index++;
return size;
- }});
+ } } );
index = 0;
- jQuery("#cssFunctionTest div").each(function() {
- var computedSize = jQuery(this).css("font-size"),
- expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).each( function() {
+ var computedSize = jQuery( this ).css( "font-size" ),
+ expectedSize = sizes[ index ];
assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
- });
+ } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-QUnit.test("css(Object) where values are Functions with incoming values", function( assert ) {
- assert.expect(3);
+QUnit.test( "css(Object) where values are Functions with incoming values", function( assert ) {
+ assert.expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
+ jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" +
- "<div class='cssFunction'></div></div>")
- .appendTo("body");
+ "<div class='cssFunction'></div></div>" )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css({"fontSize": function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() {
+ var size = sizes[ index ];
index++;
return size;
- }});
+ } } );
index = 0;
- jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
- var expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( { "font-size": function( i, computedSize ) {
+ var expectedSize = sizes[ index ];
assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
return computedSize;
- }});
+ } } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-QUnit.test("show(); hide()", function( assert ) {
+QUnit.test( "show(); hide()", function( assert ) {
assert.expect( 4 );
var hiddendiv, div;
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
hiddendiv.hide();
- assert.equal( hiddendiv.css("display"), "none", "Cascade-hidden div after hide()" );
+ assert.equal( hiddendiv.css( "display" ), "none", "Cascade-hidden div after hide()" );
hiddendiv.show();
- assert.equal( hiddendiv.css("display"), "none", "Show does not trump CSS cascade" );
+ assert.equal( hiddendiv.css( "display" ), "none", "Show does not trump CSS cascade" );
- div = jQuery("<div>").hide();
- assert.equal( div.css("display"), "none", "Detached div hidden" );
- div.appendTo("#qunit-fixture").show();
- assert.equal( div.css("display"), "block", "Initially-detached div after show()" );
+ div = jQuery( "<div>" ).hide();
+ assert.equal( div.css( "display" ), "none", "Detached div hidden" );
+ div.appendTo( "#qunit-fixture" ).show();
+ assert.equal( div.css( "display" ), "block", "Initially-detached div after show()" );
-});
+} );
-QUnit.test("show();", function( assert ) {
+QUnit.test( "show();", function( assert ) {
assert.expect( 18 );
var hiddendiv, div, pass, old, test;
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
- assert.equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
+ assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" );
- hiddendiv.css("display", "block");
- assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ hiddendiv.css( "display", "block" );
+ assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
hiddendiv.show();
- assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
- hiddendiv.css("display","");
+ hiddendiv.css( "display", "" );
pass = true;
- div = jQuery("#qunit-fixture div");
- div.show().each(function(){
+ div = jQuery( "#qunit-fixture div" );
+ div.show().each( function() {
if ( this.style.display === "none" ) {
pass = false;
}
- });
+ } );
assert.ok( pass, "Show" );
jQuery(
@@ -524,138 +524,138 @@ QUnit.test("show();", function( assert ) {
"<table id='test-table'></table>"
).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
- old = jQuery("#test-table").show().css("display") !== "table";
- jQuery("#test-table").remove();
+ old = jQuery( "#test-table" ).show().css( "display" ) !== "table";
+ jQuery( "#test-table" ).remove();
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : old ? "block" : "table",
- "thead" : old ? "block" : "table-header-group",
- "tbody" : old ? "block" : "table-row-group",
- "tr" : old ? "block" : "table-row",
- "th" : old ? "block" : "table-cell",
- "td" : old ? "block" : "table-cell",
- "ul" : "block",
- "li" : old ? "block" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline",
+ "code": "inline",
+ "pre": "block",
+ "span": "inline",
+ "table": old ? "block" : "table",
+ "thead": old ? "block" : "table-header-group",
+ "tbody": old ? "block" : "table-row-group",
+ "tr": old ? "block" : "table-row",
+ "th": old ? "block" : "table-cell",
+ "td": old ? "block" : "table-cell",
+ "ul": "block",
+ "li": old ? "block" : "list-item"
};
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show();
- assert.equal( elem.css("display"), expected, "Show using correct display type for " + selector );
- });
+ jQuery.each( test, function( selector, expected ) {
+ var elem = jQuery( selector, "#show-tests" ).show();
+ assert.equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
+ } );
// Make sure that showing or hiding a text node doesn't cause an error
- jQuery("<div>test</div> text <span>test</span>").show().remove();
- jQuery("<div>test</div> text <span>test</span>").hide().remove();
-});
+ jQuery( "<div>test</div> text <span>test</span>" ).show().remove();
+ jQuery( "<div>test</div> text <span>test</span>" ).hide().remove();
+} );
-QUnit.test( "show() resolves correct default display for detached nodes", function( assert ){
+QUnit.test( "show() resolves correct default display for detached nodes", function( assert ) {
assert.expect( 16 );
var div, span, tr;
- div = jQuery("<div class='hidden'>");
- div.show().appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "none",
+ div = jQuery( "<div class='hidden'>" );
+ div.show().appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "none",
"A shown-while-detached div can be hidden by the CSS cascade" );
- div = jQuery("<div><div class='hidden'></div></div>").children("div");
- div.show().appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "none",
+ div = jQuery( "<div><div class='hidden'></div></div>" ).children( "div" );
+ div.show().appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "none",
"A shown-while-detached div inside a visible div can be hidden by the CSS cascade" );
- span = jQuery("<span class='hidden'/>");
- span.show().appendTo("#qunit-fixture");
- assert.equal( span.css("display"), "none",
+ span = jQuery( "<span class='hidden'/>" );
+ span.show().appendTo( "#qunit-fixture" );
+ assert.equal( span.css( "display" ), "none",
"A shown-while-detached span can be hidden by the CSS cascade" );
- div = jQuery("div.hidden");
+ div = jQuery( "div.hidden" );
div.detach().show();
assert.ok( !div[ 0 ].style.display,
"show() does not update inline style of a cascade-hidden-before-detach div" );
- div.appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "none",
+ div.appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "none",
"A shown-while-detached cascade-hidden div is hidden after attachment" );
div.remove();
- span = jQuery("<span class='hidden'/>");
- span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture");
- assert.equal( span.css("display"), "none",
+ span = jQuery( "<span class='hidden'/>" );
+ span.appendTo( "#qunit-fixture" ).detach().show().appendTo( "#qunit-fixture" );
+ assert.equal( span.css( "display" ), "none",
"A shown-while-detached cascade-hidden span is hidden after attachment" );
span.remove();
- div = jQuery( document.createElement("div") );
- div.show().appendTo("#qunit-fixture");
+ div = jQuery( document.createElement( "div" ) );
+ div.show().appendTo( "#qunit-fixture" );
assert.ok( !div[ 0 ].style.display, "A shown-while-detached div has no inline style" );
- assert.equal( div.css("display"), "block",
+ assert.equal( div.css( "display" ), "block",
"A shown-while-detached div has default display after attachment" );
div.remove();
- div = jQuery("<div style='display: none'>");
+ div = jQuery( "<div style='display: none'>" );
div.show();
assert.equal( div[ 0 ].style.display, "",
"show() updates inline style of a detached inline-hidden div" );
- div.appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "block",
+ div.appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "block",
"A shown-while-detached inline-hidden div has default display after attachment" );
- div = jQuery("<div><div style='display: none'></div></div>").children("div");
- div.show().appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "block",
+ div = jQuery( "<div><div style='display: none'></div></div>" ).children( "div" );
+ div.show().appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "block",
"A shown-while-detached inline-hidden div inside a visible div has default display " +
"after attachment" );
- span = jQuery("<span style='display: none'/>");
+ span = jQuery( "<span style='display: none'/>" );
span.show();
assert.equal( span[ 0 ].style.display, "",
"show() updates inline style of a detached inline-hidden span" );
- span.appendTo("#qunit-fixture");
- assert.equal( span.css("display"), "inline",
+ span.appendTo( "#qunit-fixture" );
+ assert.equal( span.css( "display" ), "inline",
"A shown-while-detached inline-hidden span has default display after attachment" );
- div = jQuery("<div style='display: inline'/>");
- div.show().appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "inline",
+ div = jQuery( "<div style='display: inline'/>" );
+ div.show().appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "inline",
"show() does not update inline style of a detached inline-visible div" );
div.remove();
- tr = jQuery("<tr/>");
- jQuery("#table").append( tr );
+ tr = jQuery( "<tr/>" );
+ jQuery( "#table" ).append( tr );
tr.detach().hide().show();
assert.ok( !tr[ 0 ].style.display, "Not-hidden detached tr elements have no inline style" );
tr.remove();
- span = jQuery("<span/>").hide().show();
+ span = jQuery( "<span/>" ).hide().show();
assert.ok( !span[ 0 ].style.display, "Not-hidden detached span elements have no inline style" );
span.remove();
-});
+} );
-QUnit.test("toggle()", function( assert ) {
- assert.expect(9);
+QUnit.test( "toggle()", function( assert ) {
+ assert.expect( 9 );
var div, oldHide,
- x = jQuery("#foo");
+ x = jQuery( "#foo" );
- assert.ok( x.is(":visible"), "is visible" );
+ assert.ok( x.is( ":visible" ), "is visible" );
x.toggle();
- assert.ok( x.is(":hidden"), "is hidden" );
+ assert.ok( x.is( ":hidden" ), "is hidden" );
x.toggle();
- assert.ok( x.is(":visible"), "is visible again" );
+ assert.ok( x.is( ":visible" ), "is visible again" );
- x.toggle(true);
- assert.ok( x.is(":visible"), "is visible" );
- x.toggle(false);
- assert.ok( x.is(":hidden"), "is hidden" );
- x.toggle(true);
- assert.ok( x.is(":visible"), "is visible again" );
+ x.toggle( true );
+ assert.ok( x.is( ":visible" ), "is visible" );
+ x.toggle( false );
+ assert.ok( x.is( ":hidden" ), "is hidden" );
+ x.toggle( true );
+ assert.ok( x.is( ":visible" ), "is visible again" );
- div = jQuery("<div style='display:none'><div></div></div>").appendTo("#qunit-fixture");
- x = div.find("div");
+ div = jQuery( "<div style='display:none'><div></div></div>" ).appendTo( "#qunit-fixture" );
+ x = div.find( "div" );
assert.strictEqual( x.toggle().css( "display" ), "none", "is hidden" );
assert.strictEqual( x.toggle().css( "display" ), "block", "is visible" );
@@ -667,103 +667,104 @@ QUnit.test("toggle()", function( assert ) {
};
x.toggle( name === "show" );
jQuery.fn.hide = oldHide;
-});
+} );
-QUnit.test("hide hidden elements (bug #7141)", function( assert ) {
- assert.expect(3);
+QUnit.test( "hide hidden elements (bug #7141)", function( assert ) {
+ assert.expect( 3 );
- var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "none", "Element is hidden by default" );
+ var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "none", "Element is hidden by default" );
div.hide();
- assert.ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
+ assert.ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" );
div.show();
- assert.equal( div.css("display"), "block", "Show a double-hidden element" );
+ assert.equal( div.css( "display" ), "block", "Show a double-hidden element" );
div.remove();
-});
+} );
-QUnit.test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) {
- assert.expect(4);
+QUnit.test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) {
+ assert.expect( 4 );
- var $checkedtest = jQuery("#checkedtest");
- jQuery.css($checkedtest[0], "height");
+ var $checkedtest = jQuery( "#checkedtest" );
+ jQuery.css( $checkedtest[ 0 ], "height" );
- assert.ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
- assert.ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
- assert.ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
- assert.ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
-});
+ assert.ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." );
+ assert.ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." );
+ assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
+ assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
+} );
-QUnit.test("internal ref to elem.runtimeStyle (bug #7608)", function( assert ) {
- assert.expect(1);
+QUnit.test( "internal ref to elem.runtimeStyle (bug #7608)", function( assert ) {
+ assert.expect( 1 );
var result = true;
try {
- jQuery("#foo").css( { "width": "0%" } ).css("width");
- } catch (e) {
+ jQuery( "#foo" ).css( { "width": "0%" } ).css( "width" );
+ } catch ( e ) {
result = false;
}
assert.ok( result, "elem.runtimeStyle does not throw exception" );
-});
+} );
-QUnit.test("marginRight computed style (bug #3333)", function( assert ) {
- assert.expect(1);
+QUnit.test( "marginRight computed style (bug #3333)", function( assert ) {
+ assert.expect( 1 );
- var $div = jQuery("#foo");
- $div.css({
+ var $div = jQuery( "#foo" );
+ $div.css( {
"width": "1px",
"marginRight": 0
- });
+ } );
- assert.equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
-});
+ assert.equal( $div.css( "marginRight" ), "0px", "marginRight correctly calculated with a width and display block" );
+} );
-QUnit.test("box model properties incorrectly returning % instead of px, see #10639 and #12088", function( assert ) {
+QUnit.test( "box model properties incorrectly returning % instead of px, see #10639 and #12088", function( assert ) {
assert.expect( 2 );
- var container = jQuery("<div/>").width( 400 ).appendTo("#qunit-fixture"),
- el = jQuery("<div/>").css({ "width": "50%", "marginRight": "50%" }).appendTo( container ),
- el2 = jQuery("<div/>").css({ "width": "50%", "minWidth": "300px", "marginLeft": "25%" }).appendTo( container );
+ var container = jQuery( "<div/>" ).width( 400 ).appendTo( "#qunit-fixture" ),
+ el = jQuery( "<div/>" ).css( { "width": "50%", "marginRight": "50%" } ).appendTo( container ),
+ el2 = jQuery( "<div/>" ).css( { "width": "50%", "minWidth": "300px", "marginLeft": "25%" } ).appendTo( container );
- assert.equal( el.css("marginRight"), "200px", "css('marginRight') returning % instead of px, see #10639" );
- assert.equal( el2.css("marginLeft"), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
-});
+ assert.equal( el.css( "marginRight" ), "200px", "css('marginRight') returning % instead of px, see #10639" );
+ assert.equal( el2.css( "marginLeft" ), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
+} );
-QUnit.test("jQuery.cssProps behavior, (bug #8402)", function( assert ) {
+QUnit.test( "jQuery.cssProps behavior, (bug #8402)", function( assert ) {
assert.expect( 2 );
- var div = jQuery( "<div>" ).appendTo(document.body).css({
+ var div = jQuery( "<div>" ).appendTo( document.body ).css( {
"position": "absolute",
"top": 0,
"left": 10
- });
+ } );
jQuery.cssProps.top = "left";
- assert.equal( div.css("top"), "10px", "the fixed property is used when accessing the computed style");
- div.css("top", "100px");
- assert.equal( div[0].style.left, "100px", "the fixed property is used when setting the style");
+ assert.equal( div.css( "top" ), "10px", "the fixed property is used when accessing the computed style" );
+ div.css( "top", "100px" );
+ assert.equal( div[ 0 ].style.left, "100px", "the fixed property is used when setting the style" );
+
// cleanup jQuery.cssProps
jQuery.cssProps.top = undefined;
-});
+} );
-QUnit.test("widows & orphans #8936", function( assert ) {
+QUnit.test( "widows & orphans #8936", function( assert ) {
- var $p = jQuery("<p>").appendTo("#qunit-fixture");
+ var $p = jQuery( "<p>" ).appendTo( "#qunit-fixture" );
assert.expect( 2 );
- $p.css({
+ $p.css( {
"widows": 3,
"orphans": 3
- });
+ } );
- assert.equal( $p.css( "widows" ) || jQuery.style( $p[0], "widows" ), 3, "widows correctly set to 3" );
- assert.equal( $p.css( "orphans" ) || jQuery.style( $p[0], "orphans" ), 3, "orphans correctly set to 3" );
+ assert.equal( $p.css( "widows" ) || jQuery.style( $p[ 0 ], "widows" ), 3, "widows correctly set to 3" );
+ assert.equal( $p.css( "orphans" ) || jQuery.style( $p[ 0 ], "orphans" ), 3, "orphans correctly set to 3" );
$p.remove();
-});
+} );
-QUnit.test("can't get css for disconnected in IE<9, see #10254 and #8388", function( assert ) {
+QUnit.test( "can't get css for disconnected in IE<9, see #10254 and #8388", function( assert ) {
assert.expect( 2 );
var span, div;
@@ -772,9 +773,9 @@ QUnit.test("can't get css for disconnected in IE<9, see #10254 and #8388", funct
div = jQuery( "<div/>" ).css( "top", 10 );
assert.equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" );
-});
+} );
-QUnit.test("can't get background-position in IE<9, see #10796", function( assert ) {
+QUnit.test( "can't get background-position in IE<9, see #10796", function( assert ) {
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ),
units = [
"0 0",
@@ -791,29 +792,30 @@ QUnit.test("can't get background-position in IE<9, see #10796", function( assert
assert.expect( l );
- for( ; i < l; i++ ) {
+ for ( ; i < l; i++ ) {
div.css( "background-position", units [ i ] );
assert.ok( div.css( "background-position" ), "can't get background-position in IE<9, see #10796" );
}
-});
+} );
if ( jQuery.fn.offset ) {
- QUnit.test("percentage properties for left and top should be transformed to pixels, see #9505", function( assert ) {
+ QUnit.test( "percentage properties for left and top should be transformed to pixels, see #9505", function( assert ) {
assert.expect( 2 );
- var parent = jQuery("<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>").appendTo( "#qunit-fixture" ),
- div = jQuery("<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>").appendTo( parent );
+ var parent = jQuery( "<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>" ).appendTo( "#qunit-fixture" ),
+ div = jQuery( "<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>" ).appendTo( parent );
- assert.equal( div.css("top"), "100px", "position properties not transformed to pixels, see #9505" );
- assert.equal( div.css("left"), "100px", "position properties not transformed to pixels, see #9505" );
- });
+ assert.equal( div.css( "top" ), "100px", "position properties not transformed to pixels, see #9505" );
+ assert.equal( div.css( "left" ), "100px", "position properties not transformed to pixels, see #9505" );
+ } );
}
-QUnit.test("Do not append px (#9548, #12990)", function( assert ) {
+QUnit.test( "Do not append px (#9548, #12990)", function( assert ) {
assert.expect( 2 );
- var $div = jQuery("<div>").appendTo("#qunit-fixture");
+ var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
$div.css( "fill-opacity", 1 );
+
// Support: Android 2.3 (no support for fill-opacity)
if ( $div.css( "fill-opacity" ) ) {
assert.equal( $div.css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
@@ -822,25 +824,25 @@ QUnit.test("Do not append px (#9548, #12990)", function( assert ) {
}
$div.css( "column-count", 1 );
- if ( $div.css("column-count") ) {
- assert.equal( $div.css("column-count"), 1, "Do not append px to 'column-count'" );
+ if ( $div.css( "column-count" ) ) {
+ assert.equal( $div.css( "column-count" ), 1, "Do not append px to 'column-count'" );
} else {
assert.ok( true, "No support for column-count CSS property" );
}
-});
+} );
-QUnit.test("css('width') and css('height') should respect box-sizing, see #11004", function( assert ) {
+QUnit.test( "css('width') and css('height') should respect box-sizing, see #11004", function( assert ) {
assert.expect( 4 );
// Support: Android 2.3 (-webkit-box-sizing).
- var el_dis = jQuery("<div style='width:300px;height:300px;margin:2px;padding:2px;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>"),
- el = el_dis.clone().appendTo("#qunit-fixture");
+ var el_dis = jQuery( "<div style='width:300px;height:300px;margin:2px;padding:2px;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>" ),
+ el = el_dis.clone().appendTo( "#qunit-fixture" );
- assert.equal( el.css("width"), el.css("width", el.css("width")).css("width"), "css('width') is not respecting box-sizing, see #11004");
- assert.equal( el_dis.css("width"), el_dis.css("width", el_dis.css("width")).css("width"), "css('width') is not respecting box-sizing for disconnected element, see #11004");
- assert.equal( el.css("height"), el.css("height", el.css("height")).css("height"), "css('height') is not respecting box-sizing, see #11004");
- assert.equal( el_dis.css("height"), el_dis.css("height", el_dis.css("height")).css("height"), "css('height') is not respecting box-sizing for disconnected element, see #11004");
-});
+ assert.equal( el.css( "width" ), el.css( "width", el.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing, see #11004" );
+ assert.equal( el_dis.css( "width" ), el_dis.css( "width", el_dis.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing for disconnected element, see #11004" );
+ assert.equal( el.css( "height" ), el.css( "height", el.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing, see #11004" );
+ assert.equal( el_dis.css( "height" ), el_dis.css( "height", el_dis.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing for disconnected element, see #11004" );
+} );
testIframeWithCallback(
"css('width') should work correctly before document ready (#14084)",
@@ -857,7 +859,7 @@ testIframeWithCallback(
div = document.createElement( "div" );
div.style.width = "3.3px";
qunitFixture.appendChild( div );
- supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed(1) === "3.3";
+ supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed( 1 ) === "3.3";
qunitFixture.removeChild( div );
QUnit.test( "css('width') and css('height') should return fractional values for nodes in the document", function( assert ) {
@@ -896,23 +898,23 @@ testIframeWithCallback(
} );
} )();
-QUnit.test("certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) {
+QUnit.test( "certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) {
expect ( 3 );
- var el = jQuery("<div style='letter-spacing:normal;font-weight:normal;'>test</div>").appendTo("#qunit-fixture");
+ var el = jQuery( "<div style='letter-spacing:normal;font-weight:normal;'>test</div>" ).appendTo( "#qunit-fixture" );
- assert.ok( jQuery.isNumeric( parseFloat( el.css("letterSpacing") ) ), "css('letterSpacing') not convertable to number, see #8627" );
- assert.ok( jQuery.isNumeric( parseFloat( el.css("fontWeight") ) ), "css('fontWeight') not convertable to number, see #8627" );
+ assert.ok( jQuery.isNumeric( parseFloat( el.css( "letterSpacing" ) ) ), "css('letterSpacing') not convertable to number, see #8627" );
+ assert.ok( jQuery.isNumeric( parseFloat( el.css( "fontWeight" ) ) ), "css('fontWeight') not convertable to number, see #8627" );
assert.equal( typeof el.css( "fontWeight" ), "string", ".css() returns a string" );
-});
+} );
// only run this test in IE9
if ( document.documentMode === 9 ) {
QUnit.test( ".css('filter') returns a string in IE9, see #12537", function( assert ) {
assert.expect( 1 );
- assert.equal( jQuery("<div style='-ms-filter:\"progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)\";'></div>").css("filter"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)", "IE9 returns the correct value from css('filter')." );
- });
+ assert.equal( jQuery( "<div style='-ms-filter:\"progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)\";'></div>" ).css( "filter" ), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)", "IE9 returns the correct value from css('filter')." );
+ } );
}
QUnit.test( "cssHooks - expand", function( assert ) {
@@ -920,7 +922,7 @@ QUnit.test( "cssHooks - expand", function( assert ) {
var result,
properties = {
margin: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ],
- borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"],
+ borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth" ],
padding: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ]
};
@@ -929,70 +931,70 @@ QUnit.test( "cssHooks - expand", function( assert ) {
expected = {};
jQuery.each( keys, function( _, key ) {
expected[ key ] = 10;
- });
+ } );
result = hook.expand( 10 );
assert.deepEqual( result, expected, property + " expands properly with a number" );
jQuery.each( keys, function( _, key ) {
expected[ key ] = "10px";
- });
+ } );
result = hook.expand( "10px" );
assert.deepEqual( result, expected, property + " expands properly with '10px'" );
- expected[ keys[1] ] = expected[ keys[3] ] = "20px";
+ expected[ keys[ 1 ] ] = expected[ keys[ 3 ] ] = "20px";
result = hook.expand( "10px 20px" );
assert.deepEqual( result, expected, property + " expands properly with '10px 20px'" );
- expected[ keys[2] ] = "30px";
+ expected[ keys[ 2 ] ] = "30px";
result = hook.expand( "10px 20px 30px" );
assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px'" );
- expected[ keys[3] ] = "40px";
+ expected[ keys[ 3 ] ] = "40px";
result = hook.expand( "10px 20px 30px 40px" );
assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px 40px'" );
- });
+ } );
-});
+} );
QUnit.test( "css opacity consistency across browsers (#12685)", function( assert ) {
assert.expect( 4 );
var el,
- fixture = jQuery("#qunit-fixture");
+ fixture = jQuery( "#qunit-fixture" );
// Append style element
- jQuery("<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>").appendTo( fixture );
+ jQuery( "<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>" ).appendTo( fixture );
- el = jQuery("<div class='opacityWithSpaces_t12685'></div>").appendTo(fixture);
+ el = jQuery( "<div class='opacityWithSpaces_t12685'></div>" ).appendTo( fixture );
- assert.equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" );
- el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685");
- assert.equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" );
+ assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" );
+ el.removeClass( "opacityWithSpaces_t12685" ).addClass( "opacityNoSpaces_t12685" );
+ assert.equal( Math.round( el.css( "opacity" ) * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" );
el.css( "opacity", 0.3 );
- assert.equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" );
+ assert.equal( Math.round( el.css( "opacity" ) * 100 ), 30, "override opacity" );
el.css( "opacity", "" );
- assert.equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" );
-});
+ assert.equal( Math.round( el.css( "opacity" ) * 100 ), 20, "remove opacity override" );
+} );
QUnit.test( ":visible/:hidden selectors", function( assert ) {
assert.expect( 17 );
var $div, $table, $a;
- assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" );
- jQuery("#nothiddendiv").css({ display: "none" });
- assert.ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" );
- jQuery("#nothiddendiv").css({ "display": "block" });
- assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
- assert.ok( !jQuery(window).is(":visible"), "Calling is(':visible') on window does not throw an exception (#10267).");
- assert.ok( !jQuery(document).is(":visible"), "Calling is(':visible') on document does not throw an exception (#10267).");
+ assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
+ jQuery( "#nothiddendiv" ).css( { display: "none" } );
+ assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
+ jQuery( "#nothiddendiv" ).css( { "display": "block" } );
+ assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
+ assert.ok( !jQuery( window ).is( ":visible" ), "Calling is(':visible') on window does not throw an exception (#10267)." );
+ assert.ok( !jQuery( document ).is( ":visible" ), "Calling is(':visible') on document does not throw an exception (#10267)." );
- assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
- jQuery("#nothiddendiv").css("display", "none");
- assert.ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
- jQuery("#nothiddendiv").css("display", "block");
- assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
+ assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
+ jQuery( "#nothiddendiv" ).css( "display", "none" );
+ assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
+ jQuery( "#nothiddendiv" ).css( "display", "block" );
+ assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
assert.ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" );
$div = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" );
@@ -1005,19 +1007,19 @@ QUnit.test( ":visible/:hidden selectors", function( assert ) {
// $br = jQuery( "<br/>" ).appendTo( "#qunit-fixture" );
// ok( $br.is( ":visible" ), "br element is visible" );
- $table = jQuery("#table");
- $table.html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
- assert.equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements");
- $table.css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>");
- assert.equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible (#4512)");
+ $table = jQuery( "#table" );
+ $table.html( "<tr><td style='display:none'>cell</td><td>cell</td></tr>" );
+ assert.equal( jQuery( "#table td:visible" ).length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements" );
+ $table.css( "display", "none" ).html( "<tr><td>cell</td><td>cell</td></tr>" );
+ assert.equal( jQuery( "#table td:visible" ).length, 0, "hidden cell children not perceived as visible (#4512)" );
- t( "Is Visible", "#qunit-fixture div:visible:lt(2)", ["foo", "nothiddendiv"] );
+ t( "Is Visible", "#qunit-fixture div:visible:lt(2)", [ "foo", "nothiddendiv" ] );
t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
- t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
+ t( "Is Hidden", "#form input:hidden", [ "hidden1","hidden2" ] );
$a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
assert.ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
-});
+} );
QUnit.test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function( assert ) {
assert.expect( 2 );
@@ -1027,56 +1029,59 @@ QUnit.test( "Keep the last style if the new one isn't recognized by the browser
assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting an unrecognized value" );
el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", " " );
assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting to a space" );
-});
+} );
QUnit.test( "Reset the style if set to an empty string", function( assert ) {
assert.expect( 1 );
var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "" );
+
// Some browsers return an empty string; others "static". Both those cases mean the style
// was reset successfully so accept them both.
assert.equal( el.css( "position" ) || "static", "static",
"The style can be reset by setting to an empty string" );
-});
+} );
QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function( assert ) {
var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ),
- styles = [{
+ styles = [ {
name: "backgroundAttachment",
- value: ["fixed"],
+ value: [ "fixed" ],
expected: [ "scroll" ]
},{
name: "backgroundColor",
value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
- expected: ["transparent"]
+ expected: [ "transparent" ]
}, {
+
// Firefox returns auto's value
name: "backgroundImage",
value: [ "url('test.png')", "url(" + baseUrl + "test.png)", "url(\"" + baseUrl + "test.png\")" ],
expected: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ]
}, {
name: "backgroundPosition",
- value: ["5% 5%"],
+ value: [ "5% 5%" ],
expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
}, {
+
// Firefox returns no-repeat
name: "backgroundRepeat",
- value: ["repeat-y"],
+ value: [ "repeat-y" ],
expected: [ "repeat", "no-repeat" ]
}, {
name: "backgroundClip",
- value: ["padding-box"],
- expected: ["border-box"]
+ value: [ "padding-box" ],
+ expected: [ "border-box" ]
}, {
name: "backgroundOrigin",
- value: ["content-box"],
- expected: ["padding-box"]
+ value: [ "content-box" ],
+ expected: [ "padding-box" ]
}, {
name: "backgroundSize",
- value: ["80px 60px"],
+ value: [ "80px 60px" ],
expected: [ "auto auto" ]
- }];
+ } ];
- jQuery.each(styles, function( index, style ) {
+ jQuery.each( styles, function( index, style ) {
var $clone, $clonedChildren,
$source = jQuery( "#firstp" ),
source = $source[ 0 ],
@@ -1100,7 +1105,7 @@ QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original
$clone.css( style.name, "" );
$clonedChildren.css( style.name, "" );
- window.setTimeout(function() {
+ window.setTimeout( function() {
assert.notEqual( $clone.css( style.name ), style.value[ 0 ], "Cloned css was changed" );
assert.ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ),
@@ -1113,10 +1118,10 @@ QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original
"; result: " + $children.css( style.name ) +
"; expected: " + style.value.join( "," ) );
}, 100 );
- });
+ } );
window.setTimeout( start, 1000 );
-});
+} );
QUnit.test( "show() after hide() should always set display to initial value (#14750)", function( assert ) {
assert.expect( 1 );
@@ -1128,13 +1133,13 @@ QUnit.test( "show() after hide() should always set display to initial value (#14
div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show();
assert.equal( div.css( "display" ), "list-item", "should get last set display value" );
-});
+} );
// Support: IE < 11
// We have to jump through the hoops here in order to test work with "order" CSS property,
// that some browsers do not support. This test is not, strictly speaking, correct,
// but it's the best that we can do.
-(function() {
+( function() {
var style = document.createElement( "div" ).style,
exist = "order" in style || "WebkitOrder" in style;
@@ -1146,9 +1151,9 @@ QUnit.test( "show() after hide() should always set display to initial value (#14
$elem.css( "order", 2 );
assert.equal( $elem.css( "order" ), "2", "2 on order" );
- });
+ } );
}
-})();
+} )();
QUnit.test( "Do not throw on frame elements from css method (#15098)", function( assert ) {
assert.expect( 1 );
@@ -1173,7 +1178,7 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function(
} catch ( _ ) {
assert.ok( false, "It did throw" );
}
-});
+} );
( function() {
var vendorPrefixes = [ "Webkit", "Moz", "ms" ];
@@ -1186,6 +1191,7 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function(
}
QUnit.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert ) {
+
// Note: this test needs a property we know is only supported in a prefixed version
// by at least one of our main supported browsers. This may get out of date so let's
// use -(webkit|moz)-appearance as well as those two are not on a standards track.
diff --git a/test/unit/data.js b/test/unit/data.js
index 21f760473..3a90c0054 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -1,13 +1,13 @@
-QUnit.module("data", { teardown: moduleTeardown });
+QUnit.module( "data", { teardown: moduleTeardown } );
-QUnit.test("expando", function( assert ){
- assert.expect(1);
+QUnit.test( "expando", function( assert ) {
+ assert.expect( 1 );
- assert.equal(jQuery.expando !== undefined, true, "jQuery is exposing the expando");
-});
+ assert.equal( jQuery.expando !== undefined, true, "jQuery is exposing the expando" );
+} );
QUnit.test( "jQuery.data & removeData, expected returns", function( assert ) {
- assert.expect(4);
+ assert.expect( 4 );
var elem = document.body;
assert.equal(
@@ -19,7 +19,7 @@ QUnit.test( "jQuery.data & removeData, expected returns", function( assert ) {
"jQuery.data( elem, key ) returns value"
);
assert.deepEqual(
- jQuery.data( elem, { goodnight: "moon" }), { goodnight: "moon" },
+ jQuery.data( elem, { goodnight: "moon" } ), { goodnight: "moon" },
"jQuery.data( elem, obj ) returns obj"
);
assert.equal(
@@ -27,10 +27,10 @@ QUnit.test( "jQuery.data & removeData, expected returns", function( assert ) {
"jQuery.removeData( elem, key, value ) returns undefined"
);
-});
+} );
QUnit.test( "jQuery._data & _removeData, expected returns", function( assert ) {
- assert.expect(4);
+ assert.expect( 4 );
var elem = document.body;
assert.equal(
@@ -42,17 +42,17 @@ QUnit.test( "jQuery._data & _removeData, expected returns", function( assert ) {
"jQuery._data( elem, key ) returns value"
);
assert.deepEqual(
- jQuery._data( elem, { goodnight: "moon" }), { goodnight: "moon" },
+ jQuery._data( elem, { goodnight: "moon" } ), { goodnight: "moon" },
"jQuery._data( elem, obj ) returns obj"
);
assert.equal(
jQuery._removeData( elem, "hello" ), undefined,
"jQuery._removeData( elem, key, value ) returns undefined"
);
-});
+} );
QUnit.test( "jQuery.hasData no side effects", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var obj = {};
jQuery.hasData( obj );
@@ -60,44 +60,44 @@ QUnit.test( "jQuery.hasData no side effects", function( assert ) {
assert.equal( Object.getOwnPropertyNames( obj ).length, 0,
"No data expandos where added when calling jQuery.hasData(o)"
);
-});
+} );
function dataTests( elem, assert ) {
var dataObj, internalDataObj;
- assert.equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
- assert.strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" );
+ assert.equal( jQuery.data( elem, "foo" ), undefined, "No data exists initially" );
+ assert.strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists initially" );
- dataObj = jQuery.data(elem);
+ dataObj = jQuery.data( elem );
assert.equal( typeof dataObj, "object", "Calling data with no args gives us a data object reference" );
- assert.strictEqual( jQuery.data(elem), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
+ assert.strictEqual( jQuery.data( elem ), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
- assert.strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
+ assert.strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
- dataObj["foo"] = "bar";
- assert.equal( jQuery.data(elem, "foo"), "bar", "Data is readable by jQuery.data when set directly on a returned data object" );
+ dataObj[ "foo" ] = "bar";
+ assert.equal( jQuery.data( elem, "foo" ), "bar", "Data is readable by jQuery.data when set directly on a returned data object" );
- assert.strictEqual( jQuery.hasData(elem), true, "jQuery.hasData agrees data exists when data exists" );
+ assert.strictEqual( jQuery.hasData( elem ), true, "jQuery.hasData agrees data exists when data exists" );
- jQuery.data(elem, "foo", "baz");
- assert.equal( jQuery.data(elem, "foo"), "baz", "Data can be changed by jQuery.data" );
- assert.equal( dataObj["foo"], "baz", "Changes made through jQuery.data propagate to referenced data object" );
+ jQuery.data( elem, "foo", "baz" );
+ assert.equal( jQuery.data( elem, "foo" ), "baz", "Data can be changed by jQuery.data" );
+ assert.equal( dataObj[ "foo" ], "baz", "Changes made through jQuery.data propagate to referenced data object" );
- jQuery.data(elem, "foo", undefined);
- assert.equal( jQuery.data(elem, "foo"), "baz", "Data is not unset by passing undefined to jQuery.data" );
+ jQuery.data( elem, "foo", undefined );
+ assert.equal( jQuery.data( elem, "foo" ), "baz", "Data is not unset by passing undefined to jQuery.data" );
- jQuery.data(elem, "foo", null);
- assert.strictEqual( jQuery.data(elem, "foo"), null, "Setting null using jQuery.data works OK" );
+ jQuery.data( elem, "foo", null );
+ assert.strictEqual( jQuery.data( elem, "foo" ), null, "Setting null using jQuery.data works OK" );
- jQuery.data(elem, "foo", "foo1");
+ jQuery.data( elem, "foo", "foo1" );
- jQuery.data(elem, { "bar" : "baz", "boom" : "bloz" });
- assert.strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" );
- assert.equal( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" );
+ jQuery.data( elem, { "bar": "baz", "boom": "bloz" } );
+ assert.strictEqual( jQuery.data( elem, "foo" ), "foo1", "Passing an object extends the data object instead of replacing it" );
+ assert.equal( jQuery.data( elem, "boom" ), "bloz", "Extending the data object works" );
- jQuery._data(elem, "foo", "foo2", true);
- assert.equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" );
- assert.equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" );
+ jQuery._data( elem, "foo", "foo2", true );
+ assert.equal( jQuery._data( elem, "foo" ), "foo2", "Setting internal data works" );
+ assert.equal( jQuery.data( elem, "foo" ), "foo1", "Setting internal data does not override user data" );
internalDataObj = jQuery._data( elem );
assert.ok( internalDataObj, "Internal data object exists" );
@@ -105,31 +105,31 @@ function dataTests( elem, assert ) {
assert.strictEqual( elem.boom, undefined, "Data is never stored directly on the object" );
- jQuery.removeData(elem, "foo");
- assert.strictEqual( jQuery.data(elem, "foo"), undefined, "jQuery.removeData removes single properties" );
+ jQuery.removeData( elem, "foo" );
+ assert.strictEqual( jQuery.data( elem, "foo" ), undefined, "jQuery.removeData removes single properties" );
- jQuery.removeData(elem);
- assert.strictEqual( jQuery._data(elem), internalDataObj, "jQuery.removeData does not remove internal data if it exists" );
+ jQuery.removeData( elem );
+ assert.strictEqual( jQuery._data( elem ), internalDataObj, "jQuery.removeData does not remove internal data if it exists" );
- jQuery.data(elem, "foo", "foo1");
- jQuery._data(elem, "foo", "foo2");
+ jQuery.data( elem, "foo", "foo1" );
+ jQuery._data( elem, "foo", "foo2" );
- assert.equal( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" );
- assert.equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
+ assert.equal( jQuery.data( elem, "foo" ), "foo1", "(sanity check) Ensure data is set in user data object" );
+ assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" );
- assert.strictEqual( jQuery._data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" );
+ assert.strictEqual( jQuery._data( elem, jQuery.expando ), undefined, "Removing the last item in internal data destroys the internal data object" );
- jQuery._data(elem, "foo", "foo2");
- assert.equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
+ jQuery._data( elem, "foo", "foo2" );
+ assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" );
- jQuery.removeData(elem, "foo");
- assert.equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" );
+ jQuery.removeData( elem, "foo" );
+ assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" );
}
-QUnit.test("jQuery.data(div)", function( assert ) {
+QUnit.test( "jQuery.data(div)", function( assert ) {
assert.expect( 25 );
- var div = document.createElement("div");
+ var div = document.createElement( "div" );
dataTests( div, assert );
@@ -137,15 +137,15 @@ QUnit.test("jQuery.data(div)", function( assert ) {
// assert that nothing else was put in there, and that that
// one stayed there.
QUnit.expectJqData( this, div, "foo" );
-});
+} );
-QUnit.test("jQuery.data({})", function( assert ) {
+QUnit.test( "jQuery.data({})", function( assert ) {
assert.expect( 25 );
dataTests( {}, assert );
-});
+} );
-QUnit.test("jQuery.data(window)", function( assert ) {
+QUnit.test( "jQuery.data(window)", function( assert ) {
assert.expect( 25 );
// remove bound handlers from window object to stop potential false positives caused by fix for #5280 in
@@ -153,66 +153,66 @@ QUnit.test("jQuery.data(window)", function( assert ) {
jQuery( window ).off( "unload" );
dataTests( window, assert );
-});
+} );
-QUnit.test("jQuery.data(document)", function( assert ) {
+QUnit.test( "jQuery.data(document)", function( assert ) {
assert.expect( 25 );
dataTests( document, assert );
QUnit.expectJqData( this, document, "foo" );
-});
+} );
-QUnit.test("jQuery.data(<embed>)", function( assert ) {
+QUnit.test( "jQuery.data(<embed>)", function( assert ) {
assert.expect( 25 );
- dataTests( document.createElement("embed"), assert );
-});
+ dataTests( document.createElement( "embed" ), assert );
+} );
-QUnit.test("jQuery.data(object/flash)", function( assert ) {
+QUnit.test( "jQuery.data(object/flash)", function( assert ) {
assert.expect( 25 );
- var flash = document.createElement("object");
+ var flash = document.createElement( "object" );
flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" );
dataTests( flash, assert );
-});
+} );
// attempting to access the data of an undefined jQuery element should be undefined
-QUnit.test("jQuery().data() === undefined (#14101)", function( assert ) {
+QUnit.test( "jQuery().data() === undefined (#14101)", function( assert ) {
assert.expect( 2 );
- assert.strictEqual(jQuery().data(), undefined);
- assert.strictEqual(jQuery().data("key"), undefined);
-});
+ assert.strictEqual( jQuery().data(), undefined );
+ assert.strictEqual( jQuery().data( "key" ), undefined );
+} );
-QUnit.test(".data()", function( assert ) {
- assert.expect(5);
+QUnit.test( ".data()", function( assert ) {
+ assert.expect( 5 );
var div, dataObj, nodiv, obj;
- div = jQuery("#foo");
- assert.strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
- div.data("test", "success");
+ div = jQuery( "#foo" );
+ assert.strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is undefined" );
+ div.data( "test", "success" );
dataObj = div.data();
- assert.deepEqual( dataObj, {test: "success"}, "data() returns entire data object with expected properties" );
- assert.strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
+ assert.deepEqual( dataObj, { test: "success" }, "data() returns entire data object with expected properties" );
+ assert.strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is still undefined" );
- nodiv = jQuery("#unfound");
+ nodiv = jQuery( "#unfound" );
assert.equal( nodiv.data(), null, "data() on empty set returns null" );
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() );
assert.deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
-});
+} );
function testDataTypes( $obj, assert ) {
- jQuery.each({
+ jQuery.each( {
"null": null,
"true": true,
"false": false,
@@ -220,90 +220,90 @@ function testDataTypes( $obj, assert ) {
"one": 1,
"empty string": "",
"empty array": [],
- "array": [1],
+ "array": [ 1 ],
"empty object": {},
"object": { foo: "bar" },
"date": new Date(),
"regex": /test/,
"function": function() {}
}, function( type, value ) {
- assert.strictEqual( $obj.data( "test", value ).data("test"), value, "Data set to " + type );
- });
+ assert.strictEqual( $obj.data( "test", value ).data( "test" ), value, "Data set to " + type );
+ } );
}
-QUnit.test("jQuery(Element).data(String, Object).data(String)", function( assert ) {
+QUnit.test( "jQuery(Element).data(String, Object).data(String)", function( assert ) {
assert.expect( 18 );
- var parent = jQuery("<div><div></div></div>"),
+ var parent = jQuery( "<div><div></div></div>" ),
div = parent.children();
- assert.strictEqual( div.data("test"), undefined, "No data exists initially" );
- assert.strictEqual( div.data("test", "success").data("test"), "success", "Data added" );
- assert.strictEqual( div.data("test", "overwritten").data("test"), "overwritten", "Data overwritten" );
- assert.strictEqual( div.data("test", undefined).data("test"), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)");
- assert.strictEqual( div.data("notexist"), undefined, "No data exists for unset key" );
+ assert.strictEqual( div.data( "test" ), undefined, "No data exists initially" );
+ assert.strictEqual( div.data( "test", "success" ).data( "test" ), "success", "Data added" );
+ assert.strictEqual( div.data( "test", "overwritten" ).data( "test" ), "overwritten", "Data overwritten" );
+ assert.strictEqual( div.data( "test", undefined ).data( "test" ), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)" );
+ assert.strictEqual( div.data( "notexist" ), undefined, "No data exists for unset key" );
testDataTypes( div, assert );
parent.remove();
-});
+} );
-QUnit.test("jQuery(plain Object).data(String, Object).data(String)", function( assert ) {
+QUnit.test( "jQuery(plain Object).data(String, Object).data(String)", function( assert ) {
assert.expect( 16 );
// #3748
- var $obj = jQuery({ exists: true });
- assert.strictEqual( $obj.data("nothing"), undefined, "Non-existent data returns undefined");
- assert.strictEqual( $obj.data("exists"), undefined, "Object properties are not returned as data" );
+ var $obj = jQuery( { exists: true } );
+ assert.strictEqual( $obj.data( "nothing" ), undefined, "Non-existent data returns undefined" );
+ assert.strictEqual( $obj.data( "exists" ), undefined, "Object properties are not returned as data" );
testDataTypes( $obj, assert );
// Clean up
$obj.removeData();
- assert.deepEqual( $obj[0], { exists: true }, "removeData does not clear the object" );
-});
+ assert.deepEqual( $obj[ 0 ], { exists: true }, "removeData does not clear the object" );
+} );
-QUnit.test(".data(object) does not retain references. #13815", function( assert ) {
+QUnit.test( ".data(object) does not retain references. #13815", function( assert ) {
assert.expect( 2 );
- var $divs = jQuery("<div></div><div></div>").appendTo("#qunit-fixture");
+ var $divs = jQuery( "<div></div><div></div>" ).appendTo( "#qunit-fixture" );
- $divs.data({ "type": "foo" });
+ $divs.data( { "type": "foo" } );
$divs.eq( 0 ).data( "type", "bar" );
- assert.equal( $divs.eq( 0 ).data("type"), "bar", "Correct updated value" );
- assert.equal( $divs.eq( 1 ).data("type"), "foo", "Original value retained" );
-});
+ assert.equal( $divs.eq( 0 ).data( "type" ), "bar", "Correct updated value" );
+ assert.equal( $divs.eq( 1 ).data( "type" ), "foo", "Original value retained" );
+} );
-QUnit.test("data-* attributes", function( assert ) {
+QUnit.test( "data-* attributes", function( assert ) {
assert.expect( 46 );
var prop, i, l, metadata, elem,
obj, obj2, check, num, num2,
parseJSON = jQuery.parseJSON,
- div = jQuery("<div>"),
- child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>"),
- dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>");
+ div = jQuery( "<div>" ),
+ child = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>" ),
+ dummy = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>" );
- assert.equal( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
+ assert.equal( div.data( "attr" ), undefined, "Check for non-existing data-attr attribute" );
- div.attr("data-attr", "exists");
- assert.equal( div.data("attr"), "exists", "Check for existing data-attr attribute" );
+ div.attr( "data-attr", "exists" );
+ assert.equal( div.data( "attr" ), "exists", "Check for existing data-attr attribute" );
- div.attr("data-attr", "exists2");
- assert.equal( div.data("attr"), "exists", "Check that updates to data- don't update .data()" );
+ div.attr( "data-attr", "exists2" );
+ assert.equal( div.data( "attr" ), "exists", "Check that updates to data- don't update .data()" );
- div.data("attr", "internal").attr("data-attr", "external");
- assert.equal( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
+ div.data( "attr", "internal" ).attr( "data-attr", "external" );
+ assert.equal( div.data( "attr" ), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
div.remove();
- child.appendTo("#qunit-fixture");
- assert.equal( child.data("myobj"), "old data", "Value accessed from data-* attribute");
- assert.equal( child.data("foo-42"), "boosh", "camelCasing does not affect numbers (#1751)" );
+ child.appendTo( "#qunit-fixture" );
+ assert.equal( child.data( "myobj" ), "old data", "Value accessed from data-* attribute" );
+ assert.equal( child.data( "foo-42" ), "boosh", "camelCasing does not affect numbers (#1751)" );
- child.data("myobj", "replaced");
- assert.equal( child.data("myobj"), "replaced", "Original data overwritten");
+ child.data( "myobj", "replaced" );
+ assert.equal( child.data( "myobj" ), "replaced", "Original data overwritten" );
- child.data("ignored", "cache");
- assert.equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback");
+ child.data( "ignored", "cache" );
+ assert.equal( child.data( "ignored" ), "cache", "Cached data used before DOM data-* fallback" );
obj = child.data();
obj2 = dummy.data();
@@ -314,8 +314,8 @@ QUnit.test("data-* attributes", function( assert ) {
dummy.remove();
for ( i = 0, l = check.length; i < l; i++ ) {
- assert.ok( obj[ check[i] ], "Make sure data- property exists when calling data-." );
- assert.ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
+ assert.ok( obj[ check[ i ] ], "Make sure data- property exists when calling data-." );
+ assert.ok( obj2[ check[ i ] ], "Make sure data- property exists when calling data-." );
}
for ( prop in obj ) {
@@ -330,9 +330,9 @@ QUnit.test("data-* attributes", function( assert ) {
assert.equal( num2, check.length, "Make sure that the right number of properties came through." );
- child.attr("data-other", "newvalue");
+ child.attr( "data-other", "newvalue" );
- assert.equal( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." );
+ assert.equal( child.data( "other" ), "test", "Make sure value was pulled in properly from a .data()." );
// attribute parsing
i = 0;
@@ -342,221 +342,221 @@ QUnit.test("data-* attributes", function( assert ) {
};
child
- .attr("data-true", "true")
- .attr("data-false", "false")
- .attr("data-five", "5")
- .attr("data-point", "5.5")
- .attr("data-pointe", "5.5E3")
- .attr("data-grande", "5.574E9")
- .attr("data-hexadecimal", "0x42")
- .attr("data-pointbad", "5..5")
- .attr("data-pointbad2", "-.")
- .attr("data-bigassnum", "123456789123456789123456789")
- .attr("data-badjson", "{123}")
- .attr("data-badjson2", "[abc]")
- .attr("data-notjson", " {}")
- .attr("data-notjson2", "[] ")
- .attr("data-empty", "")
- .attr("data-space", " ")
- .attr("data-null", "null")
- .attr("data-string", "test");
-
- assert.strictEqual( child.data("true"), true, "Primitive true read from attribute");
- assert.strictEqual( child.data("false"), false, "Primitive false read from attribute");
- assert.strictEqual( child.data("five"), 5, "Integer read from attribute");
- assert.strictEqual( child.data("point"), 5.5, "Floating-point number read from attribute");
- assert.strictEqual( child.data("pointe"), "5.5E3",
- "Exponential-notation number read from attribute as string");
- assert.strictEqual( child.data("grande"), "5.574E9",
- "Big exponential-notation number read from attribute as string");
- assert.strictEqual( child.data("hexadecimal"), "0x42",
- "Hexadecimal number read from attribute as string");
- assert.strictEqual( child.data("pointbad"), "5..5",
- "Extra-point non-number read from attribute as string");
- assert.strictEqual( child.data("pointbad2"), "-.",
- "No-digit non-number read from attribute as string");
- assert.strictEqual( child.data("bigassnum"), "123456789123456789123456789",
- "Bad bigass number read from attribute as string");
- assert.strictEqual( child.data("badjson"), "{123}", "Bad JSON object read from attribute as string");
- assert.strictEqual( child.data("badjson2"), "[abc]", "Bad JSON array read from attribute as string");
- assert.strictEqual( child.data("notjson"), " {}",
- "JSON object with leading non-JSON read from attribute as string");
- assert.strictEqual( child.data("notjson2"), "[] ",
- "JSON array with trailing non-JSON read from attribute as string");
- assert.strictEqual( child.data("empty"), "", "Empty string read from attribute");
- assert.strictEqual( child.data("space"), " ", "Whitespace string read from attribute");
- assert.strictEqual( child.data("null"), null, "Primitive null read from attribute");
- assert.strictEqual( child.data("string"), "test", "Typical string read from attribute");
+ .attr( "data-true", "true" )
+ .attr( "data-false", "false" )
+ .attr( "data-five", "5" )
+ .attr( "data-point", "5.5" )
+ .attr( "data-pointe", "5.5E3" )
+ .attr( "data-grande", "5.574E9" )
+ .attr( "data-hexadecimal", "0x42" )
+ .attr( "data-pointbad", "5..5" )
+ .attr( "data-pointbad2", "-." )
+ .attr( "data-bigassnum", "123456789123456789123456789" )
+ .attr( "data-badjson", "{123}" )
+ .attr( "data-badjson2", "[abc]" )
+ .attr( "data-notjson", " {}" )
+ .attr( "data-notjson2", "[] " )
+ .attr( "data-empty", "" )
+ .attr( "data-space", " " )
+ .attr( "data-null", "null" )
+ .attr( "data-string", "test" );
+
+ assert.strictEqual( child.data( "true" ), true, "Primitive true read from attribute" );
+ assert.strictEqual( child.data( "false" ), false, "Primitive false read from attribute" );
+ assert.strictEqual( child.data( "five" ), 5, "Integer read from attribute" );
+ assert.strictEqual( child.data( "point" ), 5.5, "Floating-point number read from attribute" );
+ assert.strictEqual( child.data( "pointe" ), "5.5E3",
+ "Exponential-notation number read from attribute as string" );
+ assert.strictEqual( child.data( "grande" ), "5.574E9",
+ "Big exponential-notation number read from attribute as string" );
+ assert.strictEqual( child.data( "hexadecimal" ), "0x42",
+ "Hexadecimal number read from attribute as string" );
+ assert.strictEqual( child.data( "pointbad" ), "5..5",
+ "Extra-point non-number read from attribute as string" );
+ assert.strictEqual( child.data( "pointbad2" ), "-.",
+ "No-digit non-number read from attribute as string" );
+ assert.strictEqual( child.data( "bigassnum" ), "123456789123456789123456789",
+ "Bad bigass number read from attribute as string" );
+ assert.strictEqual( child.data( "badjson" ), "{123}", "Bad JSON object read from attribute as string" );
+ assert.strictEqual( child.data( "badjson2" ), "[abc]", "Bad JSON array read from attribute as string" );
+ assert.strictEqual( child.data( "notjson" ), " {}",
+ "JSON object with leading non-JSON read from attribute as string" );
+ assert.strictEqual( child.data( "notjson2" ), "[] ",
+ "JSON array with trailing non-JSON read from attribute as string" );
+ assert.strictEqual( child.data( "empty" ), "", "Empty string read from attribute" );
+ assert.strictEqual( child.data( "space" ), " ", "Whitespace string read from attribute" );
+ assert.strictEqual( child.data( "null" ), null, "Primitive null read from attribute" );
+ assert.strictEqual( child.data( "string" ), "test", "Typical string read from attribute" );
assert.equal( i, 2, "Correct number of JSON parse attempts when reading from attributes" );
jQuery.parseJSON = parseJSON;
child.remove();
// tests from metadata plugin
- function testData(index, elem) {
- switch (index) {
+ function testData( index, elem ) {
+ switch ( index ) {
case 0:
- assert.equal(jQuery(elem).data("foo"), "bar", "Check foo property");
- assert.equal(jQuery(elem).data("bar"), "baz", "Check baz property");
+ assert.equal( jQuery( elem ).data( "foo" ), "bar", "Check foo property" );
+ assert.equal( jQuery( elem ).data( "bar" ), "baz", "Check baz property" );
break;
case 1:
- assert.equal(jQuery(elem).data("test"), "bar", "Check test property");
- assert.equal(jQuery(elem).data("bar"), "baz", "Check bar property");
+ assert.equal( jQuery( elem ).data( "test" ), "bar", "Check test property" );
+ assert.equal( jQuery( elem ).data( "bar" ), "baz", "Check bar property" );
break;
case 2:
- assert.equal(jQuery(elem).data("zoooo"), "bar", "Check zoooo property");
- assert.deepEqual(jQuery(elem).data("bar"), {"test":"baz"}, "Check bar property");
+ assert.equal( jQuery( elem ).data( "zoooo" ), "bar", "Check zoooo property" );
+ assert.deepEqual( jQuery( elem ).data( "bar" ), { "test":"baz" }, "Check bar property" );
break;
case 3:
- assert.equal(jQuery(elem).data("number"), true, "Check number property");
- assert.deepEqual(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
+ assert.equal( jQuery( elem ).data( "number" ), true, "Check number property" );
+ assert.deepEqual( jQuery( elem ).data( "stuff" ), [ 2,8 ], "Check stuff property" );
break;
default:
- assert.ok(false, ["Assertion failed on index ", index, ", with data"].join(""));
+ assert.ok( false, [ "Assertion failed on index ", index, ", with data" ].join( "" ) );
}
}
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();
-});
+} );
-QUnit.test(".data(Object)", function( assert ) {
- assert.expect(4);
+QUnit.test( ".data(Object)", function( assert ) {
+ assert.expect( 4 );
var obj, jqobj,
- div = jQuery("<div/>");
+ div = jQuery( "<div/>" );
- div.data({ "test": "in", "test2": "in2" });
- assert.equal( div.data("test"), "in", "Verify setting an object in data" );
- assert.equal( div.data("test2"), "in2", "Verify setting an object in data" );
+ div.data( { "test": "in", "test2": "in2" } );
+ assert.equal( div.data( "test" ), "in", "Verify setting an object in data" );
+ assert.equal( div.data( "test2" ), "in2", "Verify setting an object in data" );
- obj = {test:"unset"};
- jqobj = jQuery(obj);
+ obj = { test:"unset" };
+ jqobj = jQuery( obj );
- jqobj.data("test", "unset");
- jqobj.data({ "test": "in", "test2": "in2" });
- assert.equal( jQuery.data(obj)["test"], "in", "Verify setting an object on an object extends the data object" );
- assert.equal( obj["test2"], undefined, "Verify setting an object on an object does not extend the object" );
+ jqobj.data( "test", "unset" );
+ jqobj.data( { "test": "in", "test2": "in2" } );
+ assert.equal( jQuery.data( obj )[ "test" ], "in", "Verify setting an object on an object extends the data object" );
+ assert.equal( obj[ "test2" ], undefined, "Verify setting an object on an object does not extend the object" );
// manually clean up detached elements
div.remove();
-});
+} );
-QUnit.test("jQuery.removeData", function( assert ) {
- assert.expect(10);
+QUnit.test( "jQuery.removeData", function( assert ) {
+ assert.expect( 10 );
var obj,
- div = jQuery("#foo")[0];
- jQuery.data(div, "test", "testing");
- jQuery.removeData(div, "test");
- assert.equal( jQuery.data(div, "test"), undefined, "Check removal of data" );
+ div = jQuery( "#foo" )[ 0 ];
+ jQuery.data( div, "test", "testing" );
+ jQuery.removeData( div, "test" );
+ assert.equal( jQuery.data( div, "test" ), undefined, "Check removal of data" );
- jQuery.data(div, "test2", "testing");
+ jQuery.data( div, "test2", "testing" );
jQuery.removeData( div );
- assert.ok( !jQuery.data(div, "test2"), "Make sure that the data property no longer exists." );
+ assert.ok( !jQuery.data( div, "test2" ), "Make sure that the data property no longer exists." );
assert.ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." );
- jQuery.data(div, {
+ jQuery.data( div, {
test3: "testing",
test4: "testing"
- });
+ } );
jQuery.removeData( div, "test3 test4" );
- assert.ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete with spaces." );
+ assert.ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete with spaces." );
- jQuery.data(div, {
+ jQuery.data( div, {
test3: "testing",
test4: "testing"
- });
+ } );
jQuery.removeData( div, [ "test3", "test4" ] );
- assert.ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete by array." );
+ assert.ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete by array." );
- jQuery.data(div, {
+ jQuery.data( div, {
"test3 test4": "testing",
"test3": "testing"
- });
+ } );
jQuery.removeData( div, "test3 test4" );
- assert.ok( !jQuery.data(div, "test3 test4"), "Multiple delete with spaces deleted key with exact name" );
- assert.ok( jQuery.data(div, "test3"), "Left the partial matched key alone" );
+ assert.ok( !jQuery.data( div, "test3 test4" ), "Multiple delete with spaces deleted key with exact name" );
+ assert.ok( jQuery.data( div, "test3" ), "Left the partial matched key alone" );
obj = {};
- jQuery.data(obj, "test", "testing");
- assert.equal( jQuery(obj).data("test"), "testing", "verify data on plain object");
- jQuery.removeData(obj, "test");
- assert.equal( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" );
+ jQuery.data( obj, "test", "testing" );
+ assert.equal( jQuery( obj ).data( "test" ), "testing", "verify data on plain object" );
+ jQuery.removeData( obj, "test" );
+ assert.equal( jQuery.data( obj, "test" ), undefined, "Check removal of data on plain object" );
jQuery.data( window, "BAD", true );
jQuery.removeData( window, "BAD" );
assert.ok( !jQuery.data( window, "BAD" ), "Make sure that the value was not still set." );
-});
-
-QUnit.test(".removeData()", function( assert ) {
- assert.expect(6);
- var div = jQuery("#foo");
- div.data("test", "testing");
- div.removeData("test");
- assert.equal( div.data("test"), undefined, "Check removal of data" );
-
- div.data("test", "testing");
- div.data("test.foo", "testing2");
- div.removeData("test.bar");
- assert.equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
- assert.equal( div.data("test"), "testing", "Make sure data is intact" );
-
- div.removeData("test");
- assert.equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
- assert.equal( div.data("test"), undefined, "Make sure data is intact" );
-
- div.removeData("test.foo");
- assert.equal( div.data("test.foo"), undefined, "Make sure data is intact" );
-});
-
-if (window.JSON && window.JSON.stringify) {
- QUnit.test("JSON serialization (#8108)", function( assert ) {
- assert.expect(1);
+} );
+
+QUnit.test( ".removeData()", function( assert ) {
+ assert.expect( 6 );
+ var div = jQuery( "#foo" );
+ div.data( "test", "testing" );
+ div.removeData( "test" );
+ assert.equal( div.data( "test" ), undefined, "Check removal of data" );
+
+ div.data( "test", "testing" );
+ div.data( "test.foo", "testing2" );
+ div.removeData( "test.bar" );
+ assert.equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" );
+ assert.equal( div.data( "test" ), "testing", "Make sure data is intact" );
+
+ div.removeData( "test" );
+ assert.equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" );
+ assert.equal( div.data( "test" ), undefined, "Make sure data is intact" );
+
+ div.removeData( "test.foo" );
+ assert.equal( div.data( "test.foo" ), undefined, "Make sure data is intact" );
+} );
+
+if ( window.JSON && window.JSON.stringify ) {
+ QUnit.test( "JSON serialization (#8108)", function( assert ) {
+ assert.expect( 1 );
var obj = { "foo": "bar" };
- jQuery.data(obj, "hidden", true);
+ jQuery.data( obj, "hidden", true );
- assert.equal( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
- });
+ assert.equal( JSON.stringify( obj ), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
+ } );
}
-QUnit.test(".data should follow html5 specification regarding camel casing", function( assert ) {
- assert.expect(12);
+QUnit.test( ".data should follow html5 specification regarding camel casing", function( assert ) {
+ assert.expect( 12 );
- var div = jQuery("<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
- .prependTo("body");
+ var div = jQuery( "<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>" )
+ .prependTo( "body" );
- assert.equal( div.data()["wTF"], "ftw", "Verify single letter data-* key" );
- assert.equal( div.data()["bigALittleA"], "bouncing-b", "Verify single letter mixed data-* key" );
+ assert.equal( div.data()[ "wTF" ], "ftw", "Verify single letter data-* key" );
+ assert.equal( div.data()[ "bigALittleA" ], "bouncing-b", "Verify single letter mixed data-* key" );
- assert.equal( div.data()["foo"], "a", "Verify single word data-* key" );
- assert.equal( div.data()["fooBar"], "b", "Verify multiple word data-* key" );
- assert.equal( div.data()["fooBarBaz"], "c", "Verify multiple word data-* key" );
+ assert.equal( div.data()[ "foo" ], "a", "Verify single word data-* key" );
+ assert.equal( div.data()[ "fooBar" ], "b", "Verify multiple word data-* key" );
+ assert.equal( div.data()[ "fooBarBaz" ], "c", "Verify multiple word data-* key" );
- assert.equal( div.data("foo"), "a", "Verify single word data-* key" );
- assert.equal( div.data("fooBar"), "b", "Verify multiple word data-* key" );
- assert.equal( div.data("fooBarBaz"), "c", "Verify multiple word data-* key" );
+ assert.equal( div.data( "foo" ), "a", "Verify single word data-* key" );
+ assert.equal( div.data( "fooBar" ), "b", "Verify multiple word data-* key" );
+ assert.equal( div.data( "fooBarBaz" ), "c", "Verify multiple word data-* key" );
- div.data("foo-bar", "d");
+ div.data( "foo-bar", "d" );
- assert.equal( div.data("fooBar"), "d", "Verify updated data-* key" );
- assert.equal( div.data("foo-bar"), "d", "Verify updated data-* key" );
+ assert.equal( div.data( "fooBar" ), "d", "Verify updated data-* key" );
+ assert.equal( div.data( "foo-bar" ), "d", "Verify updated data-* key" );
- assert.equal( div.data("fooBar"), "d", "Verify updated data-* key (fooBar)" );
- assert.equal( div.data("foo-bar"), "d", "Verify updated data-* key (foo-bar)" );
+ assert.equal( div.data( "fooBar" ), "d", "Verify updated data-* key (fooBar)" );
+ assert.equal( div.data( "foo-bar" ), "d", "Verify updated data-* key (foo-bar)" );
div.remove();
-});
+} );
-QUnit.test(".data should not miss preset data-* w/ hyphenated property names", function( assert ) {
+QUnit.test( ".data should not miss preset data-* w/ hyphenated property names", function( assert ) {
- assert.expect(2);
+ assert.expect( 2 );
- var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
+ var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
test = {
"camelBar": "camelBar",
"hyphen-foo": "hyphen-foo"
@@ -564,47 +564,47 @@ QUnit.test(".data should not miss preset data-* w/ hyphenated property names", f
div.data( test );
- jQuery.each( test , function(i, k) {
- assert.equal( div.data(k), k, "data with property '"+k+"' was correctly found");
- });
-});
+ jQuery.each( test, function( i, k ) {
+ assert.equal( div.data( k ), k, "data with property '" + k + "' was correctly found" );
+ } );
+} );
-QUnit.test("jQuery.data should not miss data-* w/ hyphenated property names #14047", function( assert ) {
+QUnit.test( "jQuery.data should not miss data-* w/ hyphenated property names #14047", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
- var div = jQuery("<div/>");
+ var div = jQuery( "<div/>" );
div.data( "foo-bar", "baz" );
- assert.equal( jQuery.data(div[0], "foo-bar"), "baz", "data with property 'foo-bar' was correctly found");
-});
+ assert.equal( jQuery.data( div[ 0 ], "foo-bar" ), "baz", "data with property 'foo-bar' was correctly found" );
+} );
-QUnit.test(".data should not miss attr() set data-* with hyphenated property names", function( assert ) {
- assert.expect(2);
+QUnit.test( ".data should not miss attr() set data-* with hyphenated property names", function( assert ) {
+ assert.expect( 2 );
var a, b;
- a = jQuery("<div/>").appendTo("#qunit-fixture");
+ a = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
a.attr( "data-long-param", "test" );
- a.data( "long-param", { a: 2 });
+ a.data( "long-param", { a: 2 } );
- assert.deepEqual( a.data("long-param"), { a: 2 }, "data with property long-param was found, 1" );
+ assert.deepEqual( a.data( "long-param" ), { a: 2 }, "data with property long-param was found, 1" );
- b = jQuery("<div/>").appendTo("#qunit-fixture");
+ b = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
b.attr( "data-long-param", "test" );
b.data( "long-param" );
- b.data( "long-param", { a: 2 });
+ b.data( "long-param", { a: 2 } );
- assert.deepEqual( b.data("long-param"), { a: 2 }, "data with property long-param was found, 2" );
-});
+ assert.deepEqual( b.data( "long-param" ), { a: 2 }, "data with property long-param was found, 2" );
+} );
-QUnit.test(".data always sets data with the camelCased key (gh-2257)", function( assert ) {
+QUnit.test( ".data always sets data with the camelCased key (gh-2257)", function( assert ) {
assert.expect( 18 );
- var div = jQuery("<div>").appendTo("#qunit-fixture"),
+ var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -626,8 +626,8 @@ QUnit.test(".data always sets data with the camelCased key (gh-2257)", function(
var allData = div.data();
assert.equal( allData[ key ], undefined, ".data does not store with hyphenated keys" );
assert.equal( allData[ jQuery.camelCase( key ) ], val, ".data stores the camelCased key" );
- });
-});
+ } );
+} );
QUnit.test( ".data should not strip more than one hyphen when camelCasing (gh-2070)", function( assert ) {
assert.expect( 3 );
@@ -637,11 +637,11 @@ QUnit.test( ".data should not strip more than one hyphen when camelCasing (gh-20
assert.equal( allData.nestedSingle, "single", "Key is correctly camelCased" );
assert.equal( allData[ "nested-Double" ], "double", "Key with double hyphens is correctly camelCased" );
assert.equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
-});
+} );
-QUnit.test(".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
+QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
- var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
+ var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -651,6 +651,7 @@ QUnit.test(".data supports interoperable hyphenated/camelCase get/set of propert
"an-object": {},
"bool-true": true,
"bool-false": false,
+
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
@@ -667,11 +668,11 @@ QUnit.test(".data supports interoperable hyphenated/camelCase get/set of propert
assert.deepEqual( div.data( key ), val, "get: " + key );
assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
- });
-});
+ } );
+} );
-QUnit.test(".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) {
- var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
+QUnit.test( ".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) {
+ var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -681,6 +682,7 @@ QUnit.test(".data supports interoperable removal of hyphenated/camelCase propert
"an-object": {},
"bool-true": true,
"bool-false": false,
+
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
@@ -699,11 +701,11 @@ QUnit.test(".data supports interoperable removal of hyphenated/camelCase propert
assert.equal( div.data( key ), undefined, "get: " + key );
- });
-});
+ } );
+} );
-QUnit.test(".data supports interoperable removal of properties SET TWICE #13850", function( assert ) {
- var div = jQuery("<div>").appendTo("#qunit-fixture"),
+QUnit.test( ".data supports interoperable removal of properties SET TWICE #13850", function( assert ) {
+ var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -713,6 +715,7 @@ QUnit.test(".data supports interoperable removal of properties SET TWICE #13850"
"an-object": {},
"bool-true": true,
"bool-false": false,
+
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
@@ -728,51 +731,54 @@ QUnit.test(".data supports interoperable removal of properties SET TWICE #13850"
div.removeData( key );
assert.equal( div.data( key ), undefined, "removal: " + key );
- });
-});
+ } );
+} );
QUnit.test( ".removeData supports removal of hyphenated properties via array (#12786, gh-2257)", function( assert ) {
assert.expect( 4 );
var div, plain, compare;
- div = jQuery("<div>").appendTo("#qunit-fixture");
- plain = jQuery({});
+ div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
+ plain = jQuery( {} );
// Properties should always be camelCased
compare = {
+
// From batch assignment .data({ "a-a": 1 })
"aA": 1,
+
// From property, value assignment .data( "b-b", 1 )
"bB": 1
};
// Mixed assignment
- div.data({ "a-a": 1 }).data( "b-b", 1 );
- plain.data({ "a-a": 1 }).data( "b-b", 1 );
+ div.data( { "a-a": 1 } ).data( "b-b", 1 );
+ plain.data( { "a-a": 1 } ).data( "b-b", 1 );
assert.deepEqual( div.data(), compare, "Data appears as expected. (div)" );
assert.deepEqual( plain.data(), compare, "Data appears as expected. (plain)" );
- div.removeData([ "a-a", "b-b" ]);
- plain.removeData([ "a-a", "b-b" ]);
+ div.removeData( [ "a-a", "b-b" ] );
+ plain.removeData( [ "a-a", "b-b" ] );
assert.deepEqual( div.data(), {}, "Data is empty. (div)" );
assert.deepEqual( plain.data(), {}, "Data is empty. (plain)" );
-});
+} );
// Test originally by Moschel
-QUnit.test(".removeData should not throw exceptions. (#10080)", function( assert ) {
- assert.expect(1);
+QUnit.test( ".removeData should not throw exceptions. (#10080)", function( assert ) {
+ assert.expect( 1 );
QUnit.stop();
- var frame = jQuery("#loadediframe");
- jQuery(frame[0].contentWindow).on("unload", function() {
- assert.ok(true, "called unload");
+ var frame = jQuery( "#loadediframe" );
+ jQuery( frame[ 0 ].contentWindow ).on( "unload", function() {
+ assert.ok( true, "called unload" );
QUnit.start();
- });
+ } );
+
// change the url to trigger unload
- frame.attr("src", "data/iframe.html?param=true");
-});
+ frame.attr( "src", "data/iframe.html?param=true" );
+} );
QUnit.test( ".data only checks element attributes once. #8909", function( assert ) {
assert.expect( 2 );
@@ -792,18 +798,18 @@ QUnit.test( ".data only checks element attributes once. #8909", function( assert
// clean up data cache
element.remove();
-});
+} );
QUnit.test( "data-* with JSON value can have newlines", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
- var x = jQuery("<div data-some='{\n\"foo\":\n\t\"bar\"\n}'></div>");
- assert.equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" );
+ var x = jQuery( "<div data-some='{\n\"foo\":\n\t\"bar\"\n}'></div>" );
+ assert.equal( x.data( "some" ).foo, "bar", "got a JSON data- attribute with spaces" );
x.remove();
-});
+} );
-QUnit.test(".data doesn't throw when calling selection is empty. #13551", function( assert ) {
- assert.expect(1);
+QUnit.test( ".data doesn't throw when calling selection is empty. #13551", function( assert ) {
+ assert.expect( 1 );
try {
jQuery( null ).data( "prop" );
@@ -811,9 +817,9 @@ QUnit.test(".data doesn't throw when calling selection is empty. #13551", functi
} catch ( e ) {
assert.ok( false, e.message );
}
-});
+} );
-QUnit.test("jQuery.acceptData", function( assert ) {
+QUnit.test( "jQuery.acceptData", function( assert ) {
assert.expect( 10 );
var flash, pdf;
@@ -838,19 +844,19 @@ QUnit.test("jQuery.acceptData", function( assert ) {
assert.ok( jQuery.acceptData(
jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ] ),
"form with aliased DOM properties" );
-});
+} );
-QUnit.test("Check proper data removal of non-element descendants nodes (#8335)", function( assert ) {
+QUnit.test( "Check proper data removal of non-element descendants nodes (#8335)", function( assert ) {
assert.expect( 1 );
- var div = jQuery("<div>text</div>"),
+ var div = jQuery( "<div>text</div>" ),
text = div.contents();
text.data( "test", "test" ); // This should be a noop.
div.remove();
- assert.ok( !text.data("test"), "Be sure data is not stored in non-element" );
-});
+ assert.ok( !text.data( "test" ), "Be sure data is not stored in non-element" );
+} );
testIframeWithCallback(
"enumerate data attrs on body (#14894)",
@@ -876,4 +882,4 @@ QUnit.test( "Check that the expando is removed when there's no more data", funct
assert.ok( false, "Expando was not removed when there was no more data" );
}
}
-});
+} );
diff --git a/test/unit/deferred.js b/test/unit/deferred.js
index 83b7897af..33b5b4f16 100644
--- a/test/unit/deferred.js
+++ b/test/unit/deferred.js
@@ -1,6 +1,6 @@
QUnit.module( "deferred", {
teardown: moduleTeardown
-});
+} );
jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
@@ -16,32 +16,32 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
assert.ok( jQuery.isFunction( defer.pipe ), "defer.pipe is a function" );
- createDeferred().resolve().done(function() {
+ createDeferred().resolve().done( function() {
assert.ok( true, "Success on resolve" );
assert.strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( false, "Error on resolve" );
- }).always(function() {
+ } ).always( function() {
assert.ok( true, "Always callback on resolve" );
- });
+ } );
- createDeferred().reject().done(function() {
+ createDeferred().reject().done( function() {
assert.ok( false, "Success on reject" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( true, "Error on reject" );
assert.strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
- }).always(function() {
+ } ).always( function() {
assert.ok( true, "Always callback on reject" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
assert.ok( this === defer, "Defer passed as this & first argument" );
- this.resolve("done");
- }).done(function( value ) {
+ this.resolve( "done" );
+ } ).done( function( value ) {
assert.strictEqual( value, "done", "Passed function executed" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
var promise = defer.promise(),
func = function() {},
funcPromise = defer.promise( func );
@@ -54,17 +54,17 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
if ( promise[ key ] !== func[ key ] ) {
assert.strictEqual( func[ key ], promise[ key ], key + " is the same" );
}
- });
- });
+ } );
+ } );
jQuery.expandedEach = jQuery.each;
- jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) {
- createDeferred(function( defer ) {
+ jQuery.expandedEach( "resolve reject".split( " " ), function( _, change ) {
+ createDeferred( function( defer ) {
assert.strictEqual( defer.state(), "pending", "pending after creation" );
var checked = 0;
- defer.progress(function( value ) {
+ defer.progress( function( value ) {
assert.strictEqual( value, checked, "Progress: right value (" + value + ") received" );
- });
+ } );
for ( checked = 0; checked < 3; checked++ ) {
defer.notify( checked );
}
@@ -72,11 +72,10 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
defer[ change ]();
assert.notStrictEqual( defer.state(), "pending", "not pending after " + change );
defer.notify();
- });
- });
- });
-});
-
+ } );
+ } );
+ } );
+} );
QUnit.test( "jQuery.Deferred - chainability", function( assert ) {
@@ -85,13 +84,13 @@ QUnit.test( "jQuery.Deferred - chainability", function( assert ) {
assert.expect( 10 );
jQuery.expandedEach = jQuery.each;
- jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) {
+ jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split( " " ), function( _, method ) {
var object = {
m: defer[ method ]
};
assert.strictEqual( object.m(), object, method + " is chainable" );
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - filtering (done)", function( assert ) {
@@ -99,36 +98,36 @@ QUnit.test( "jQuery.Deferred.then - filtering (done)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer.then(function( a, b ) {
+ piped = defer.then( function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.done(function( a, b ) {
+ defer.done( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
- defer.resolve( 2, 3 ).then(function() {
+ defer.resolve( 2, 3 ).then( function() {
assert.strictEqual( value1, 2, "first resolve value ok" );
assert.strictEqual( value2, 3, "second resolve value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().reject().then(function() {
+ jQuery.Deferred().reject().then( function() {
assert.ok( false, "then should not be called on reject" );
- }).then( null, done.pop() );
+ } ).then( null, done.pop() );
- jQuery.Deferred().resolve().then( jQuery.noop ).done(function( value ) {
+ jQuery.Deferred().resolve().then( jQuery.noop ).done( function( value ) {
assert.strictEqual( value, undefined, "then done callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - filtering (fail)", function( assert ) {
@@ -138,70 +137,70 @@ QUnit.test( "jQuery.Deferred.then - filtering (fail)", function( assert ) {
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.reject( 2, 3 ).then( null, function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
jQuery.Deferred().resolve().then( null, function() {
assert.ok( false, "then should not be called on resolve" );
- }).then( done.pop() );
+ } ).then( done.pop() );
- jQuery.Deferred().reject().then( null, jQuery.noop ).done(function( value ) {
+ jQuery.Deferred().reject().then( null, jQuery.noop ).done( function( value ) {
assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.catch", function( assert ) {
assert.expect( 4 );
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer[ "catch" ](function( a, b ) {
+ piped = defer[ "catch" ]( function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
- defer.reject( 2, 3 )[ "catch" ](function() {
+ defer.reject( 2, 3 )[ "catch" ]( function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve()[ "catch" ](function() {
+ jQuery.Deferred().resolve()[ "catch" ]( function() {
assert.ok( false, "then should not be called on resolve" );
- }).then( done.pop() );
+ } ).then( done.pop() );
- jQuery.Deferred().reject()[ "catch" ]( jQuery.noop ).done(function( value ) {
+ jQuery.Deferred().reject()[ "catch" ]( jQuery.noop ).done( function( value ) {
assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert ) {
@@ -211,34 +210,34 @@ QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( ass
defer = jQuery.Deferred(),
piped = defer.pipe( null, function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.fail(function( result ) {
+ piped.fail( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.reject( 2, 3 ).pipe( null, function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
jQuery.Deferred().resolve().pipe( null, function() {
assert.ok( false, "then should not be called on resolve" );
- }).then( done.pop() );
+ } ).then( done.pop() );
- jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) {
+ jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail( function( value ) {
assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - filtering (progress)", function( assert ) {
@@ -248,25 +247,25 @@ QUnit.test( "jQuery.Deferred.then - filtering (progress)", function( assert ) {
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
return a * b;
- }),
+ } ),
done = assert.async();
- piped.progress(function( result ) {
+ piped.progress( function( result ) {
value3 = result;
- });
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 ).then( null, null, function() {
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - deferred (done)", function( assert ) {
@@ -274,31 +273,31 @@ QUnit.test( "jQuery.Deferred.then - deferred (done)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer.then(function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ piped = defer.then( function( a, b ) {
+ return jQuery.Deferred( function( defer ) {
defer.reject( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.fail(function( result ) {
+ piped.fail( function( result ) {
value3 = result;
- });
+ } );
- defer.done(function( a, b ) {
+ defer.done( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.resolve( 2, 3 );
- piped.fail(function() {
+ piped.fail( function() {
assert.strictEqual( value1, 2, "first resolve value ok" );
assert.strictEqual( value2, 3, "second resolve value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - deferred (fail)", function( assert ) {
@@ -307,30 +306,30 @@ QUnit.test( "jQuery.Deferred.then - deferred (fail)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.reject( 2, 3 );
- piped.done(function() {
+ piped.done( function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - deferred (progress)", function( assert ) {
@@ -339,38 +338,38 @@ QUnit.test( "jQuery.Deferred.then - deferred (progress)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.progress(function( result ) {
- return jQuery.Deferred().resolve().then(function() {
+ piped.progress( function( result ) {
+ return jQuery.Deferred().resolve().then( function() {
return result;
- }).then(function( result ) {
+ } ).then( function( result ) {
value3 = result;
- });
- });
+ } );
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 );
piped.then( null, null, function( result ) {
- return jQuery.Deferred().resolve().then(function() {
+ return jQuery.Deferred().resolve().then( function() {
return result;
- }).then(function() {
+ } ).then( function() {
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
- });
-});
+ } );
+ } );
+} );
QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( assert ) {
@@ -379,30 +378,30 @@ QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function(
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.pipe( null, null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 );
- piped.done(function() {
+ piped.done( function() {
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - context", function( assert ) {
@@ -412,48 +411,48 @@ QUnit.test( "jQuery.Deferred.then - context", function( assert ) {
context = {},
done = jQuery.map( new Array( 4 ), function() { return assert.async(); } );
- jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
+ jQuery.Deferred().resolveWith( context, [ 2 ] ).then( function( value ) {
return value * 3;
- }).done(function( value ) {
+ } ).done( function( value ) {
assert.notStrictEqual( this, context, "custom context not propagated through .then" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve().then(function() {
+ jQuery.Deferred().resolve().then( function() {
return jQuery.Deferred().resolveWith( context );
- }).done(function() {
+ } ).done( function() {
assert.strictEqual( this, context,
"custom context of returned deferred correctly propagated" );
done.pop().call();
- });
+ } );
defer = jQuery.Deferred();
- piped = defer.then(function( value ) {
+ piped = defer.then( function( value ) {
return value * 3;
- });
+ } );
defer.resolve( 2 );
- piped.done(function( value ) {
+ piped.done( function( value ) {
assert.strictEqual( this, piped,
"default context gets updated to latest promise in the chain" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
defer2 = jQuery.Deferred();
piped2 = defer2.then();
defer2.resolve( 2 );
- piped2.done(function( value ) {
+ piped2.done( function( value ) {
assert.strictEqual( this, piped2,
"default context updated to latest promise in the chain (without passing function)" );
assert.strictEqual( value, 2, "proper value received (without passing function)" );
done.pop().call();
- });
-});
+ } );
+} );
QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) {
@@ -463,66 +462,66 @@ QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) {
context = {},
done = jQuery.map( new Array( 4 ), function() { return assert.async(); } );
- jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) {
+ jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe( function( value ) {
return value * 3;
- }).done(function( value ) {
+ } ).done( function( value ) {
assert.strictEqual( this, context, "[PIPE ONLY] custom context correctly propagated" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve().pipe(function() {
- return jQuery.Deferred().resolveWith(context);
- }).done(function() {
+ jQuery.Deferred().resolve().pipe( function() {
+ return jQuery.Deferred().resolveWith( context );
+ } ).done( function() {
assert.strictEqual( this, context,
"custom context of returned deferred correctly propagated" );
done.pop().call();
- });
+ } );
defer = jQuery.Deferred();
- piped = defer.pipe(function( value ) {
+ piped = defer.pipe( function( value ) {
return value * 3;
- });
+ } );
defer.resolve( 2 );
- piped.done(function( value ) {
+ piped.done( function( value ) {
assert.strictEqual( this, piped,
"default context gets updated to latest promise in the chain" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
defer2 = jQuery.Deferred();
piped2 = defer2.pipe();
defer2.resolve( 2 );
- piped2.done(function( value ) {
+ piped2.done( function( value ) {
assert.strictEqual( this, piped2,
"default context updated to latest promise in the chain (without passing function)" );
assert.strictEqual( value, 2, "proper value received (without passing function)" );
done.pop().call();
- });
-});
+ } );
+} );
QUnit.asyncTest( "jQuery.Deferred.then - spec compatibility", function( assert ) {
assert.expect( 1 );
- var defer = jQuery.Deferred().done(function() {
+ var defer = jQuery.Deferred().done( function() {
setTimeout( start );
throw new Error();
- });
+ } );
- defer.then(function() {
+ defer.then( function() {
assert.ok( true, "errors in .done callbacks don't stop .then handlers" );
- });
+ } );
try {
defer.resolve();
} catch ( _ ) {}
-});
+} );
QUnit.test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) {
@@ -534,46 +533,46 @@ QUnit.test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) {
thenable.unwrapped = false;
- jQuery.Deferred().resolve( 1, 2 ).then(function() {
+ jQuery.Deferred().resolve( 1, 2 ).then( function() {
assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ],
".then fulfillment callbacks receive all resolution values" );
done.pop().call();
- });
+ } );
jQuery.Deferred().reject( 1, 2 ).then( null, function() {
assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ],
".then rejection callbacks receive all rejection values" );
done.pop().call();
- });
+ } );
jQuery.Deferred().notify( 1, 2 ).then( null, null, function() {
assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ],
".then progress callbacks receive all progress values" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolveWith( context ).then(function() {
+ jQuery.Deferred().resolveWith( context ).then( function() {
assert.deepEqual( this, context, ".then fulfillment callbacks receive context" );
done.pop().call();
- });
+ } );
jQuery.Deferred().rejectWith( context ).then( null, function() {
assert.deepEqual( this, context, ".then rejection callbacks receive context" );
done.pop().call();
- });
+ } );
jQuery.Deferred().notifyWith( context ).then( null, null, function() {
assert.deepEqual( this, context, ".then progress callbacks receive context" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve( thenable ).done(function( value ) {
+ jQuery.Deferred().resolve( thenable ).done( function( value ) {
assert.strictEqual( value, thenable, ".done doesn't unwrap thenables" );
done.pop().call();
- });
+ } );
jQuery.Deferred().notify( thenable ).then().then( null, null, function( value ) {
assert.strictEqual( value, "thenable fulfillment",
".then implicit progress callbacks unwrap thenables" );
done.pop().call();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.Deferred.then - progress and thenables", function( assert ) {
@@ -590,16 +589,16 @@ QUnit.test( "jQuery.Deferred.then - progress and thenables", function( assert )
trigger.then( null, null, function() {
var notifier = jQuery.Deferred().notify( "foo" );
- setTimeout(function() {
+ setTimeout( function() {
notifier.notify( "bar" ).resolve( "baz" );
- });
+ } );
return notifier;
- }).then( failer( "fulfill" ), failer( "reject" ), function( v ) {
+ } ).then( failer( "fulfill" ), failer( "reject" ), function( v ) {
assert.strictEqual( v, expectedProgress.shift(), "expected progress value" );
done.pop().call();
- });
+ } );
trigger.notify();
-});
+} );
QUnit.test( "jQuery.Deferred - notify and resolve", function( assert ) {
@@ -643,18 +642,19 @@ QUnit.test( "jQuery.Deferred - notify and resolve", function( assert ) {
notifiedResolved.then( null, null, function() {
return jQuery.Deferred().notify( "baz" ).resolve( "quux" );
} ).progress( function( v ) {
+
// Progress from the surrogate deferred is ignored
assert.strictEqual( v, "quux", "deferred replaced then'd progress value" );
done.pop().call();
} );
-});
+} );
QUnit.test( "jQuery.when", function( assert ) {
assert.expect( 37 );
// Some other objects
- jQuery.each({
+ jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
@@ -669,21 +669,21 @@ QUnit.test( "jQuery.when", function( assert ) {
}, function( message, value ) {
assert.ok(
jQuery.isFunction(
- jQuery.when( value ).done(function( resolveValue ) {
+ jQuery.when( value ).done( function( resolveValue ) {
assert.strictEqual( this, window, "Context is the global object with " + message );
assert.strictEqual( resolveValue, value, "Test the promise was resolved with " + message );
- }).promise
+ } ).promise
),
"Test " + message + " triggers the creation of a new Promise"
);
- });
+ } );
assert.ok(
jQuery.isFunction(
- jQuery.when().done(function( resolveValue ) {
+ jQuery.when().done( function( resolveValue ) {
assert.strictEqual( this, window, "Test the promise was resolved with window as its context" );
assert.strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" );
- }).promise
+ } ).promise
),
"Test calling when with no parameter triggers the creation of a new Promise"
);
@@ -691,23 +691,23 @@ QUnit.test( "jQuery.when", function( assert ) {
var cache,
context = {};
- jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
+ jQuery.when( jQuery.Deferred().resolveWith( context ) ).done( function() {
assert.strictEqual( this, context, "when( promise ) propagates context" );
- });
+ } );
- 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() {
this.resolve( i );
- })
- ).done(function( value ) {
+ } )
+ ).done( function( value ) {
assert.strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
- });
+ } );
- });
-});
+ } );
+} );
QUnit.test( "jQuery.when - joined", function( assert ) {
@@ -762,7 +762,7 @@ QUnit.test( "jQuery.when - joined", function( assert ) {
context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2.promise() :
( defer2.then ? window : undefined );
- jQuery.when( defer1, defer2 ).done(function( a, b ) {
+ jQuery.when( defer1, defer2 ).done( function( a, b ) {
if ( shouldResolve ) {
assert.deepEqual( [ a, b ], expected, code + " => resolve" );
assert.strictEqual( this[ 0 ], context1, code + " => first context OK" );
@@ -770,22 +770,22 @@ QUnit.test( "jQuery.when - joined", function( assert ) {
} else {
assert.ok( false, code + " => resolve" );
}
- }).fail(function( a, b ) {
+ } ).fail( function( a, b ) {
if ( shouldError ) {
assert.deepEqual( [ a, b ], expected, code + " => reject" );
} else {
assert.ok( false, code + " => reject" );
}
- }).progress(function( a, b ) {
+ } ).progress( function( a, b ) {
assert.deepEqual( [ a, b ], expectedNotify, code + " => progress" );
assert.strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" );
assert.strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" );
- }).always( restart );
- });
- });
+ } ).always( restart );
+ } );
+ } );
deferreds.eventuallyFulfilled.resolve( 1 );
deferreds.eventuallyRejected.reject( 0 );
-});
+} );
QUnit.test( "jQuery.when - resolved", function( assert ) {
@@ -795,18 +795,18 @@ QUnit.test( "jQuery.when - resolved", function( assert ) {
b = jQuery.Deferred().notify( 2 ).resolve( 5 ),
c = jQuery.Deferred().notify( 3 ).resolve( 6 );
- jQuery.when( a, b, c ).progress(function( a, b, c ) {
+ jQuery.when( a, b, c ).progress( function( a, b, c ) {
assert.strictEqual( a, 1, "first notify value ok" );
assert.strictEqual( b, 2, "second notify value ok" );
assert.strictEqual( c, 3, "third notify value ok" );
- }).done(function( a, b, c ) {
+ } ).done( function( a, b, c ) {
assert.strictEqual( a, 4, "first resolve value ok" );
assert.strictEqual( b, 5, "second resolve value ok" );
assert.strictEqual( c, 6, "third resolve value ok" );
- }).fail(function() {
+ } ).fail( function() {
assert.ok( false, "Error on resolve" );
- });
-});
+ } );
+} );
QUnit.test( "jQuery.when - filtering", function( assert ) {
@@ -821,12 +821,12 @@ QUnit.test( "jQuery.when - filtering", function( assert ) {
jQuery.when(
jQuery.Deferred().resolve( 3 ).then( increment ),
jQuery.Deferred().reject( 5 ).then( null, increment )
- ).done(function( four, six ) {
+ ).done( function( four, six ) {
assert.strictEqual( four, 4, "resolved value incremented" );
assert.strictEqual( six, 6, "rejected value incremented" );
QUnit.start();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.when - exceptions", function( assert ) {
@@ -838,14 +838,14 @@ QUnit.test( "jQuery.when - exceptions", function( assert ) {
QUnit.stop();
- jQuery.Deferred().resolve().then( woops ).fail(function( doneException ) {
+ jQuery.Deferred().resolve().then( woops ).fail( function( doneException ) {
assert.strictEqual( doneException, "exception thrown", "throwing in done handler" );
- jQuery.Deferred().reject().then( null, woops ).fail(function( failException ) {
+ jQuery.Deferred().reject().then( null, woops ).fail( function( failException ) {
assert.strictEqual( failException, "exception thrown", "throwing in fail handler" );
QUnit.start();
- });
- });
-});
+ } );
+ } );
+} );
QUnit.test( "jQuery.when - chaining", function( assert ) {
@@ -868,13 +868,13 @@ QUnit.test( "jQuery.when - chaining", function( assert ) {
jQuery.Deferred().reject( 5 ).then( null, chain ),
jQuery.Deferred().resolve( 3 ).then( chainStandard ),
jQuery.Deferred().reject( 5 ).then( null, chainStandard )
- ).done(function( v1, v2, s1, s2 ) {
+ ).done( function( v1, v2, s1, s2 ) {
assert.strictEqual( v1, "other deferred", "chaining in done handler" );
assert.strictEqual( v2, "other deferred", "chaining in fail handler" );
assert.strictEqual( s1, "std deferred", "chaining thenable in done handler" );
assert.strictEqual( s2, "std deferred", "chaining thenable in fail handler" );
QUnit.start();
- });
+ } );
defer.resolve( "other deferred" );
-});
+} );
diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js
index 2a2357a52..52c137dc3 100644
--- a/test/unit/deprecated.js
+++ b/test/unit/deprecated.js
@@ -1,2 +1,2 @@
-QUnit.module("deprecated", { teardown: moduleTeardown });
+QUnit.module( "deprecated", { teardown: moduleTeardown } );
diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js
index 5b471094f..c2f08a0bd 100644
--- a/test/unit/dimensions.js
+++ b/test/unit/dimensions.js
@@ -1,10 +1,10 @@
-(function() {
+( function() {
if ( !jQuery.fn.width ) {
return;
}
-QUnit.module("dimensions", { teardown: moduleTeardown });
+QUnit.module( "dimensions", { teardown: moduleTeardown } );
function pass( val ) {
return val;
@@ -29,111 +29,111 @@ function fn( val ) {
*/
function testWidth( val, assert ) {
- assert.expect(9);
+ assert.expect( 9 );
var $div, blah;
- $div = jQuery("#nothiddendiv");
- $div.width( val(30) );
- assert.equal($div.width(), 30, "Test set to 30 correctly");
+ $div = jQuery( "#nothiddendiv" );
+ $div.width( val( 30 ) );
+ assert.equal( $div.width(), 30, "Test set to 30 correctly" );
$div.hide();
- assert.equal($div.width(), 30, "Test hidden div");
+ assert.equal( $div.width(), 30, "Test hidden div" );
$div.show();
- $div.width( val(-1) ); // handle negative numbers by setting to 0 #11604
- assert.equal($div.width(), 0, "Test negative width normalized to 0");
- $div.css("padding", "20px");
- assert.equal($div.width(), 0, "Test padding specified with pixels");
- $div.css("border", "2px solid #fff");
- assert.equal($div.width(), 0, "Test border specified with pixels");
+ $div.width( val( -1 ) ); // handle negative numbers by setting to 0 #11604
+ assert.equal( $div.width(), 0, "Test negative width normalized to 0" );
+ $div.css( "padding", "20px" );
+ assert.equal( $div.width(), 0, "Test padding specified with pixels" );
+ $div.css( "border", "2px solid #fff" );
+ assert.equal( $div.width(), 0, "Test border specified with pixels" );
- $div.css({ "display": "", "border": "", "padding": "" });
+ $div.css( { "display": "", "border": "", "padding": "" } );
- jQuery("#nothiddendivchild").css({ "width": 20, "padding": "3px", "border": "2px solid #fff" });
- assert.equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
- jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" });
+ jQuery( "#nothiddendivchild" ).css( { "width": 20, "padding": "3px", "border": "2px solid #fff" } );
+ assert.equal( jQuery( "#nothiddendivchild" ).width(), 20, "Test child width with border and padding" );
+ jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "width": "" } );
- blah = jQuery("blah");
- assert.equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
- assert.equal( blah.width(), null, "Make sure 'null' is returned on an empty set");
+ blah = jQuery( "blah" );
+ assert.equal( blah.width( val( 10 ) ), blah, "Make sure that setting a width on an empty set returns the set." );
+ assert.equal( blah.width(), null, "Make sure 'null' is returned on an empty set" );
- assert.equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
+ assert.equal( jQuery( window ).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
- QUnit.expectJqData( this, $div[0], "olddisplay" );
+ QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}
-QUnit.test("width()", function( assert ) {
+QUnit.test( "width()", function( assert ) {
testWidth( pass, assert );
-});
+} );
-QUnit.test("width(Function)", function( assert ) {
+QUnit.test( "width(Function)", function( assert ) {
testWidth( fn, assert );
-});
+} );
-QUnit.test("width(Function(args))", function( assert ) {
+QUnit.test( "width(Function(args))", function( assert ) {
assert.expect( 2 );
- var $div = jQuery("#nothiddendiv");
- $div.width( 30 ).width(function(i, width) {
+ var $div = jQuery( "#nothiddendiv" );
+ $div.width( 30 ).width( function( i, width ) {
assert.equal( width, 30, "Make sure previous value is correct." );
return width + 1;
- });
+ } );
assert.equal( $div.width(), 31, "Make sure value was modified correctly." );
-});
+} );
function testHeight( val, assert ) {
- assert.expect(9);
+ assert.expect( 9 );
var $div, blah;
- $div = jQuery("#nothiddendiv");
- $div.height( val(30) );
- assert.equal($div.height(), 30, "Test set to 30 correctly");
+ $div = jQuery( "#nothiddendiv" );
+ $div.height( val( 30 ) );
+ assert.equal( $div.height(), 30, "Test set to 30 correctly" );
$div.hide();
- assert.equal($div.height(), 30, "Test hidden div");
+ assert.equal( $div.height(), 30, "Test hidden div" );
$div.show();
- $div.height( val(-1) ); // handle negative numbers by setting to 0 #11604
- assert.equal($div.height(), 0, "Test negative height normalized to 0");
- $div.css("padding", "20px");
- assert.equal($div.height(), 0, "Test padding specified with pixels");
- $div.css("border", "2px solid #fff");
- assert.equal($div.height(), 0, "Test border specified with pixels");
+ $div.height( val( -1 ) ); // handle negative numbers by setting to 0 #11604
+ assert.equal( $div.height(), 0, "Test negative height normalized to 0" );
+ $div.css( "padding", "20px" );
+ assert.equal( $div.height(), 0, "Test padding specified with pixels" );
+ $div.css( "border", "2px solid #fff" );
+ assert.equal( $div.height(), 0, "Test border specified with pixels" );
- $div.css({ "display": "", "border": "", "padding": "", "height": "1px" });
+ $div.css( { "display": "", "border": "", "padding": "", "height": "1px" } );
- jQuery("#nothiddendivchild").css({ "height": 20, "padding": "3px", "border": "2px solid #fff" });
- assert.equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
- jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" });
+ jQuery( "#nothiddendivchild" ).css( { "height": 20, "padding": "3px", "border": "2px solid #fff" } );
+ assert.equal( jQuery( "#nothiddendivchild" ).height(), 20, "Test child height with border and padding" );
+ jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "height": "" } );
- blah = jQuery("blah");
- assert.equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
- assert.equal( blah.height(), null, "Make sure 'null' is returned on an empty set");
+ blah = jQuery( "blah" );
+ assert.equal( blah.height( val( 10 ) ), blah, "Make sure that setting a height on an empty set returns the set." );
+ assert.equal( blah.height(), null, "Make sure 'null' is returned on an empty set" );
- assert.equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
+ assert.equal( jQuery( window ).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
- QUnit.expectJqData( this, $div[0], "olddisplay" );
+ QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}
-QUnit.test("height()", function( assert ) {
+QUnit.test( "height()", function( assert ) {
testHeight( pass, assert );
-});
+} );
-QUnit.test("height(Function)", function( assert ) {
+QUnit.test( "height(Function)", function( assert ) {
testHeight( fn, assert );
-});
+} );
-QUnit.test("height(Function(args))", function( assert ) {
+QUnit.test( "height(Function(args))", function( assert ) {
assert.expect( 2 );
- var $div = jQuery("#nothiddendiv");
- $div.height( 30 ).height(function(i, height) {
+ var $div = jQuery( "#nothiddendiv" );
+ $div.height( 30 ).height( function( i, height ) {
assert.equal( height, 30, "Make sure previous value is correct." );
return height + 1;
- });
+ } );
assert.equal( $div.height(), 31, "Make sure value was modified correctly." );
-});
+} );
-QUnit.test("innerWidth()", function( assert ) {
+QUnit.test( "innerWidth()", function( assert ) {
assert.expect( 6 );
var $div, div,
@@ -144,11 +144,11 @@ QUnit.test("innerWidth()", function( assert ) {
assert.equal( jQuery( document ).innerWidth(), $doc.width(), "Test on document" );
$div = jQuery( "#nothiddendiv" );
- $div.css({
+ $div.css( {
"margin": 10,
"border": "2px solid #fff",
"width": 30
- });
+ } );
assert.equal( $div.innerWidth(), 30, "Test with margin and border" );
$div.css( "padding", "20px" );
@@ -157,7 +157,7 @@ QUnit.test("innerWidth()", function( assert ) {
assert.equal( $div.innerWidth(), 70, "Test hidden div" );
// reset styles
- $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( "<div>" );
@@ -166,9 +166,9 @@ QUnit.test("innerWidth()", function( assert ) {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
-QUnit.test("innerHeight()", function( assert ) {
+QUnit.test( "innerHeight()", function( assert ) {
assert.expect( 6 );
var $div, div,
@@ -179,11 +179,11 @@ QUnit.test("innerHeight()", function( assert ) {
assert.equal( jQuery( document ).innerHeight(), $doc.height(), "Test on document" );
$div = jQuery( "#nothiddendiv" );
- $div.css({
+ $div.css( {
"margin": 10,
"border": "2px solid #fff",
"height": 30
- });
+ } );
assert.equal( $div.innerHeight(), 30, "Test with margin and border" );
$div.css( "padding", "20px" );
@@ -192,7 +192,7 @@ QUnit.test("innerHeight()", function( assert ) {
assert.equal( $div.innerHeight(), 70, "Test hidden div" );
// reset styles
- $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( "<div>" );
@@ -201,9 +201,9 @@ QUnit.test("innerHeight()", function( assert ) {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
-QUnit.test("outerWidth()", function( assert ) {
+QUnit.test( "outerWidth()", function( assert ) {
assert.expect( 11 );
var $div, div,
@@ -231,7 +231,7 @@ QUnit.test("outerWidth()", function( assert ) {
assert.equal( $div.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" );
// reset styles
- $div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( "<div>" );
@@ -240,23 +240,23 @@ QUnit.test("outerWidth()", function( assert ) {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
-QUnit.test("child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) {
- assert.expect(16);
+QUnit.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) {
+ assert.expect( 16 );
// setup html
- var $divNormal = jQuery("<div>").css({ "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
+ var $divNormal = jQuery( "<div>" ).css( { "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
- $divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body");
- $divNormal.appendTo("body");
+ $divHiddenParent = jQuery( "<div>" ).css( "display", "none" ).append( $divChild ).appendTo( "body" );
+ $divNormal.appendTo( "body" );
// tests that child div of a hidden div works the same as a normal div
assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" );
assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
- assert.equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
+ assert.equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -269,7 +269,7 @@ QUnit.test("child of a hidden elem (or unconnected node) has accurate inner/oute
assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" );
assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #9441" );
assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" );
- assert.equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
+ assert.equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -281,9 +281,9 @@ QUnit.test("child of a hidden elem (or unconnected node) has accurate inner/oute
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
-});
+} );
-QUnit.test("getting dimensions shouldn't modify runtimeStyle see #9233", function( assert ) {
+QUnit.test( "getting dimensions shouldn't modify runtimeStyle see #9233", function( assert ) {
assert.expect( 1 );
var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
@@ -304,36 +304,36 @@ QUnit.test("getting dimensions shouldn't modify runtimeStyle see #9233", functio
}
$div.remove();
-});
+} );
QUnit.test( "table dimensions", function( assert ) {
assert.expect( 2 );
- var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"),
- tdElem = table.find("td").first(),
- colElem = table.find("col").first().width( 300 );
+ var table = jQuery( "<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>" ).appendTo( "#qunit-fixture" ),
+ tdElem = table.find( "td" ).first(),
+ colElem = table.find( "col" ).first().width( 300 );
- table.find("td").css({ "margin": 0, "padding": 0 });
+ table.find( "td" ).css( { "margin": 0, "padding": 0 } );
assert.equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see #11293" );
assert.equal( colElem.width(), 300, "col elements have width(), see #12243" );
-});
+} );
-QUnit.test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) {
- assert.expect(16);
+QUnit.test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) {
+ assert.expect( 16 );
// setup html
- var $divNormal = jQuery("<div>").css({ "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
+ var $divNormal = jQuery( "<div>" ).css( { "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
- $divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body");
- $divNormal.appendTo("body");
+ $divHiddenParent = jQuery( "<div>" ).css( "display", "none" ).append( $divChild ).appendTo( "body" );
+ $divNormal.appendTo( "body" );
// tests that child div of a hidden div works the same as a normal div
assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" );
assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" );
assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
- assert.equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
+ assert.equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -346,7 +346,7 @@ QUnit.test("box-sizing:border-box child of a hidden elem (or unconnected node) h
assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" );
assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
- assert.equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
+ assert.equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -358,9 +358,9 @@ QUnit.test("box-sizing:border-box child of a hidden elem (or unconnected node) h
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
-});
+} );
-QUnit.test("outerHeight()", function( assert ) {
+QUnit.test( "outerHeight()", function( assert ) {
assert.expect( 11 );
var $div, div,
@@ -387,7 +387,7 @@ QUnit.test("outerHeight()", function( assert ) {
assert.equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" );
// reset styles
- $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( "<div>" );
@@ -396,20 +396,20 @@ QUnit.test("outerHeight()", function( assert ) {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
-});
+} );
-QUnit.test("passing undefined is a setter #5571", function( assert ) {
- assert.expect(4);
- assert.equal(jQuery("#nothiddendiv").height(30).height(undefined).height(), 30, ".height(undefined) is chainable (#5571)");
- assert.equal(jQuery("#nothiddendiv").height(30).innerHeight(undefined).height(), 30, ".innerHeight(undefined) is chainable (#5571)");
- assert.equal(jQuery("#nothiddendiv").height(30).outerHeight(undefined).height(), 30, ".outerHeight(undefined) is chainable (#5571)");
- assert.equal(jQuery("#nothiddendiv").width(30).width(undefined).width(), 30, ".width(undefined) is chainable (#5571)");
-});
+QUnit.test( "passing undefined is a setter #5571", function( assert ) {
+ assert.expect( 4 );
+ assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).height( undefined ).height(), 30, ".height(undefined) is chainable (#5571)" );
+ assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).innerHeight( undefined ).height(), 30, ".innerHeight(undefined) is chainable (#5571)" );
+ assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).outerHeight( undefined ).height(), 30, ".outerHeight(undefined) is chainable (#5571)" );
+ assert.equal( jQuery( "#nothiddendiv" ).width( 30 ).width( undefined ).width(), 30, ".width(undefined) is chainable (#5571)" );
+} );
QUnit.test( "getters on non elements should return null", function( assert ) {
assert.expect( 8 );
- var nonElem = jQuery("notAnElement");
+ var nonElem = jQuery( "notAnElement" );
assert.strictEqual( nonElem.width(), null, ".width() is not null (#12283)" );
assert.strictEqual( nonElem.innerWidth(), null, ".innerWidth() is not null (#12283)" );
@@ -420,14 +420,14 @@ QUnit.test( "getters on non elements should return null", function( assert ) {
assert.strictEqual( nonElem.innerHeight(), null, ".innerHeight() is not null (#12283)" );
assert.strictEqual( nonElem.outerHeight(), null, ".outerHeight() is not null (#12283)" );
assert.strictEqual( nonElem.outerHeight( true ), null, ".outerHeight(true) is not null (#12283)" );
-});
+} );
-QUnit.test("setters with and without box-sizing:border-box", function( assert ){
- assert.expect(20);
+QUnit.test( "setters with and without box-sizing:border-box", function( assert ) {
+ assert.expect( 20 );
// Support: Android 2.3 (-webkit-box-sizing).
- var el_bb = jQuery("<div style='width:114px;height:114px;margin:5px;padding:3px;border:4px solid white;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>").appendTo("#qunit-fixture"),
- el = jQuery("<div style='width:100px;height:100px;margin:5px;padding:3px;border:4px solid white;'>test</div>").appendTo("#qunit-fixture"),
+ var el_bb = jQuery( "<div style='width:114px;height:114px;margin:5px;padding:3px;border:4px solid white;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>" ).appendTo( "#qunit-fixture" ),
+ el = jQuery( "<div style='width:100px;height:100px;margin:5px;padding:3px;border:4px solid white;'>test</div>" ).appendTo( "#qunit-fixture" ),
expected = 100;
assert.equal( el_bb.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" );
@@ -453,13 +453,13 @@ QUnit.test("setters with and without box-sizing:border-box", function( assert ){
assert.equal( el.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" );
assert.equal( el.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" );
assert.equal( el.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" );
-});
+} );
testIframe(
"dimensions/documentLarge",
"window vs. large document",
function( jQuery, window, document, assert ) {
- assert.expect(2);
+ assert.expect( 2 );
assert.ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height" );
assert.ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
@@ -472,15 +472,15 @@ QUnit.test( "allow modification of coordinates argument (gh-1848)", function( as
var offsetTop,
element = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
- element.offset(function( index, coords ) {
+ element.offset( function( index, coords ) {
coords.top = 100;
return coords;
- });
+ } );
offsetTop = element.offset().top;
- assert.ok( Math.abs(offsetTop - 100) < 0.02,
- "coordinates are modified (got offset.top: " + offsetTop + ")");
-});
+ assert.ok( Math.abs( offsetTop - 100 ) < 0.02,
+ "coordinates are modified (got offset.top: " + offsetTop + ")" );
+} );
-})();
+} )();
diff --git a/test/unit/effects.js b/test/unit/effects.js
index 934b3e193..755b074f8 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -1,4 +1,4 @@
-(function() {
+( function() {
// Can't test what ain't there
if ( !jQuery.fx ) {
@@ -7,7 +7,7 @@ if ( !jQuery.fx ) {
var oldRaf = window.requestAnimationFrame;
-QUnit.module("effects", {
+QUnit.module( "effects", {
setup: function() {
window.requestAnimationFrame = null;
this.sandbox = sinon.sandbox.create();
@@ -25,44 +25,44 @@ QUnit.module("effects", {
window.requestAnimationFrame = oldRaf;
return moduleTeardown.apply( this, arguments );
}
-});
+} );
-QUnit.test("sanity check", function( assert ) {
- assert.expect(1);
- assert.equal( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length, 3, "QUnit state is correct for testing effects" );
-});
+QUnit.test( "sanity check", function( assert ) {
+ assert.expect( 1 );
+ assert.equal( jQuery( "#dl:visible, #qunit-fixture:visible, #foo:visible" ).length, 3, "QUnit state is correct for testing effects" );
+} );
-QUnit.test("show() basic", function( assert ) {
+QUnit.test( "show() basic", function( assert ) {
assert.expect( 1 );
- var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
+ var div = jQuery( "<div>" ).hide().appendTo( "#qunit-fixture" ).show();
- assert.equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
+ assert.equal( div.css( "display" ), "block", "Make sure pre-hidden divs show" );
// Clean up the detached node
div.remove();
-});
+} );
-QUnit.test("show()", function( assert ) {
+QUnit.test( "show()", function( assert ) {
assert.expect( 27 );
var div, speeds, old, test,
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
- assert.equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
+ assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" );
- hiddendiv.css("display", "block");
- assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ hiddendiv.css( "display", "block" );
+ assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
hiddendiv.show();
- assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
- hiddendiv.css("display","");
+ hiddendiv.css( "display", "" );
- div = jQuery("#fx-queue div").slice(0, 4);
- div.show().each(function() {
- assert.notEqual(this.style.display, "none", "don't change any <div> with display block");
- });
+ div = jQuery( "#fx-queue div" ).slice( 0, 4 );
+ div.show().each( function() {
+ assert.notEqual( this.style.display, "none", "don't change any <div> with display block" );
+ } );
speeds = {
"null speed": null,
@@ -70,23 +70,23 @@ QUnit.test("show()", function( assert ) {
"false speed": false
};
- jQuery.each(speeds, function(name, speed) {
+ jQuery.each( speeds, function( name, speed ) {
var pass = true;
- div.hide().show(speed).each(function() {
+ div.hide().show( speed ).each( function() {
if ( this.style.display === "none" ) {
pass = false;
}
- });
- assert.ok( pass, "Show with " + name);
- });
+ } );
+ assert.ok( pass, "Show with " + name );
+ } );
- jQuery.each(speeds, function(name, speed) {
+ jQuery.each( speeds, function( name, speed ) {
var pass = true;
- div.hide().show(speed, function() {
+ div.hide().show( speed, function() {
pass = false;
- });
+ } );
assert.ok( pass, "Show with " + name + " does not call animate callback" );
- });
+ } );
// Tolerate data from show()/hide()
QUnit.expectJqData( this, div, "olddisplay" );
@@ -99,40 +99,40 @@ QUnit.test("show()", function( assert ) {
"<table id='test-table'></table>"
).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
- old = jQuery("#test-table").show().css("display") !== "table";
- jQuery("#test-table").remove();
+ old = jQuery( "#test-table" ).show().css( "display" ) !== "table";
+ jQuery( "#test-table" ).remove();
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : old ? "block" : "table",
- "thead" : old ? "block" : "table-header-group",
- "tbody" : old ? "block" : "table-row-group",
- "tr" : old ? "block" : "table-row",
- "th" : old ? "block" : "table-cell",
- "td" : old ? "block" : "table-cell",
- "ul" : "block",
- "li" : old ? "block" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline",
+ "code": "inline",
+ "pre": "block",
+ "span": "inline",
+ "table": old ? "block" : "table",
+ "thead": old ? "block" : "table-header-group",
+ "tbody": old ? "block" : "table-row-group",
+ "tr": old ? "block" : "table-row",
+ "th": old ? "block" : "table-cell",
+ "td": old ? "block" : "table-cell",
+ "ul": "block",
+ "li": old ? "block" : "list-item"
};
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show();
- assert.equal( elem.css("display"), expected, "Show using correct display type for " + selector );
- });
+ jQuery.each( test, function( selector, expected ) {
+ var elem = jQuery( selector, "#show-tests" ).show();
+ assert.equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
+ } );
- jQuery("#show-tests").remove();
+ jQuery( "#show-tests" ).remove();
// Make sure that showing or hiding a text node doesn't cause an error
- jQuery("<div>test</div> text <span>test</span>").show().remove();
- jQuery("<div>test</div> text <span>test</span>").hide().remove();
-});
+ jQuery( "<div>test</div> text <span>test</span>" ).show().remove();
+ jQuery( "<div>test</div> text <span>test</span>" ).hide().remove();
+} );
-QUnit.test("show(Number) - other displays", function( assert ) {
- assert.expect(30);
+QUnit.test( "show(Number) - other displays", function( assert ) {
+ assert.expect( 30 );
jQuery(
"<div id='show-tests'>" +
@@ -143,105 +143,105 @@ QUnit.test("show(Number) - other displays", function( assert ) {
).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
var test,
- old = jQuery("#test-table").show().css("display") !== "table";
+ old = jQuery( "#test-table" ).show().css( "display" ) !== "table";
- jQuery("#test-table").remove();
+ jQuery( "#test-table" ).remove();
// Note: inline elements are expected to be inline-block
// because we're showing width/height
// Can't animate width/height inline
// See #14344
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : old ? "block" : "table",
- "thead" : old ? "block" : "table-header-group",
- "tbody" : old ? "block" : "table-row-group",
- "tr" : old ? "block" : "table-row",
- "th" : old ? "block" : "table-cell",
- "td" : old ? "block" : "table-cell",
- "ul" : "block",
- "li" : old ? "block" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline",
+ "code": "inline",
+ "pre": "block",
+ "span": "inline",
+ "table": old ? "block" : "table",
+ "thead": old ? "block" : "table-header-group",
+ "tbody": old ? "block" : "table-row-group",
+ "tr": old ? "block" : "table-row",
+ "th": old ? "block" : "table-cell",
+ "td": old ? "block" : "table-cell",
+ "ul": "block",
+ "li": old ? "block" : "list-item"
};
jQuery.each( test, function( selector ) {
jQuery( selector, "#show-tests" ).show( 100 );
- });
+ } );
this.clock.tick( 50 );
jQuery.each( test, function( selector, expected ) {
- jQuery( selector, "#show-tests" ).each(function() {
+ jQuery( selector, "#show-tests" ).each( function() {
assert.equal(
jQuery( this ).css( "display" ),
expected === "inline" ? "inline-block" : expected,
"Correct display type during animation for " + selector
);
- });
- });
+ } );
+ } );
this.clock.tick( 50 );
jQuery.each( test, function( selector, expected ) {
- jQuery( selector, "#show-tests" ).each(function() {
+ jQuery( selector, "#show-tests" ).each( function() {
assert.equal( jQuery( this ).css( "display" ), expected,
"Correct display type after animation for " + selector );
- });
- });
+ } );
+ } );
- jQuery("#show-tests").remove();
-});
+ jQuery( "#show-tests" ).remove();
+} );
// Supports #7397
-QUnit.test("Persist correct display value", function( assert ) {
- assert.expect(3);
+QUnit.test( "Persist correct display value", function( assert ) {
+ assert.expect( 3 );
jQuery( "<div id='show-tests'><span style='position:absolute;'>foo</span></div>" )
.appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
- var $span = jQuery("#show-tests span"),
- displayNone = $span.css("display"),
+ var $span = jQuery( "#show-tests span" ),
+ displayNone = $span.css( "display" ),
display = "",
clock = this.clock;
$span.show();
- display = $span.css("display");
+ display = $span.css( "display" );
$span.hide();
- $span.fadeIn(100, function() {
- assert.equal($span.css("display"), display, "Expecting display: " + display);
- $span.fadeOut(100, function () {
- assert.equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
- $span.fadeIn(100, function() {
- assert.equal($span.css("display"), display, "Expecting display: " + display);
- });
- });
- });
+ $span.fadeIn( 100, function() {
+ assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
+ $span.fadeOut( 100, function() {
+ assert.equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone );
+ $span.fadeIn( 100, function() {
+ assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
+ } );
+ } );
+ } );
clock.tick( 300 );
QUnit.expectJqData( this, $span, "olddisplay" );
-});
+} );
-QUnit.test("animate(Hash, Object, Function)", function( assert ) {
- assert.expect(1);
- var hash = {opacity: "show"},
- hashCopy = jQuery.extend({}, hash);
- jQuery("#foo").animate(hash, 0, function() {
+QUnit.test( "animate(Hash, Object, Function)", function( assert ) {
+ assert.expect( 1 );
+ var hash = { opacity: "show" },
+ hashCopy = jQuery.extend( {}, hash );
+ jQuery( "#foo" ).animate( hash, 0, function() {
assert.equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
- });
-});
+ } );
+} );
-QUnit.test("animate relative values", function( assert ) {
+QUnit.test( "animate relative values", function( assert ) {
var value = 40,
clock = this.clock,
bases = [ "%", "px", "em" ],
adjustments = [ "px", "em" ],
- container = jQuery("<div></div>")
- .css({ position: "absolute", height: "50em", width: "50em" }),
+ container = jQuery( "<div></div>" )
+ .css( { position: "absolute", height: "50em", width: "50em" } ),
animations = bases.length * adjustments.length;
assert.expect( 2 * animations );
@@ -250,13 +250,13 @@ QUnit.test("animate relative values", function( assert ) {
jQuery.each( adjustments, function( _, adjustUnit ) {
var base = value + baseUnit,
adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit },
- elem = jQuery("<div></div>")
- .appendTo( container.clone().appendTo("#qunit-fixture") )
- .css({
+ elem = jQuery( "<div></div>" )
+ .appendTo( container.clone().appendTo( "#qunit-fixture" ) )
+ .css( {
position: "absolute",
height: base,
width: value + adjustUnit
- }),
+ } ),
baseScale = elem[ 0 ].offsetHeight / value,
adjustScale = elem[ 0 ].offsetWidth / value;
@@ -266,80 +266,79 @@ QUnit.test("animate relative values", function( assert ) {
assert.equal( this.offsetWidth, value * baseScale - 2 * adjustScale,
baseUnit + "-=" + adjustUnit );
- });
+ } );
clock.tick( 100 );
- });
- });
-});
+ } );
+ } );
+} );
-QUnit.test("animate negative height", function( assert ) {
- assert.expect(1);
- jQuery("#foo").animate({ height: -100 }, 100, function() {
+QUnit.test( "animate negative height", function( assert ) {
+ assert.expect( 1 );
+ jQuery( "#foo" ).animate( { height: -100 }, 100, function() {
assert.equal( this.offsetHeight, 0, "Verify height." );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate negative margin", function( assert ) {
- assert.expect(1);
- jQuery("#foo").animate({ "marginTop": -100 }, 100, function() {
- assert.equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
- });
+QUnit.test( "animate negative margin", function( assert ) {
+ assert.expect( 1 );
+ jQuery( "#foo" ).animate( { "marginTop": -100 }, 100, function() {
+ assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate negative margin with px", function( assert ) {
- assert.expect(1);
- jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() {
- assert.equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
- });
+QUnit.test( "animate negative margin with px", function( assert ) {
+ assert.expect( 1 );
+ jQuery( "#foo" ).animate( { marginTop: "-100px" }, 100, function() {
+ assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate negative padding", function( assert ) {
- assert.expect(1);
- jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() {
- assert.equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
- });
+QUnit.test( "animate negative padding", function( assert ) {
+ assert.expect( 1 );
+ jQuery( "#foo" ).animate( { "paddingBottom": -100 }, 100, function() {
+ assert.equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." );
+ } );
this.clock.tick( 100 );
-});
-
-QUnit.test("animate block as inline width/height", function( assert ) {
- assert.expect(3);
+} );
+QUnit.test( "animate block as inline width/height", function( assert ) {
+ assert.expect( 3 );
- jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
- assert.equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, 100, function() {
+ assert.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
assert.equal( this.offsetWidth, 42, "width was animated" );
assert.equal( this.offsetHeight, 42, "height was animated" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate native inline width/height", function( assert ) {
- assert.expect(3);
+QUnit.test( "animate native inline width/height", function( assert ) {
+ assert.expect( 3 );
- jQuery("#foo").css({ display: "", width: "", height: "" })
- .append("<span>text</span>")
- .children("span")
- .animate({ width: 42, height: 42 }, 100, function() {
- assert.equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ jQuery( "#foo" ).css( { display: "", width: "", height: "" } )
+ .append( "<span>text</span>" )
+ .children( "span" )
+ .animate( { width: 42, height: 42 }, 100, function() {
+ assert.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
assert.equal( this.offsetWidth, 42, "width was animated" );
assert.equal( this.offsetHeight, 42, "height was animated" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
QUnit.test( "animate block width/height", function( assert ) {
assert.expect( 3 );
- jQuery("<div>").appendTo("#qunit-fixture").css({
+ jQuery( "<div>" ).appendTo( "#qunit-fixture" ).css( {
display: "block",
width: 20,
height: 20,
paddingLeft: 60
- }).animate({
+ } ).animate( {
width: 42,
height: 42
}, {
@@ -350,80 +349,80 @@ QUnit.test( "animate block width/height", function( assert ) {
}
},
complete: function() {
- assert.equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" );
+ assert.equal( jQuery( this ).css( "display" ), "block", "inline-block was not set on block element when animating width/height" );
assert.equal( jQuery( this ).width(), 42, "width was animated" );
assert.equal( jQuery( this ).height(), 42, "height was animated" );
}
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate table width/height", function( assert ) {
- assert.expect(1);
+QUnit.test( "animate table width/height", function( assert ) {
+ assert.expect( 1 );
- var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
+ var displayMode = jQuery( "#table" ).css( "display" ) !== "table" ? "block" : "table";
- jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
- assert.equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
- });
+ jQuery( "#table" ).animate( { width: 42, height: 42 }, 100, function() {
+ assert.equal( jQuery( this ).css( "display" ), displayMode, "display mode is correct" );
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate table-row width/height", function( assert ) {
- assert.expect(3);
+QUnit.test( "animate table-row width/height", function( assert ) {
+ assert.expect( 3 );
var tr = jQuery( "#table" )
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
.html( "<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
.find( "tr" );
- tr.animate({ width: 10, height: 10 }, 100, function() {
+ tr.animate( { width: 10, height: 10 }, 100, function() {
assert.equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" );
assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate table-cell width/height", function( assert ) {
- assert.expect(3);
+QUnit.test( "animate table-cell width/height", function( assert ) {
+ assert.expect( 3 );
var td = jQuery( "#table" )
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
.html( "<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" )
.find( "td" );
- td.animate({ width: 10, height: 10 }, 100, function() {
+ td.animate( { width: 10, height: 10 }, 100, function() {
assert.equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" );
assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("animate percentage(%) on width/height", function( assert ) {
+QUnit.test( "animate percentage(%) on width/height", function( assert ) {
assert.expect( 2 );
- var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>")
- .appendTo("#qunit-fixture").children("div");
+ var $div = jQuery( "<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>" )
+ .appendTo( "#qunit-fixture" ).children( "div" );
- $div.animate({ width: "25%", height: "25%" }, 13, function() {
- var $this = jQuery(this);
- assert.equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px");
- assert.equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px");
- });
+ $div.animate( { width: "25%", height: "25%" }, 13, function() {
+ var $this = jQuery( this );
+ assert.equal( $this.css( "width" ), "15px", "Width was animated to 15px rather than 25px" );
+ assert.equal( $this.css( "height" ), "15px", "Height was animated to 15px rather than 25px" );
+ } );
this.clock.tick( 20 );
-});
+} );
-QUnit.test("animate resets overflow-x and overflow-y when finished", function( assert ) {
- assert.expect(2);
- jQuery("#foo")
- .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
- .animate({ width: 42, height: 42 }, 100, function() {
+QUnit.test( "animate resets overflow-x and overflow-y when finished", function( assert ) {
+ assert.expect( 2 );
+ jQuery( "#foo" )
+ .css( { display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" } )
+ .animate( { width: 42, height: 42 }, 100, function() {
assert.equal( this.style.overflowX, "visible", "overflow-x is visible" );
assert.equal( this.style.overflowY, "auto", "overflow-y is auto" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
/* // This test ends up being flaky depending upon the CPU load
QUnit.test("animate option (queue === false)", function( assert ) {
@@ -450,7 +449,7 @@ QUnit.test( "animate option { queue: false }", function( assert ) {
assert.expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
fontSize: "2em"
}, {
queue: false,
@@ -458,17 +457,17 @@ QUnit.test( "animate option { queue: false }", function( assert ) {
complete: function() {
assert.ok( true, "Animation Completed" );
}
- });
+ } );
this.clock.tick( 10 );
assert.equal( foo.queue().length, 0, "Queue is empty" );
-});
+} );
QUnit.test( "animate option { queue: true }", function( assert ) {
assert.expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
fontSize: "2em"
}, {
queue: true,
@@ -476,18 +475,18 @@ QUnit.test( "animate option { queue: true }", function( assert ) {
complete: function() {
assert.ok( true, "Animation Completed" );
}
- });
+ } );
assert.notEqual( foo.queue().length, 0, "Default queue is not empty" );
//clear out existing timers before next test
this.clock.tick( 10 );
-});
+} );
QUnit.test( "animate option { queue: 'name' }", function( assert ) {
assert.expect( 5 );
var foo = jQuery( "#foo" ),
- origWidth = parseFloat( foo.css("width") ),
+ origWidth = parseFloat( foo.css( "width" ) ),
order = [];
foo.animate( { width: origWidth + 100 }, {
@@ -497,128 +496,127 @@ QUnit.test( "animate option { queue: 'name' }", function( assert ) {
// second callback function
order.push( 2 );
- assert.equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
- assert.equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
+ assert.equal( parseFloat( foo.css( "width" ) ), origWidth + 100, "Animation ended" );
+ assert.equal( foo.queue( "name" ).length, 1, "Queue length of 'name' queue" );
}
- }).queue( "name", function() {
+ } ).queue( "name", function() {
// last callback function
assert.deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
- });
-
+ } );
// this is the first callback function that should be called
order.push( 1 );
- assert.equal( parseFloat( foo.css("width") ), origWidth, "Animation does not start on its own." );
- assert.equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
+ assert.equal( parseFloat( foo.css( "width" ) ), origWidth, "Animation does not start on its own." );
+ assert.equal( foo.queue( "name" ).length, 2, "Queue length of 'name' queue" );
foo.dequeue( "name" );
this.clock.tick( 10 );
-});
+} );
-QUnit.test("animate with no properties", function( assert ) {
- assert.expect(2);
+QUnit.test( "animate with no properties", function( assert ) {
+ assert.expect( 2 );
var foo,
- divs = jQuery("div"),
+ divs = jQuery( "div" ),
count = 0;
- divs.animate({}, function(){
+ divs.animate( {}, function() {
count++;
- });
+ } );
assert.equal( divs.length, count, "Make sure that callback is called for each element in the set." );
+ foo = jQuery( "#foo" );
- foo = jQuery("#foo");
-
- foo.animate({});
- foo.animate({top: 10}, 100, function(){
+ foo.animate( {} );
+ foo.animate( { top: 10 }, 100, function() {
assert.ok( true, "Animation was properly dequeued." );
- });
+ } );
this.clock.tick( 100 );
-});
-
-QUnit.test("animate duration 0", function( assert ) {
- assert.expect(11);
+} );
+QUnit.test( "animate duration 0", function( assert ) {
+ assert.expect( 11 );
var $elem,
- $elems = jQuery([{ a:0 },{ a:0 }]),
+ $elems = jQuery( [ { a:0 },{ a:0 } ] ),
counter = 0;
assert.equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
- $elems.eq(0).animate( {a:1}, 0, function(){
+ $elems.eq( 0 ).animate( { a:1 }, 0, function() {
assert.ok( true, "Animate a simple property." );
counter++;
- });
+ } );
// Failed until [6115]
assert.equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
assert.equal( counter, 1, "One synchronic animations" );
- $elems.animate( { a:2 }, 0, function(){
+ $elems.animate( { a:2 }, 0, function() {
assert.ok( true, "Animate a second simple property." );
counter++;
- });
+ } );
assert.equal( counter, 3, "Multiple synchronic animations" );
- $elems.eq(0).animate( {a:3}, 0, function(){
+ $elems.eq( 0 ).animate( { a:3 }, 0, function() {
assert.ok( true, "Animate a third simple property." );
counter++;
- });
- $elems.eq(1).animate( {a:3}, 200, function(){
+ } );
+ $elems.eq( 1 ).animate( { a:3 }, 200, function() {
counter++;
+
// Failed until [6115]
assert.equal( counter, 5, "One synchronic and one asynchronic" );
- });
+ } );
this.clock.tick( 200 );
- $elem = jQuery("<div />");
- $elem.show(0, function(){
- assert.ok(true, "Show callback with no duration");
- });
- $elem.hide(0, function(){
- assert.ok(true, "Hide callback with no duration");
- });
+ $elem = jQuery( "<div />" );
+ $elem.show( 0, function() {
+ assert.ok( true, "Show callback with no duration" );
+ } );
+ $elem.hide( 0, function() {
+ assert.ok( true, "Hide callback with no duration" );
+ } );
// manually clean up detached elements
$elem.remove();
-});
+} );
-QUnit.test("animate hyphenated properties", function( assert ) {
- assert.expect(1);
+QUnit.test( "animate hyphenated properties", function( assert ) {
+ assert.expect( 1 );
- jQuery("#foo")
- .css("font-size", 10)
- .animate({"font-size": 20}, 200, function() {
+ jQuery( "#foo" )
+ .css( "font-size", 10 )
+ .animate( { "font-size": 20 }, 200, function() {
assert.equal( this.style.fontSize, "20px", "The font-size property was animated." );
- });
+ } );
+
// FIXME why is this double only when run with other tests
this.clock.tick( 400 );
-});
+} );
-QUnit.test("animate non-element", function( assert ) {
- assert.expect(1);
+QUnit.test( "animate non-element", function( assert ) {
+ assert.expect( 1 );
var obj = { test: 0 };
- jQuery(obj).animate({test: 200}, 200, function(){
+ jQuery( obj ).animate( { test: 200 }, 200, function() {
assert.equal( obj.test, 200, "The custom property should be modified." );
- });
+ } );
this.clock.tick( 200 );
-});
+} );
-QUnit.test("stop()", function( assert ) {
+QUnit.test( "stop()", function( assert ) {
assert.expect( 4 );
var $one, $two,
- $foo = jQuery("#foo"),
+ $foo = jQuery( "#foo" ),
w = 0,
nw;
@@ -626,34 +624,35 @@ QUnit.test("stop()", function( assert ) {
.animate( { "width": "show" }, 1500 );
this.clock.tick( 100 );
- nw = $foo.css("width");
+ nw = $foo.css( "width" );
assert.notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
$foo.stop();
- nw = $foo.css("width");
+ nw = $foo.css( "width" );
assert.notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
this.clock.tick( 100 );
$foo.removeData();
- $foo.removeData(undefined, true);
- assert.equal( nw, $foo.css("width"), "The animation didn't continue" );
+ $foo.removeData( undefined, true );
+ assert.equal( nw, $foo.css( "width" ), "The animation didn't continue" );
- $one = jQuery("#fadein");
- $two = jQuery("#show");
- $one.fadeTo(100, 0, function() {
+ $one = jQuery( "#fadein" );
+ $two = jQuery( "#show" );
+ $one.fadeTo( 100, 0, function() {
$one.stop();
- });
+ } );
this.clock.tick( 100 );
- $two.fadeTo(100, 0, function() {
- assert.equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
+ $two.fadeTo( 100, 0, function() {
+ assert.equal( $two.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (#6641)" );
+
// Reset styles
- $one.add( $two ).css("opacity", "");
- });
+ $one.add( $two ).css( "opacity", "" );
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("stop() - several in queue", function( assert ) {
+QUnit.test( "stop() - several in queue", function( assert ) {
assert.expect( 5 );
var nw, $foo = jQuery( "#foo" );
@@ -661,9 +660,9 @@ QUnit.test("stop() - several in queue", function( assert ) {
// default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
$foo.hide().css( "width", 800 );
- $foo.animate({ "width": "show" }, 400, "linear");
- $foo.animate({ "width": "hide" });
- $foo.animate({ "width": "show" });
+ $foo.animate( { "width": "show" }, 400, "linear" );
+ $foo.animate( { "width": "hide" } );
+ $foo.animate( { "width": "show" } );
this.clock.tick( 1 );
@@ -681,119 +680,121 @@ QUnit.test("stop() - several in queue", function( assert ) {
$foo.stop( true );
assert.equal( $foo.queue().length, 0, "0 in the queue" );
-});
+} );
-QUnit.test("stop(clearQueue)", function( assert ) {
- assert.expect(4);
+QUnit.test( "stop(clearQueue)", function( assert ) {
+ assert.expect( 4 );
- var $foo = jQuery("#foo"),
+ var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css("width");
+ $foo.hide().css( "width", 200 ).css( "width" );
- $foo.animate({ "width": "show" }, 1000);
- $foo.animate({ "width": "hide" }, 1000);
- $foo.animate({ "width": "show" }, 1000);
+ $foo.animate( { "width": "show" }, 1000 );
+ $foo.animate( { "width": "hide" }, 1000 );
+ $foo.animate( { "width": "show" }, 1000 );
this.clock.tick( 100 );
- nw = $foo.css("width");
- assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
- $foo.stop(true);
+ nw = $foo.css( "width" );
+ assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
+ $foo.stop( true );
- nw = $foo.css("width");
- assert.ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
+ nw = $foo.css( "width" );
+ assert.ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px" );
assert.equal( $foo.queue().length, 0, "The animation queue was cleared" );
this.clock.tick( 100 );
- assert.equal( nw, $foo.css("width"), "The animation didn't continue" );
-});
+ assert.equal( nw, $foo.css( "width" ), "The animation didn't continue" );
+} );
-QUnit.test("stop(clearQueue, gotoEnd)", function( assert ) {
- assert.expect(1);
+QUnit.test( "stop(clearQueue, gotoEnd)", function( assert ) {
+ assert.expect( 1 );
- var $foo = jQuery("#foo"),
+ var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css("width");
+ $foo.hide().css( "width", 200 ).css( "width" );
- $foo.animate({ width: "show" }, 1000);
- $foo.animate({ width: "hide" }, 1000);
- $foo.animate({ width: "show" }, 1000);
- $foo.animate({ width: "hide" }, 1000);
+ $foo.animate( { width: "show" }, 1000 );
+ $foo.animate( { width: "hide" }, 1000 );
+ $foo.animate( { width: "show" }, 1000 );
+ $foo.animate( { width: "hide" }, 1000 );
this.clock.tick( 100 );
- nw = $foo.css("width");
- assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
- $foo.stop(false, true);
+ nw = $foo.css( "width" );
+ assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
+ $foo.stop( false, true );
+
+ nw = $foo.css( "width" );
- nw = $foo.css("width");
// Disabled, being flaky
//equal( nw, 1, "Stop() reset the animation" );
this.clock.tick( 100 );
+
// Disabled, being flaky
//equal( $foo.queue().length, 2, "The next animation continued" );
- $foo.stop(true);
-});
+ $foo.stop( true );
+} );
QUnit.test( "stop( queue, ..., ... ) - Stop single queues", function( assert ) {
assert.expect( 3 );
var saved,
- foo = jQuery("#foo").css({ width: 200, height: 200 });
+ foo = jQuery( "#foo" ).css( { width: 200, height: 200 } );
- foo.animate({
+ foo.animate( {
width: 400
- },{
+ }, {
duration: 500,
complete: function() {
- assert.equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
- assert.equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
+ assert.equal( parseFloat( foo.css( "width" ) ), 400, "Animation completed for standard queue" );
+ assert.equal( parseFloat( foo.css( "height" ) ), saved, "Height was not changed after the second stop" );
}
- });
+ } );
- foo.animate({
+ foo.animate( {
height: 400
- },{
+ }, {
duration: 1000,
queue: "height"
- }).dequeue("height").stop( "height", false, true );
+ } ).dequeue( "height" ).stop( "height", false, true );
- assert.equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
+ assert.equal( parseFloat( foo.css( "height" ) ), 400, "Height was stopped with gotoEnd" );
- foo.animate({
+ foo.animate( {
height: 200
- },{
+ }, {
duration: 1000,
queue: "height"
- }).dequeue( "height" ).stop( "height", false, false );
- saved = parseFloat( foo.css("height") );
+ } ).dequeue( "height" ).stop( "height", false, false );
+ saved = parseFloat( foo.css( "height" ) );
this.clock.tick( 500 );
-});
+} );
-QUnit.test("toggle()", function( assert ) {
- assert.expect(6);
- var x = jQuery("#foo");
- assert.ok( x.is(":visible"), "is visible" );
+QUnit.test( "toggle()", function( assert ) {
+ assert.expect( 6 );
+ var x = jQuery( "#foo" );
+ assert.ok( x.is( ":visible" ), "is visible" );
x.toggle();
- assert.ok( x.is(":hidden"), "is hidden" );
+ assert.ok( x.is( ":hidden" ), "is hidden" );
x.toggle();
- assert.ok( x.is(":visible"), "is visible again" );
-
- x.toggle(true);
- assert.ok( x.is(":visible"), "is visible" );
- x.toggle(false);
- assert.ok( x.is(":hidden"), "is hidden" );
- x.toggle(true);
- assert.ok( x.is(":visible"), "is visible again" );
-});
+ assert.ok( x.is( ":visible" ), "is visible again" );
+
+ x.toggle( true );
+ assert.ok( x.is( ":visible" ), "is visible" );
+ x.toggle( false );
+ assert.ok( x.is( ":hidden" ), "is hidden" );
+ x.toggle( true );
+ assert.ok( x.is( ":visible" ), "is visible again" );
+} );
QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert ) {
assert.expect( 7 );
- var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
+ var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css( {
color: "#ABC",
border: "5px solid black",
left: "auto",
marginBottom: "-11000px"
- })[0];
+ } )[ 0 ];
assert.equal(
( new jQuery.fx( div, {}, "color" ) ).cur(),
@@ -839,31 +840,31 @@ QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert ) {
);
jQuery( div ).remove();
-});
+} );
-QUnit.test("Overflow and Display", function( assert ) {
- assert.expect(4);
+QUnit.test( "Overflow and Display", function( assert ) {
+ assert.expect( 4 );
var
- testClass = jQuery.makeTest("Overflow and Display")
- .addClass("overflow inline"),
- testStyle = jQuery.makeTest("Overflow and Display (inline style)")
- .css({ overflow: "visible", display: "inline" }),
+ testClass = jQuery.makeTest( "Overflow and Display" )
+ .addClass( "overflow inline" ),
+ testStyle = jQuery.makeTest( "Overflow and Display (inline style)" )
+ .css( { overflow: "visible", display: "inline" } ),
done = function() {
assert.equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
assert.equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
};
testClass.add( testStyle )
- .addClass("widewidth")
- .text("Some sample text.")
- .before("text before")
- .after("text after")
- .animate({ opacity: 0.5 }, "slow", done );
+ .addClass( "widewidth" )
+ .text( "Some sample text." )
+ .before( "text before" )
+ .after( "text after" )
+ .animate( { opacity: 0.5 }, "slow", done );
this.clock.tick( 600 );
-});
+} );
-jQuery.each({
+jQuery.each( {
"CSS Auto": function( elem, prop ) {
jQuery( elem ).addClass( "auto" + prop )
.text( "This is a long string of text." );
@@ -899,7 +900,7 @@ jQuery.each({
return 0;
}
}, function( fn, f ) {
- jQuery.each({
+ jQuery.each( {
"show": function( elem, prop ) {
jQuery( elem ).hide().addClass( "wide" + prop );
return "show";
@@ -920,7 +921,7 @@ jQuery.each({
return 0;
}
}, function( tn, t ) {
- QUnit.test(fn + " to " + tn, function( assert ) {
+ QUnit.test( fn + " to " + tn, function( assert ) {
var num, anim,
elem = jQuery.makeTest( fn + " to " + tn ),
t_w = t( elem, "width" ),
@@ -935,6 +936,7 @@ jQuery.each({
}
num = 0;
+
// TODO: uncrowd this
if ( t_h === "show" ) { num++; }
if ( t_w === "show" ) { num++; }
@@ -950,9 +952,9 @@ jQuery.each({
anim = { width: t_w, height: t_h, opacity: t_o };
- elem.animate(anim, 50);
+ elem.animate( anim, 50 );
- jQuery.when( elem ).done(function( $elem ) {
+ jQuery.when( elem ).done( function( $elem ) {
var cur_o, cur_w, cur_h, old_h,
elem = $elem[ 0 ];
@@ -969,9 +971,9 @@ jQuery.each({
assert.ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height );
}
- cur_o = jQuery.style(elem, "opacity");
+ cur_o = jQuery.style( elem, "opacity" );
- if ( f_o !== jQuery.css(elem, "opacity") ) {
+ if ( f_o !== jQuery.css( elem, "opacity" ) ) {
f_o = f( elem, "opacity" );
}
@@ -986,13 +988,13 @@ jQuery.each({
if ( t_o.constructor === Number ) {
assert.equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
- assert.ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
+ assert.ok( jQuery.css( elem, "opacity" ) !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
}
if ( t_w.constructor === Number ) {
assert.equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
- cur_w = jQuery.css( elem,"width" );
+ cur_w = jQuery.css( elem, "width" );
assert.ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
}
@@ -1000,14 +1002,14 @@ jQuery.each({
if ( t_h.constructor === Number ) {
assert.equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
- cur_h = jQuery.css( elem,"height" );
+ cur_h = jQuery.css( elem, "height" );
assert.ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
}
if ( t_h === "show" ) {
old_h = jQuery.css( elem, "height" );
- jQuery( elem ).append("<br/>Some more text<br/>and some more...");
+ jQuery( elem ).append( "<br/>Some more text<br/>and some more..." );
if ( /Auto/.test( fn ) ) {
assert.notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
@@ -1019,18 +1021,18 @@ jQuery.each({
// manually remove generated element
jQuery( elem ).remove();
- });
+ } );
this.clock.tick( 50 );
- });
- });
-});
+ } );
+ } );
+} );
-QUnit.test("Effects chaining", function( assert ) {
+QUnit.test( "Effects chaining", function( assert ) {
var remaining = 16,
props = [ "opacity", "height", "width", "display", "overflow" ],
setup = function( name, selector ) {
var $el = jQuery( selector );
- return $el.data( getProps( $el[0] ) ).data( "name", name );
+ return $el.data( getProps( $el[ 0 ] ) ).data( "name", name );
},
check = function() {
var data = jQuery.data( this ),
@@ -1045,40 +1047,40 @@ QUnit.test("Effects chaining", function( assert ) {
var obj = {};
jQuery.each( props, function( i, prop ) {
obj[ prop ] = prop === "overflow" && el.style[ prop ] || jQuery.css( el, prop );
- });
+ } );
return obj;
};
assert.expect( remaining );
- setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", check );
- setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", check );
- setup( ".hide().show()", "#show div" ).hide("fast").show( "fast", check );
- setup( ".show().hide()", "#hide div" ).show("fast").hide( "fast", check );
- setup( ".show().hide(easing)", "#easehide div" ).show("fast").hide( "fast", "linear", check );
- setup( ".toggle().toggle() - in", "#togglein div" ).toggle("fast").toggle( "fast", check );
- setup( ".toggle().toggle() - out", "#toggleout div" ).toggle("fast").toggle( "fast", check );
- setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle("fast").toggle( "fast", "linear", check );
- setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown("fast").slideUp( "fast", check );
- setup( ".slideUp().slideDown()", "#slideup div" ).slideUp("fast").slideDown( "fast", check );
- setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp("fast").slideDown( "fast", "linear", check );
- setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle("fast").slideToggle( "fast", check );
- setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle("fast").slideToggle( "fast", check );
- setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", check );
- setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", check );
+ setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", check );
+ setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", check );
+ setup( ".hide().show()", "#show div" ).hide( "fast" ).show( "fast", check );
+ setup( ".show().hide()", "#hide div" ).show( "fast" ).hide( "fast", check );
+ setup( ".show().hide(easing)", "#easehide div" ).show( "fast" ).hide( "fast", "linear", check );
+ setup( ".toggle().toggle() - in", "#togglein div" ).toggle( "fast" ).toggle( "fast", check );
+ setup( ".toggle().toggle() - out", "#toggleout div" ).toggle( "fast" ).toggle( "fast", check );
+ setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle( "fast" ).toggle( "fast", "linear", check );
+ setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown( "fast" ).slideUp( "fast", check );
+ setup( ".slideUp().slideDown()", "#slideup div" ).slideUp( "fast" ).slideDown( "fast", check );
+ setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp( "fast" ).slideDown( "fast", "linear", check );
+ setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle( "fast" ).slideToggle( "fast", check );
+ setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle( "fast" ).slideToggle( "fast", check );
+ setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", check );
+ setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", check );
setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", check );
this.clock.tick( 400 );
-});
+} );
-jQuery.makeTest = function( text ){
- var elem = jQuery("<div></div>")
+jQuery.makeTest = function( text ) {
+ var elem = jQuery( "<div></div>" )
.attr( "id", "test" + jQuery.makeTest.id++ )
- .addClass("box");
+ .addClass( "box" );
- jQuery("<h4></h4>")
+ jQuery( "<h4></h4>" )
.text( text )
- .appendTo("#fx-tests")
+ .appendTo( "#fx-tests" )
.after( elem );
return elem;
@@ -1086,18 +1088,18 @@ jQuery.makeTest = function( text ){
jQuery.makeTest.id = 1;
-QUnit.test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function( assert ) {
- assert.expect(4);
+QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function( assert ) {
+ assert.expect( 4 );
- var $checkedtest = jQuery("#checkedtest");
- $checkedtest.hide().show("fast", function() {
- assert.ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
- assert.ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
- assert.ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
- assert.ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
- });
+ var $checkedtest = jQuery( "#checkedtest" );
+ $checkedtest.hide().show( "fast", function() {
+ assert.ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." );
+ assert.ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." );
+ assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
+ assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
+ } );
this.clock.tick( 200 );
-});
+} );
QUnit.test( "interrupt toggle", function( assert ) {
assert.expect( 24 );
@@ -1106,13 +1108,14 @@ QUnit.test( "interrupt toggle", function( assert ) {
longDuration = 2000,
shortDuration = 500,
remaining = 0,
- $elems = jQuery(".chain-test"),
+ $elems = jQuery( ".chain-test" ),
clock = this.clock,
finish = function() {
};
jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
- var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
+ var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each( function() {
+
// Don't end test until we're done with this element
remaining++;
@@ -1121,28 +1124,28 @@ QUnit.test( "interrupt toggle", function( assert ) {
// Expect olddisplay data from our .hide() call below
QUnit.expectJqData( env, this, "olddisplay" );
- });
+ } );
// Interrupt a hiding toggle
$methodElems[ method ]( longDuration );
- setTimeout(function() {
- $methodElems.stop().each(function() {
+ setTimeout( function() {
+ $methodElems.stop().each( function() {
assert.notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
- });
+ } );
// Restore
$methodElems[ method ]( shortDuration, function() {
var id = this.id,
$elem = jQuery( this ),
- startVal = $elem.data("startVal");
+ startVal = $elem.data( "startVal" );
- $elem.removeData("startVal");
+ $elem.removeData( "startVal" );
assert.equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
// Interrupt a showing toggle
$elem.hide()[ method ]( longDuration );
- setTimeout(function() {
+ setTimeout( function() {
$elem.stop();
assert.notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
@@ -1150,15 +1153,15 @@ QUnit.test( "interrupt toggle", function( assert ) {
$elem[ method ]( shortDuration, function() {
assert.equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
finish();
- });
+ } );
}, shortDuration );
- });
+ } );
}, shortDuration );
- });
+ } );
clock.tick( longDuration );
// FIXME untangle the set timeouts
-});
+} );
QUnit.test( "animate with per-property easing", function( assert ) {
@@ -1195,34 +1198,34 @@ QUnit.test( "animate with per-property easing", function( assert ) {
assert.ok( defaultTestCalled, "Easing function (_default) called" );
assert.equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" );
assert.equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
-QUnit.test("animate with CSS shorthand properties", function( assert ){
- assert.expect(11);
+QUnit.test( "animate with CSS shorthand properties", function( assert ) {
+ assert.expect( 11 );
var easeAnimation_count = 0,
easeProperty_count = 0,
propsBasic = { "padding": "10 20 30" },
propsSpecial = { "padding": [ "1 2 3", "propertyScope" ] };
- jQuery.easing.animationScope = function(p) {
+ jQuery.easing.animationScope = function( p ) {
if ( p >= 1 ) {
easeAnimation_count++;
}
return p;
};
- jQuery.easing.propertyScope = function(p) {
+ jQuery.easing.propertyScope = function( p ) {
if ( p >= 1 ) {
easeProperty_count++;
}
return p;
};
- jQuery("#foo")
+ jQuery( "#foo" )
.animate( propsBasic, 200, "animationScope", function() {
assert.equal( this.style.paddingTop, "10px", "padding-top was animated" );
assert.equal( this.style.paddingLeft, "20px", "padding-left was animated" );
@@ -1230,7 +1233,7 @@ QUnit.test("animate with CSS shorthand properties", function( assert ){
assert.equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
assert.equal( easeAnimation_count, 4, "per-animation default easing called for each property" );
easeAnimation_count = 0;
- })
+ } )
.animate( propsSpecial, 200, "animationScope", function() {
assert.equal( this.style.paddingTop, "1px", "padding-top was animated again" );
assert.equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
@@ -1239,37 +1242,37 @@ QUnit.test("animate with CSS shorthand properties", function( assert ){
assert.equal( easeAnimation_count, 0, "per-animation default easing not called" );
assert.equal( easeProperty_count, 4, "special easing called for each property" );
- jQuery(this).css("padding", "0");
+ jQuery( this ).css( "padding", "0" );
delete jQuery.easing.animationScope;
delete jQuery.easing.propertyScope;
- });
+ } );
this.clock.tick( 400 );
-});
+} );
-QUnit.test("hide hidden elements, with animation (bug #7141)", function( assert ) {
- assert.expect(3);
+QUnit.test( "hide hidden elements, with animation (bug #7141)", function( assert ) {
+ assert.expect( 3 );
- var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
- assert.equal( div.css("display"), "none", "Element is hidden by default" );
- div.hide(1, function () {
- assert.ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
- div.show(1, function () {
- assert.equal( div.css("display"), "block", "Show a double-hidden element" );
- });
- });
+ var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
+ assert.equal( div.css( "display" ), "none", "Element is hidden by default" );
+ div.hide( 1, function() {
+ assert.ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" );
+ div.show( 1, function() {
+ assert.equal( div.css( "display" ), "block", "Show a double-hidden element" );
+ } );
+ } );
this.clock.tick( 10 );
-});
+} );
-QUnit.test("animate unit-less properties (#4966)", function( assert ) {
+QUnit.test( "animate unit-less properties (#4966)", function( assert ) {
assert.expect( 2 );
var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
assert.equal( div.css( "z-index" ), "0", "z-index is 0" );
- div.animate({ zIndex: 2 }, function() {
+ div.animate( { zIndex: 2 }, function() {
assert.equal( div.css( "z-index" ), "2", "z-index is 2" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function( assert ) {
assert.expect( 6 );
@@ -1282,11 +1285,11 @@ QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function
}
assert.equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
assert.equal( cssInt( "left" ), 0, "Left is 0" );
- div.animate({
+ div.animate( {
left: 200,
marginLeft: 200,
opacity: 0
- }, 2000);
+ }, 2000 );
this.clock.tick( 500 );
@@ -1297,25 +1300,26 @@ QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function
assert.notEqual( l, 0, "Left is not 0 after partial animate" );
assert.notEqual( l, 200, "Left is not 200 after partial animate" );
div.stop().remove();
-});
+} );
-QUnit.test("callbacks should fire in correct order (#9100)", function( assert ) {
+QUnit.test( "callbacks should fire in correct order (#9100)", function( assert ) {
assert.expect( 1 );
var a = 1,
cb = 0;
- jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture")
+ jQuery( "<p data-operation='*2'></p><p data-operation='^2'></p>" ).appendTo( "#qunit-fixture" )
+
// The test will always pass if no properties are animated or if the duration is 0
- .animate({fontSize: 12}, 13, function() {
- a *= jQuery(this).data("operation") === "*2" ? 2 : a;
+ .animate( { fontSize: 12 }, 13, function() {
+ a *= jQuery( this ).data( "operation" ) === "*2" ? 2 : a;
cb++;
if ( cb === 2 ) {
- assert.equal( a, 4, "test value has been *2 and _then_ ^2");
+ assert.equal( a, 4, "test value has been *2 and _then_ ^2" );
}
- });
+ } );
this.clock.tick( 20 );
-});
+} );
QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function( assert ) {
assert.expect( 2 );
@@ -1325,9 +1329,9 @@ QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function(
function TestException() {
}
- foo.animate({ height: 1 }, 1, function() {
+ foo.animate( { height: 1 }, 1, function() {
throw new TestException();
- });
+ } );
// this test thoroughly abuses undocumented methods - please feel free to update
// with any changes internally to these functions.
@@ -1343,39 +1347,40 @@ QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function(
assert.ok( true, "Test completed without throwing a second exception" );
-});
+} );
-QUnit.test("animate will scale margin properties individually", function( assert ) {
+QUnit.test( "animate will scale margin properties individually", function( assert ) {
assert.expect( 2 );
- var foo = jQuery( "#foo" ).css({
+ var foo = jQuery( "#foo" ).css( {
"margin": 0,
"marginLeft": 100
- });
+ } );
assert.ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
- foo.animate({
+ foo.animate( {
"margin": 200
- }).stop();
+ } ).stop();
- assert.ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
+ assert.ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "The margin properties are different" );
// clean up for next test
- foo.css({
+ foo.css( {
"marginLeft": "",
"marginRight": "",
"marginTop": "",
"marginBottom": ""
- });
-});
+ } );
+} );
-QUnit.test("Do not append px to 'fill-opacity' #9548", function( assert ) {
+QUnit.test( "Do not append px to 'fill-opacity' #9548", function( assert ) {
assert.expect( 1 );
- var $div = jQuery("<div>").appendTo("#qunit-fixture");
+ var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
+
+ $div.css( "fill-opacity", 0 ).animate( { "fill-opacity": 1.0 }, 0, function() {
- $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
// Support: Android 2.3 (no support for fill-opacity)
if ( jQuery( this ).css( "fill-opacity" ) ) {
assert.equal( jQuery( this ).css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
@@ -1383,10 +1388,10 @@ QUnit.test("Do not append px to 'fill-opacity' #9548", function( assert ) {
assert.ok( true, "No support for fill-opacity CSS property" );
}
$div.remove();
- });
-});
+ } );
+} );
-QUnit.test("line-height animates correctly (#13855)", function( assert ) {
+QUnit.test( "line-height animates correctly (#13855)", function( assert ) {
assert.expect( 12 );
var t0,
@@ -1398,22 +1403,22 @@ QUnit.test("line-height animates correctly (#13855)", function( assert ) {
"<p style='line-height: 5000px;'>px</p>" +
"<p style='line-height: 5000%;'>percent</p>" +
"<p style='line-height: 100em;'>em</p>"
- ).appendTo("#qunit-fixture"),
+ ).appendTo( "#qunit-fixture" ),
initialHeight = jQuery.map( animated, function( el ) {
return jQuery( el ).height();
- }),
+ } ),
tolerance = 1.5;
// Delay start to improve test stability
- setTimeout(function() {
+ setTimeout( function() {
- t0 = +(new Date());
+ t0 = +( new Date() );
animated.animate( { "line-height": "hide" }, longDuration, "linear" );
- setTimeout(function() {
- var progress = ( (new Date()) - t0 ) / longDuration;
+ setTimeout( function() {
+ var progress = ( ( new Date() ) - t0 ) / longDuration;
- animated.each(function( i ) {
+ animated.each( function( i ) {
var label = jQuery.text( this ),
initial = initialHeight[ i ],
height = jQuery( this ).height(),
@@ -1422,32 +1427,32 @@ QUnit.test("line-height animates correctly (#13855)", function( assert ) {
height + " < " + initial + " @ " + ( progress * 100 ) + "%" );
assert.ok( height > lower, "hide " + label + ": lower bound; " +
height + " > " + lower + " @ " + ( progress * 100 ) + "%" );
- });
+ } );
- t0 = +(new Date());
+ t0 = +( new Date() );
animated.stop( true, true ).hide()
.animate( { "line-height": "show" }, longDuration, "linear" );
- setTimeout(function() {
- var progress = ( (new Date()) - t0 ) / longDuration;
+ setTimeout( function() {
+ var progress = ( ( new Date() ) - t0 ) / longDuration;
- animated.each(function( i ) {
+ animated.each( function( i ) {
var label = jQuery.text( this ),
initial = initialHeight[ i ],
height = jQuery( this ).height(),
upper = initial * progress * tolerance;
assert.ok( height < upper, "show " + label + ": upper bound; " +
height + " < " + upper + " @ " + ( progress * 100 ) + "%" );
- });
+ } );
animated.stop( true, true );
}, shortDuration );
-clock.tick(shortDuration);
+clock.tick( shortDuration );
}, shortDuration );
-clock.tick(shortDuration);
+clock.tick( shortDuration );
}, 50 );
clock.tick( 50 );
-});
+} );
// Start 1.8 Animation tests
QUnit.test( "jQuery.Animation( object, props, opts )", function( assert ) {
@@ -1465,23 +1470,23 @@ QUnit.test( "jQuery.Animation( object, props, opts )", function( assert ) {
"width": 200
};
- animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
- animation.done(function() {
+ animation = jQuery.Animation( testObject, testDest, { "duration": 1 } );
+ animation.done( function() {
for ( var prop in testDest ) {
assert.equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
}
- animation.done(function() {
+ animation.done( function() {
assert.deepEqual( testObject, testDest, "No unexpected properties" );
- });
- });
+ } );
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "Animate Option: step: function( percent, tween )", function( assert ) {
assert.expect( 1 );
var counter = {};
- jQuery( "#foo" ).animate({
+ jQuery( "#foo" ).animate( {
prop1: 1,
prop2: 2,
prop3: 3
@@ -1489,37 +1494,38 @@ QUnit.test( "Animate Option: step: function( percent, tween )", function( assert
duration: 1,
step: function( value, tween ) {
var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
+
// in case this is called multiple times for either, lets store it in
// 0 or 1 in the array
calls[ value === 0 ? 0 : 1 ] = value;
}
- }).queue( function( next ) {
+ } ).queue( function( next ) {
assert.deepEqual( counter, {
- prop1: [0, 1],
- prop2: [0, 2],
- prop3: [0, 3]
- }, "Step function was called once at 0% and once at 100% for each property");
+ prop1: [ 0, 1 ],
+ prop2: [ 0, 2 ],
+ prop3: [ 0, 3 ]
+ }, "Step function was called once at 0% and once at 100% for each property" );
next();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "Animate callbacks have correct context", function( assert ) {
assert.expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
height: 10
}, 10, function() {
assert.equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
- }).stop( true, true );
- foo.animate({
+ } ).stop( true, true );
+ foo.animate( {
height: 100
}, 10, function() {
assert.equal( foo[ 0 ], this, "Complete callback `this` is element" );
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "User supplied callback called after show when fx off (#8892)", function( assert ) {
assert.expect( 2 );
@@ -1532,10 +1538,10 @@ QUnit.test( "User supplied callback called after show when fx off (#8892)", func
foo.fadeOut( 500, function() {
assert.ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
jQuery.fx.off = false;
- });
- });
+ } );
+ } );
this.clock.tick( 1000 );
-});
+} );
QUnit.test( "animate should set display for disconnected nodes", function( assert ) {
assert.expect( 20 );
@@ -1548,18 +1554,18 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser
fadeTo: [ "fast", 0.5 ],
slideDown: [ "fast" ],
show: [ 1 ],
- animate: [{ width: "show" }]
+ animate: [ { width: "show" } ]
},
- $divEmpty = jQuery("<div/>"),
- $divTest = jQuery("<div>test</div>"),
- $divNone = jQuery("<div style='display: none;'/>"),
- $divInline = jQuery("<div style='display: inline;'/>"),
- nullParentDisplay = $divEmpty.css("display"),
- underFragmentDisplay = $divTest.css("display"),
+ $divEmpty = jQuery( "<div/>" ),
+ $divTest = jQuery( "<div>test</div>" ),
+ $divNone = jQuery( "<div style='display: none;'/>" ),
+ $divInline = jQuery( "<div style='display: inline;'/>" ),
+ nullParentDisplay = $divEmpty.css( "display" ),
+ underFragmentDisplay = $divTest.css( "display" ),
clock = this.clock;
assert.strictEqual( $divEmpty[ 0 ].parentNode, null, "Setup: element with null parentNode" );
- assert.strictEqual( ($divTest[ 0 ].parentNode || {}).nodeType, 11, "Setup: element under fragment" );
+ assert.strictEqual( ( $divTest[ 0 ].parentNode || {} ).nodeType, 11, "Setup: element under fragment" );
assert.strictEqual( $divEmpty.show()[ 0 ].style.display, "",
"set display with show() for element with null parentNode" );
@@ -1573,54 +1579,54 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser
QUnit.expectJqData( env, $divNone[ 0 ], "olddisplay" );
jQuery.each( methods, function( name, opt ) {
- jQuery.fn[ name ].apply( jQuery("<div/>"), opt.concat( [ function() {
+ jQuery.fn[ name ].apply( jQuery( "<div/>" ), opt.concat( [ function() {
assert.strictEqual( jQuery( this ).css( "display" ), nullParentDisplay,
"." + name + " block with null parentNode" );
} ] ) );
- jQuery.fn[ name ].apply( jQuery("<div>test</div>"), opt.concat( [ function() {
+ jQuery.fn[ name ].apply( jQuery( "<div>test</div>" ), opt.concat( [ function() {
assert.strictEqual( jQuery( this ).css( "display" ), underFragmentDisplay,
"." + name + " block under fragment" );
} ] ) );
- });
+ } );
clock.tick( 400 );
-});
+} );
-QUnit.test("Animation callback should not show animated element as :animated (#7157)", function( assert ) {
+QUnit.test( "Animation callback should not show animated element as :animated (#7157)", function( assert ) {
assert.expect( 1 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
opacity: 0
}, 100, function() {
- assert.ok( !foo.is(":animated"), "The element is not animated" );
- });
+ assert.ok( !foo.is( ":animated" ), "The element is not animated" );
+ } );
this.clock.tick( 100 );
-});
+} );
-QUnit.test("Initial step callback should show element as :animated (#14623)", function( assert ) {
+QUnit.test( "Initial step callback should show element as :animated (#14623)", function( assert ) {
assert.expect( 1 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
opacity: 0
}, {
duration: 100,
step: function() {
- assert.ok( foo.is(":animated"), "The element matches :animated inside step function" );
+ assert.ok( foo.is( ":animated" ), "The element matches :animated inside step function" );
}
- });
+ } );
this.clock.tick( 1 );
foo.stop();
-});
+} );
QUnit.test( "hide called on element within hidden parent should set display to none (#10045)", function( assert ) {
assert.expect( 3 );
- var hidden = jQuery(".hidden"),
- elems = jQuery("<div>hide</div><div>hide0</div><div>hide1</div>");
+ var hidden = jQuery( ".hidden" ),
+ elems = jQuery( "<div>hide</div><div>hide0</div><div>hide1</div>" );
hidden.append( elems );
@@ -1628,25 +1634,25 @@ QUnit.test( "hide called on element within hidden parent should set display to n
elems.eq( 0 ).hide(),
elems.eq( 1 ).hide( 0 ),
elems.eq( 2 ).hide( 1 )
- ).done(function() {
+ ).done( function() {
assert.strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" );
assert.strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
assert.strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
elems.remove();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", function( assert ) {
assert.expect( 5 );
- var foo = jQuery("#foo"),
+ var foo = jQuery( "#foo" ),
i = 0,
elems = jQuery();
for ( ; i < 5; i++ ) {
- elems = elems.add("<div style='width:0;height:0;'></div>");
+ elems = elems.add( "<div style='width:0;height:0;'></div>" );
}
foo.append( elems );
@@ -1657,7 +1663,7 @@ QUnit.test( "hide, fadeOut and slideUp called on element width height and width
elems.eq( 2 ).hide( 1 ),
elems.eq( 3 ).fadeOut(),
elems.eq( 4 ).slideUp()
- ).done(function() {
+ ).done( function() {
assert.strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" );
assert.strictEqual( elems.get( 1 ).style.display, "none",
"hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
@@ -1665,24 +1671,24 @@ QUnit.test( "hide, fadeOut and slideUp called on element width height and width
assert.strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
assert.strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
QUnit.test( "hide should not leave hidden inline elements visible (#14848)", function( assert ) {
assert.expect( 2 );
- var el = jQuery("#simon1");
+ var el = jQuery( "#simon1" );
el.hide( 1, function() {
assert.equal( el.css( "display" ), "none", "hidden" );
el.hide( 1, function() {
assert.equal( el.css( "display" ), "none", "still hidden" );
- });
- });
+ } );
+ } );
this.clock.tick( 100 );
-});
+} );
QUnit.test( "Handle queue:false promises", function( assert ) {
assert.expect( 10 );
@@ -1690,7 +1696,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
var foo = jQuery( "#foo" ).clone().addBack(),
step = 1;
- foo.animate({
+ foo.animate( {
top: 1
}, {
duration: 10,
@@ -1698,7 +1704,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
complete: function() {
assert.ok( step++ <= 2, "Step one or two" );
}
- }).animate({
+ } ).animate( {
bottom: 1
}, {
duration: 10,
@@ -1706,13 +1712,13 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
assert.ok( step > 2 && step < 5, "Step three or four" );
step++;
}
- });
+ } );
this.clock.tick( 10 );
foo.promise().done( function() {
assert.equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
- foo.animate({
+ foo.animate( {
top: 10
}, {
duration: 10,
@@ -1720,7 +1726,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
assert.ok( step > 5 && step < 8, "Step six or seven" );
step++;
}
- }).animate({
+ } ).animate( {
bottom: 10
}, {
duration: 10,
@@ -1729,20 +1735,20 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
assert.ok( step > 7 && step < 10, "Step eight or nine" );
step++;
}
- }).promise().done( function() {
+ } ).promise().done( function() {
assert.equal( step++, 10, "steps 6-10: queue:fx then queue:false" );
- });
+ } );
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "multiple unqueued and promise", function( assert ) {
assert.expect( 4 );
var foo = jQuery( "#foo" ),
step = 1;
- foo.animate({
+ foo.animate( {
marginLeft: 300
}, {
duration: 500,
@@ -1750,7 +1756,7 @@ QUnit.test( "multiple unqueued and promise", function( assert ) {
complete: function() {
assert.strictEqual( step++, 2, "Step 2" );
}
- }).animate({
+ } ).animate( {
top: 100
}, {
duration: 1000,
@@ -1758,54 +1764,55 @@ QUnit.test( "multiple unqueued and promise", function( assert ) {
complete: function() {
assert.strictEqual( step++, 3, "Step 3" );
}
- }).animate({}, {
+ } ).animate( {}, {
duration: 2000,
queue: false,
complete: function() {
+
// no properties is a non-op and finishes immediately
assert.strictEqual( step++, 1, "Step 1" );
}
- }).promise().done( function() {
+ } ).promise().done( function() {
assert.strictEqual( step++, 4, "Step 4" );
- });
+ } );
this.clock.tick( 1000 );
-});
+} );
QUnit.test( "animate does not change start value for non-px animation (#7109)", function( assert ) {
assert.expect( 1 );
- var parent = jQuery( "<div><div></div></div>" ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ),
- child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }),
+ var parent = jQuery( "<div><div></div></div>" ).css( { width: 284, height: 1 } ).appendTo( "#qunit-fixture" ),
+ child = parent.children().css( { fontSize: "98.6in", width: "0.01em", height: 1 } ),
actual = parseFloat( child.css( "width" ) ),
computed = [];
- child.animate({ width: "0%" }, {
+ child.animate( { width: "0%" }, {
duration: 1,
step: function() {
computed.push( parseFloat( child.css( "width" ) ) );
}
- }).queue( function( next ) {
+ } ).queue( function( next ) {
var ratio = computed[ 0 ] / actual;
- assert.ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
+ assert.ok( ratio > 0.9 && ratio < 1.1, "Starting width was close enough" );
next();
parent.remove();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "non-px animation handles non-numeric start (#11971)", function( assert ) {
assert.expect( 2 );
- var foo = jQuery("#foo"),
- initial = foo.css("backgroundPositionX");
+ var foo = jQuery( "#foo" ),
+ initial = foo.css( "backgroundPositionX" );
if ( !initial ) {
- assert.expect(1);
+ assert.expect( 1 );
assert.ok( true, "Style property not understood" );
return;
}
- foo.animate({ backgroundPositionX: "42%" }, {
+ foo.animate( { backgroundPositionX: "42%" }, {
duration: 1,
progress: function( anim, percent ) {
if ( percent ) {
@@ -1821,14 +1828,14 @@ QUnit.test( "non-px animation handles non-numeric start (#11971)", function( ass
done: function() {
assert.equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
}
- });
+ } );
this.clock.tick( 10 );
-});
+} );
-QUnit.test("Animation callbacks (#11797)", function( assert ) {
+QUnit.test( "Animation callbacks (#11797)", function( assert ) {
assert.expect( 15 );
- var targets = jQuery("#foo").children(),
+ var targets = jQuery( "#foo" ).children(),
done = false,
expectedProgress = 0;
@@ -1850,12 +1857,12 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) {
assert.ok( true, "empty: always" );
done = true;
}
- });
+ } );
assert.ok( done, "empty: done immediately" );
done = false;
- targets.eq( 1 ).animate({
+ targets.eq( 1 ).animate( {
opacity: 0
}, {
duration: 1,
@@ -1875,11 +1882,11 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) {
assert.ok( true, "stopped: always" );
done = true;
}
- }).stop();
+ } ).stop();
assert.ok( done, "stopped: stopped immediately" );
- targets.eq( 2 ).animate({
+ targets.eq( 2 ).animate( {
opacity: 0
}, {
duration: 1,
@@ -1887,11 +1894,13 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) {
assert.ok( true, "async: start" );
},
progress: function( anim, percent ) {
+
// occasionally the progress handler is called twice in first frame.... *shrug*
if ( percent === 0 && expectedProgress === 1 ) {
return;
}
assert.equal( percent, expectedProgress, "async: progress " + expectedProgress );
+
// once at 0, once at 1
expectedProgress++;
},
@@ -1904,16 +1913,16 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) {
always: function() {
assert.ok( true, "async: always" );
}
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "Animate properly sets overflow hidden when animating width/height (#12117)", function( assert ) {
assert.expect( 8 );
jQuery.each( [ "height", "width" ], function( _, prop ) {
jQuery.each( [ 100, 0 ], function( _, value ) {
- var div = jQuery("<div>").css( "overflow", "auto" ),
+ var div = jQuery( "<div>" ).css( "overflow", "auto" ),
props = {};
props[ prop ] = value;
div.animate( props, 1 );
@@ -1922,24 +1931,24 @@ QUnit.test( "Animate properly sets overflow hidden when animating width/height (
div.stop();
assert.equal( div.css( "overflow" ), "auto",
"overflow: auto restored after animating " + prop + " to " + value );
- });
- });
-});
+ } );
+ } );
+} );
QUnit.test( "Each tick of the timer loop uses a fresh time (#12837)", function( assert ) {
var lastVal,
- tmp = jQuery({
+ tmp = jQuery( {
test: 0
- });
+ } );
assert.expect( 3 );
- tmp.animate({
+ tmp.animate( {
test: 100
}, {
step: function( p, fx ) {
assert.ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
lastVal = fx.now;
}
- });
+ } );
this.clock.tick( 1 );
// now that we have a new time, run another tick
@@ -1949,7 +1958,7 @@ QUnit.test( "Each tick of the timer loop uses a fresh time (#12837)", function(
jQuery.fx.tick();
tmp.stop();
-});
+} );
QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert ) {
assert.expect( 1 );
@@ -1958,7 +1967,7 @@ QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert )
assert.ok( false, "Called easing" );
};
- jQuery( "#foo" ).animate({
+ jQuery( "#foo" ).animate( {
height: 100
}, {
duration: 0,
@@ -1966,12 +1975,13 @@ QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert )
complete: function() {
assert.equal( jQuery( this ).height(), 100, "Height is 100" );
}
- });
+ } );
delete jQuery.easing.test;
-});
+} );
+
+jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) {
-jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
// this test would look a lot better if we were using something to override
// the default timers
var duration = 1500;
@@ -1979,7 +1989,7 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
function secondToggle() {
var stopped = parseFloat( element.css( check ) );
tested = false;
- element[ method ]({
+ element[ method ]( {
duration: duration,
step: function( p, fx ) {
if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
@@ -1989,17 +1999,17 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
element.stop();
}
}
- });
+ } );
}
var tested,
original,
check = method === "slideToggle" ? "height" : "opacity",
- element = jQuery("#foo").height( 200 );
+ element = jQuery( "#foo" ).height( 200 );
assert.expect( 4 );
- element[ method ]({
+ element[ method ]( {
duration: duration,
easing: "linear",
step: function( p, fx ) {
@@ -2012,16 +2022,17 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
}
},
always: secondToggle
- });
+ } );
+
//FIXME figure out why 470
this.clock.tick( 470 );
- });
-});
+ } );
+} );
QUnit.test( "jQuery.fx.start & jQuery.fx.stop hook points", function( assert ) {
var oldStart = jQuery.fx.start,
oldStop = jQuery.fx.stop,
- foo = jQuery({ foo: 0 });
+ foo = jQuery( { foo: 0 } );
assert.expect( 3 );
@@ -2033,17 +2044,19 @@ QUnit.test( "jQuery.fx.start & jQuery.fx.stop hook points", function( assert ) {
};
// calls start
- foo.animate({ foo: 1 }, { queue: false });
+ foo.animate( { foo: 1 }, { queue: false } );
+
// calls start
- foo.animate({ foo: 2 }, { queue: false });
+ foo.animate( { foo: 2 }, { queue: false } );
foo.stop();
+
// calls stop
jQuery.fx.tick();
// cleanup
jQuery.fx.start = oldStart;
jQuery.fx.stop = oldStop;
-});
+} );
QUnit.test( ".finish() completes all queued animations", function( assert ) {
var animations = {
@@ -2052,31 +2065,33 @@ QUnit.test( ".finish() completes all queued animations", function( assert ) {
height: 100,
width: 100
},
- div = jQuery("<div>");
+ div = jQuery( "<div>" );
assert.expect( 11 );
jQuery.each( animations, function( prop, value ) {
var anim = {};
anim[ prop ] = value;
+
// the delay shouldn't matter at all!
div.css( prop, 1 ).animate( anim, function() {
assert.ok( true, "Called animation callback for " + prop );
- }).delay( 100 );
- });
+ } ).delay( 100 );
+ } );
assert.equal( div.queue().length, 8, "8 animations in the queue" );
div.finish();
jQuery.each( animations, function( prop, value ) {
assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
+ } );
assert.equal( div.queue().length, 0, "empty queue when done" );
- assert.equal( div.is(":animated"), false, ":animated doesn't match" );
+ assert.equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
QUnit.test( ".finish( false ) - unqueued animations", function( assert ) {
var animations = {
@@ -2085,7 +2100,7 @@ QUnit.test( ".finish( false ) - unqueued animations", function( assert ) {
height: 100,
width: 100
},
- div = jQuery("<div>");
+ div = jQuery( "<div>" );
assert.expect( 10 );
@@ -2097,20 +2112,21 @@ QUnit.test( ".finish( false ) - unqueued animations", function( assert ) {
complete: function() {
assert.ok( true, "Called animation callback for " + prop );
}
- });
- });
+ } );
+ } );
assert.equal( div.queue().length, 0, "0 animations in the queue" );
div.finish( false );
jQuery.each( animations, function( prop, value ) {
assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
- assert.equal( div.is(":animated"), false, ":animated doesn't match" );
+ } );
+ assert.equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert ) {
var animations = {
@@ -2119,7 +2135,7 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert
height: 100,
width: 100
},
- div = jQuery("<div>");
+ div = jQuery( "<div>" );
assert.expect( 11 );
@@ -2131,30 +2147,32 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert
complete: function() {
assert.ok( true, "Called animation callback for " + prop );
}
- });
- });
+ } );
+ } );
assert.equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
+
// start the first animation
div.dequeue( "custom" );
- assert.equal( div.is(":animated"), true, ":animated matches" );
+ assert.equal( div.is( ":animated" ), true, ":animated matches" );
div.finish( "custom" );
jQuery.each( animations, function( prop, value ) {
assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
- assert.equal( div.is(":animated"), false, ":animated doesn't match" );
+ } );
+ assert.equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
QUnit.test( ".finish() calls finish of custom queue functions", function( assert ) {
function queueTester( next, hooks ) {
hooks.stop = function( gotoEnd ) {
inside++;
- assert.equal( this, div[0] );
- assert.ok( gotoEnd, "hooks.stop(true) called");
+ assert.equal( this, div[ 0 ] );
+ assert.ok( gotoEnd, "hooks.stop(true) called" );
};
}
var div = jQuery( "<div>" ),
@@ -2173,15 +2191,15 @@ QUnit.test( ".finish() calls finish of custom queue functions", function( assert
assert.equal( outside, 2, "2 finish callbacks" );
div.remove();
-});
+} );
QUnit.test( ".finish() is applied correctly when multiple elements were animated (#13937)", function( assert ) {
assert.expect( 3 );
- var elems = jQuery("<a>0</a><a>1</a><a>2</a>");
+ var elems = jQuery( "<a>0</a><a>1</a><a>2</a>" );
elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
- setTimeout(function() {
+ setTimeout( function() {
elems.eq( 1 ).finish();
assert.ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
assert.ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
@@ -2190,13 +2208,13 @@ QUnit.test( ".finish() is applied correctly when multiple elements were animated
}, 100 );
this.clock.tick( 1500 );
-});
+} );
QUnit.test( "slideDown() after stop() (#13483)", function( assert ) {
assert.expect( 2 );
var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" )
- .appendTo("#qunit-fixture"),
+ .appendTo( "#qunit-fixture" ),
origHeight = ul.height(),
clock = this.clock;
@@ -2220,10 +2238,10 @@ QUnit.test( "slideDown() after stop() (#13483)", function( assert ) {
ul.remove();
clock.tick( 10 );
- });
+ } );
clock.tick( 10 );
-});
+} );
QUnit.test( "Respect display value on inline elements (#14824)", function( assert ) {
assert.expect( 2 );
@@ -2234,22 +2252,22 @@ QUnit.test( "Respect display value on inline elements (#14824)", function( asser
jQuery( "#qunit-fixture" ).append( fromStyleSheet, fromStyleAttr );
- fromStyleSheet.slideUp(function() {
+ fromStyleSheet.slideUp( function() {
jQuery( this ).slideDown( function() {
assert.equal( jQuery( this ).css( "display" ), "block",
"Respect previous display value (from stylesheet) on span element" );
- });
- });
+ } );
+ } );
fromStyleAttr.slideUp( function() {
jQuery( this ).slideDown( function() {
assert.equal( jQuery( this ).css( "display" ), "block",
"Respect previous display value (from style attribute) on span element" );
- });
- });
+ } );
+ } );
clock.tick( 800 );
-});
+} );
QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) {
assert.expect( 2 );
@@ -2261,7 +2279,7 @@ QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) {
assert.equal( anim.opts.easing, jQuery.easing._default,
"anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
}
- })
+ } )
.animate( { height: "5px" }, {
duration: 5,
easing: "linear",
@@ -2269,11 +2287,11 @@ QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) {
assert.equal( anim.opts.easing, "linear",
"anim.opts.easing should be equal to the easing argument" );
}
- })
+ } )
.stop();
this.clock.tick( 25 );
-});
+} );
QUnit.test( "jQuery.easing._default in Animation (gh-2218", function( assert ) {
assert.expect( 3 );
@@ -2298,10 +2316,10 @@ QUnit.test( "jQuery.easing._default in Animation (gh-2218", function( assert ) {
"Animation used custom jQuery.easing._default" );
jQuery.easing._default = defaultEasing;
delete jQuery.easing.custom;
- });
+ } );
this.clock.tick( 10 );
-});
+} );
QUnit.test( "jQuery.easing._default in Tween (gh-2218)", function( assert ) {
assert.expect( 3 );
@@ -2325,33 +2343,33 @@ QUnit.test( "jQuery.easing._default in Tween (gh-2218)", function( assert ) {
"Animation used custom jQuery.easing._default" );
jQuery.easing._default = defaultEasing;
delete jQuery.easing.custom;
-});
+} );
QUnit.test( "Display value is correct for disconnected nodes (trac-13310)", function( assert ) {
assert.expect( 3 );
- var div = jQuery("<div/>");
+ var div = jQuery( "<div/>" );
- assert.equal( div.css( "display", "inline" ).hide().show().appendTo("body").css( "display" ), "inline", "Initialized display value has returned" );
+ assert.equal( div.css( "display", "inline" ).hide().show().appendTo( "body" ).css( "display" ), "inline", "Initialized display value has returned" );
div.remove();
div.css( "display", "none" ).hide();
assert.equal( jQuery._data( div[ 0 ], "olddisplay" ), undefined, "olddisplay is undefined after hiding a detached and hidden element" );
div.remove();
- div.css( "display", "inline-block" ).hide().appendTo("body").fadeIn(function() {
+ div.css( "display", "inline-block" ).hide().appendTo( "body" ).fadeIn( function() {
assert.equal( div.css( "display" ), "inline-block", "Initialized display value has returned" );
div.remove();
- });
+ } );
this.clock.tick( 1000 );
-});
+} );
QUnit.test( "Show/hide/toggle and display: inline", function( assert ) {
assert.expect( 40 );
var clock = this.clock;
- jQuery( "<span/><div style='display:inline' title='inline div'/>" ).each(function() {
+ jQuery( "<span/><div style='display:inline' title='inline div'/>" ).each( function() {
var completed, interrupted,
N = 100,
fixture = jQuery( "#qunit-fixture" ),
@@ -2360,59 +2378,59 @@ QUnit.test( "Show/hide/toggle and display: inline", function( assert ) {
// Animations allowed to complete
completed = jQuery.map( [
- $el.clone().data({ call: "hide", done: "none" }).appendTo( fixture ).hide( N ),
- $el.clone().data({ call: "toggle", done: "none" }).appendTo( fixture ).toggle( N ),
- $el.clone().data({ call: "hide+show", done: "inline" }).appendTo( fixture )
+ $el.clone().data( { call: "hide", done: "none" } ).appendTo( fixture ).hide( N ),
+ $el.clone().data( { call: "toggle", done: "none" } ).appendTo( fixture ).toggle( N ),
+ $el.clone().data( { call: "hide+show", done: "inline" } ).appendTo( fixture )
.hide().show( N ),
- $el.clone().data({ call: "hide+toggle", done: "inline" }).appendTo( fixture )
+ $el.clone().data( { call: "hide+toggle", done: "inline" } ).appendTo( fixture )
.hide().toggle( N )
], function( $clone ) { return $clone[ 0 ]; } );
// Animations not allowed to complete
interrupted = jQuery.map( [
- $el.clone().data({ call: "hide+stop" }).appendTo( fixture ).hide( N ),
- $el.clone().data({ call: "toggle+stop" }).appendTo( fixture ).toggle( N ),
- $el.clone().data({ call: "hide+show+stop" }).appendTo( fixture ).hide().show( N ),
- $el.clone().data({ call: "hide+toggle+stop" }).appendTo( fixture ).hide().toggle( N )
+ $el.clone().data( { call: "hide+stop" } ).appendTo( fixture ).hide( N ),
+ $el.clone().data( { call: "toggle+stop" } ).appendTo( fixture ).toggle( N ),
+ $el.clone().data( { call: "hide+show+stop" } ).appendTo( fixture ).hide().show( N ),
+ $el.clone().data( { call: "hide+toggle+stop" } ).appendTo( fixture ).hide().toggle( N )
], function( $clone ) { return $clone[ 0 ]; } );
// All elements should be inline-block during the animation
clock.tick( N / 2 );
- jQuery( completed ).each(function() {
+ jQuery( completed ).each( function() {
var $el = jQuery( this ),
call = $el.data( "call" );
assert.strictEqual( $el.css( "display" ), "inline-block", kind + " display during " + call );
- });
+ } );
// Interrupted elements should remain inline-block
jQuery( interrupted ).stop();
clock.tick( N / 2 );
- jQuery( interrupted ).each(function() {
+ jQuery( interrupted ).each( function() {
var $el = jQuery( this ),
call = $el.data( "call" );
assert.strictEqual( $el.css( "display" ), "inline-block", kind + " display after " + call );
- });
+ } );
// Completed elements should not remain inline-block
clock.tick( N / 2 );
- jQuery( completed ).each(function() {
+ jQuery( completed ).each( function() {
var $el = jQuery( this ),
call = $el.data( "call" ),
display = $el.data( "done" );
assert.strictEqual( $el.css( "display" ), display, kind + " display after " + call );
- });
+ } );
// A post-animation toggle should not make any element inline-block
completed = jQuery( completed.concat( interrupted ) );
completed.toggle( N / 2 );
clock.tick( N );
- completed.each(function() {
+ completed.each( function() {
var $el = jQuery( this ),
call = $el.data( "call" );
assert.ok( $el.css( "display" ) !== "inline-block",
kind + " display is not inline-block after " + call + "+toggle" );
- });
- });
-});
+ } );
+ } );
+} );
-})();
+} )();
diff --git a/test/unit/event.js b/test/unit/event.js
index 8b0976721..6f4e6824e 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -3,28 +3,28 @@ QUnit.module( "event", {
document.body.focus();
},
teardown: moduleTeardown
-});
+} );
-QUnit.test("on() with non-null,defined data", function( assert ) {
+QUnit.test( "on() with non-null,defined data", function( assert ) {
- assert.expect(2);
+ assert.expect( 2 );
var handler = function( event, data ) {
assert.equal( data, 0, "non-null, defined data (zero) is correctly passed" );
};
- jQuery("#foo").on("foo.on", handler);
- jQuery("div").on("foo.delegate", "#foo", handler);
+ jQuery( "#foo" ).on( "foo.on", handler );
+ jQuery( "div" ).on( "foo.delegate", "#foo", handler );
- jQuery("#foo").trigger("foo", 0);
+ jQuery( "#foo" ).trigger( "foo", 0 );
- jQuery("#foo").off("foo.on", handler);
- jQuery("div").off("foo.delegate", "#foo");
+ jQuery( "#foo" ).off( "foo.on", handler );
+ jQuery( "div" ).off( "foo.delegate", "#foo" );
-});
+} );
-QUnit.test("Handler changes and .trigger() order", function( assert ) {
- assert.expect(1);
+QUnit.test( "Handler changes and .trigger() order", function( assert ) {
+ assert.expect( 1 );
var markup = jQuery(
"<div><div><p><span><b class=\"a\">b</b></span></p></div></div>"
@@ -34,154 +34,154 @@ QUnit.test("Handler changes and .trigger() order", function( assert ) {
markup
.find( "*" ).addBack().on( "click", function() {
path += this.nodeName.toLowerCase() + " ";
- })
+ } )
.filter( "b" ).on( "click", function( e ) {
+
// Removing span should not stop propagation to original parents
if ( e.target === this ) {
- jQuery(this).parent().remove();
+ jQuery( this ).parent().remove();
}
- });
+ } );
markup.find( "b" ).trigger( "click" );
assert.equal( path, "b p div div ", "Delivered all events" );
markup.remove();
-});
+} );
-QUnit.test("on(), with data", function( assert ) {
- assert.expect(4);
+QUnit.test( "on(), with data", function( assert ) {
+ assert.expect( 4 );
var test, handler, handler2;
- handler = function(event) {
+ handler = function( event ) {
assert.ok( event.data, "on() with data, check passed data exists" );
- assert.equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
+ assert.equal( event.data[ "foo" ], "bar", "on() with data, Check value of passed data" );
};
- jQuery("#firstp").on("click", {"foo": "bar"}, handler).trigger("click").off("click", handler);
+ jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler );
- assert.ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
+ assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." );
- test = function(){};
- handler2 = function(event) {
+ test = function() {};
+ handler2 = function( event ) {
assert.equal( event.data, test, "on() with function data, Check value of passed data" );
};
- jQuery("#firstp").on("click", test, handler2).trigger("click").off("click", handler2);
-});
+ jQuery( "#firstp" ).on( "click", test, handler2 ).trigger( "click" ).off( "click", handler2 );
+} );
-QUnit.test("click(), with data", function( assert ) {
- assert.expect(3);
- var handler = function(event) {
+QUnit.test( "click(), with data", function( assert ) {
+ assert.expect( 3 );
+ var handler = function( event ) {
assert.ok( event.data, "on() with data, check passed data exists" );
- assert.equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
+ assert.equal( event.data[ "foo" ], "bar", "on() with data, Check value of passed data" );
};
- jQuery("#firstp").on( "click", {"foo": "bar"}, handler).trigger("click").off("click", handler);
+ jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler );
- assert.ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
-});
+ assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." );
+} );
-QUnit.test("on(), with data, trigger with data", function( assert ) {
- assert.expect(4);
- var handler = function(event, data) {
+QUnit.test( "on(), with data, trigger with data", function( assert ) {
+ assert.expect( 4 );
+ var handler = function( event, data ) {
assert.ok( event.data, "check passed data exists" );
assert.equal( event.data.foo, "bar", "Check value of passed data" );
assert.ok( data, "Check trigger data" );
assert.equal( data.bar, "foo", "Check value of trigger data" );
};
- jQuery("#firstp").on("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).off("click", handler);
-});
+ jQuery( "#firstp" ).on( "click", { foo: "bar" }, handler ).trigger( "click", [ { bar: "foo" } ] ).off( "click", handler );
+} );
-QUnit.test("on(), multiple events at once", function( assert ) {
- assert.expect(2);
+QUnit.test( "on(), multiple events at once", function( assert ) {
+ assert.expect( 2 );
var handler,
clickCounter = 0,
mouseoverCounter = 0;
- handler = function(event) {
- if (event.type === "click") {
+ handler = function( event ) {
+ if ( event.type === "click" ) {
clickCounter += 1;
- }
- else if (event.type === "mouseover") {
+ } else if ( event.type === "mouseover" ) {
mouseoverCounter += 1;
}
};
- jQuery("#firstp").on("click mouseover", handler).trigger("click").trigger("mouseover");
+ jQuery( "#firstp" ).on( "click mouseover", handler ).trigger( "click" ).trigger( "mouseover" );
assert.equal( clickCounter, 1, "on() with multiple events at once" );
assert.equal( mouseoverCounter, 1, "on() with multiple events at once" );
-});
+} );
-QUnit.test("on(), five events at once", function( assert ) {
- assert.expect(1);
+QUnit.test( "on(), five events at once", function( assert ) {
+ assert.expect( 1 );
var count = 0,
handler = function() {
count++;
};
- jQuery("#firstp").on("click mouseover foo bar baz", handler)
- .trigger("click").trigger("mouseover")
- .trigger("foo").trigger("bar")
- .trigger("baz");
+ jQuery( "#firstp" ).on( "click mouseover foo bar baz", handler )
+ .trigger( "click" ).trigger( "mouseover" )
+ .trigger( "foo" ).trigger( "bar" )
+ .trigger( "baz" );
assert.equal( count, 5, "on() five events at once" );
-});
+} );
-QUnit.test("on(), multiple events at once and namespaces", function( assert ) {
- assert.expect(7);
+QUnit.test( "on(), multiple events at once and namespaces", function( assert ) {
+ assert.expect( 7 );
var cur, div,
obj = {};
- div = jQuery("<div/>").on("focusin.a", function(e) {
+ div = jQuery( "<div/>" ).on( "focusin.a", function( e ) {
assert.equal( e.type, cur, "Verify right single event was fired." );
- });
+ } );
cur = "focusin";
- div.trigger("focusin.a");
+ div.trigger( "focusin.a" );
// manually clean up detached elements
div.remove();
- div = jQuery("<div/>").on("click mouseover", obj, function(e) {
+ div = jQuery( "<div/>" ).on( "click mouseover", obj, function( e ) {
assert.equal( e.type, cur, "Verify right multi event was fired." );
assert.equal( e.data, obj, "Make sure the data came in correctly." );
- });
+ } );
cur = "click";
- div.trigger("click");
+ div.trigger( "click" );
cur = "mouseover";
- div.trigger("mouseover");
+ div.trigger( "mouseover" );
// manually clean up detached elements
div.remove();
- div = jQuery("<div/>").on("focusin.a focusout.b", function(e) {
+ div = jQuery( "<div/>" ).on( "focusin.a focusout.b", function( e ) {
assert.equal( e.type, cur, "Verify right multi event was fired." );
- });
+ } );
cur = "focusin";
- div.trigger("focusin.a");
+ div.trigger( "focusin.a" );
cur = "focusout";
- div.trigger("focusout.b");
+ div.trigger( "focusout.b" );
// manually clean up detached elements
div.remove();
-});
+} );
-QUnit.test("on(), namespace with special add", function( assert ) {
- assert.expect(27);
+QUnit.test( "on(), namespace with special add", function( assert ) {
+ assert.expect( 27 );
var i = 0,
- div = jQuery("<div/>").appendTo("#qunit-fixture").on( "test", function() {
+ div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "test", function() {
assert.ok( true, "Test event fired." );
- });
+ } );
- jQuery.event.special["test"] = {
+ jQuery.event.special[ "test" ] = {
_default: function( e, data ) {
assert.equal( e.type, "test", "Make sure we're dealing with a test event." );
assert.ok( data, "And that trigger data was passed." );
- assert.strictEqual( e.target, div[0], "And that the target is correct." );
+ assert.strictEqual( e.target, div[ 0 ], "And that the target is correct." );
assert.equal( this, window, "And that the context is correct." );
},
setup: function() {},
@@ -202,13 +202,13 @@ QUnit.test("on(), namespace with special add", function( assert ) {
div.on( "test.a", { x: 1 }, function( e ) {
assert.ok( !!e.xyz, "Make sure that the data is getting passed through." );
- assert.equal( e.data["x"], 1, "Make sure data is attached properly." );
- });
+ assert.equal( e.data[ "x" ], 1, "Make sure data is attached properly." );
+ } );
div.on( "test.b", { x: 2 }, function( e ) {
assert.ok( !!e.xyz, "Make sure that the data is getting passed through." );
- assert.equal( e.data["x"], 2, "Make sure data is attached properly." );
- });
+ assert.equal( e.data[ "x" ], 2, "Make sure data is attached properly." );
+ } );
// Should trigger 5
div.trigger( "test", 33.33 );
@@ -220,61 +220,63 @@ QUnit.test("on(), namespace with special add", function( assert ) {
div.trigger( "test.b", { year: 1982 } );
// Should trigger 4
- div.off("test");
+ div.off( "test" );
- div = jQuery("<div/>").on( "test", function() {
+ div = jQuery( "<div/>" ).on( "test", function() {
assert.ok( true, "Test event fired." );
- });
+ } );
// Should trigger 2
- div.appendTo("#qunit-fixture").remove();
+ div.appendTo( "#qunit-fixture" ).remove();
- delete jQuery.event.special["test"];
-});
+ delete jQuery.event.special[ "test" ];
+} );
-QUnit.test("on(), no data", function( assert ) {
- assert.expect(1);
- var handler = function(event) {
+QUnit.test( "on(), no data", function( assert ) {
+ assert.expect( 1 );
+ var handler = function( event ) {
ok ( !event.data, "Check that no data is added to the event object" );
};
- jQuery("#firstp").on("click", handler).trigger("click");
-});
+ jQuery( "#firstp" ).on( "click", handler ).trigger( "click" );
+} );
-QUnit.test("on/one/off(Object)", function( assert ){
- assert.expect(6);
+QUnit.test( "on/one/off(Object)", function( assert ) {
+ assert.expect( 6 );
var $elem,
clickCounter = 0,
mouseoverCounter = 0;
- function handler(event) {
- if (event.type === "click") {
+ function handler( event ) {
+ if ( event.type === "click" ) {
clickCounter++;
- } else if (event.type === "mouseover") {
+ } else if ( event.type === "mouseover" ) {
mouseoverCounter++;
}
}
- function handlerWithData(event) {
- if (event.type === "click") {
+ function handlerWithData( event ) {
+ if ( event.type === "click" ) {
clickCounter += event.data;
- } else if (event.type === "mouseover") {
+ } else if ( event.type === "mouseover" ) {
mouseoverCounter += event.data;
}
}
- function trigger(){
- $elem.trigger("click").trigger("mouseover");
+ function trigger() {
+ $elem.trigger( "click" ).trigger( "mouseover" );
}
- $elem = jQuery("#firstp")
+ $elem = jQuery( "#firstp" )
+
// Regular bind
- .on({
+ .on( {
"click":handler,
"mouseover":handler
- })
+ } )
+
// Bind with data
- .one({
+ .one( {
"click":handlerWithData,
"mouseover":handlerWithData
}, 2 );
@@ -288,24 +290,24 @@ QUnit.test("on/one/off(Object)", function( assert ){
assert.equal( clickCounter, 4, "on(Object)" );
assert.equal( mouseoverCounter, 4, "on(Object)" );
- jQuery("#firstp").off({
+ jQuery( "#firstp" ).off( {
"click":handler,
"mouseover":handler
- });
+ } );
trigger();
assert.equal( clickCounter, 4, "on(Object)" );
assert.equal( mouseoverCounter, 4, "on(Object)" );
-});
+} );
-QUnit.test("on/off(Object), on/off(Object, String)", function( assert ) {
- assert.expect(6);
+QUnit.test( "on/off(Object), on/off(Object, String)", function( assert ) {
+ assert.expect( 6 );
var events,
clickCounter = 0,
mouseoverCounter = 0,
- $p = jQuery("#firstp"),
- $a = $p.find("a").eq(0);
+ $p = jQuery( "#firstp" ),
+ $a = $p.find( "a" ).eq( 0 );
events = {
"click": function( event ) {
@@ -317,7 +319,7 @@ QUnit.test("on/off(Object), on/off(Object, String)", function( assert ) {
};
function trigger() {
- $a.trigger("click").trigger("mouseover");
+ $a.trigger( "click" ).trigger( "mouseover" );
}
jQuery( document ).on( events, "#firstp a" );
@@ -338,41 +340,41 @@ QUnit.test("on/off(Object), on/off(Object, String)", function( assert ) {
trigger();
assert.equal( clickCounter, 4, "off" );
assert.equal( mouseoverCounter, 4, "off" );
-});
+} );
-QUnit.test("on immediate propagation", function( assert ) {
- assert.expect(2);
+QUnit.test( "on immediate propagation", function( assert ) {
+ assert.expect( 2 );
var lastClick,
- $p = jQuery("#firstp"),
- $a = $p.find("a").eq(0);
+ $p = jQuery( "#firstp" ),
+ $a = $p.find( "a" ).eq( 0 );
lastClick = "";
- jQuery( document ).on( "click", "#firstp a", function(e) {
+ jQuery( document ).on( "click", "#firstp a", function( e ) {
lastClick = "click1";
e.stopImmediatePropagation();
- });
+ } );
jQuery( document ).on( "click", "#firstp a", function() {
lastClick = "click2";
- });
+ } );
$a.trigger( "click" );
assert.equal( lastClick, "click1", "on stopImmediatePropagation" );
jQuery( document ).off( "click", "#firstp a" );
lastClick = "";
- $p.on( "click", "a", function(e) {
+ $p.on( "click", "a", function( e ) {
lastClick = "click1";
e.stopImmediatePropagation();
- });
+ } );
$p.on( "click", "a", function() {
lastClick = "click2";
- });
+ } );
$a.trigger( "click" );
assert.equal( lastClick, "click1", "on stopImmediatePropagation" );
$p.off( "click", "**" );
-});
+} );
-QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function( assert ) {
+QUnit.test( "on bubbling, isDefaultPrevented, stopImmediatePropagation", function( assert ) {
assert.expect( 3 );
var $anchor2 = jQuery( "#anchor2" ),
@@ -380,27 +382,29 @@ QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function
neverCallMe = function() {
assert.ok( false, "immediate propagation should have been stopped" );
},
- fakeClick = function($jq) {
+ fakeClick = function( $jq ) {
+
// Use a native click so we don't get jQuery simulated bubbling
var e = document.createEvent( "MouseEvents" );
e.initEvent( "click", true, true );
$jq[ 0 ].dispatchEvent( e );
};
- $anchor2.on( "click", function(e) {
+ $anchor2.on( "click", function( e ) {
e.preventDefault();
- });
+ } );
$main.on( "click", "#foo", function( e ) {
assert.equal( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" );
- });
+ } );
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
$anchor2.on( "click", function() {
+
// Let the default action occur
- });
- $main.on("click", "#foo", function(e) {
+ } );
+ $main.on( "click", "#foo", function( e ) {
assert.equal( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" );
- });
+ } );
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
@@ -414,91 +418,91 @@ QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function
$anchor2.on( "click", function( e ) {
e.stopImmediatePropagation();
assert.ok( true, "anchor was clicked and prop stopped" );
- });
- $anchor2[0].addEventListener( "click", neverCallMe, false );
+ } );
+ $anchor2[ 0 ].addEventListener( "click", neverCallMe, false );
fakeClick( $anchor2 );
- $anchor2[0].removeEventListener( "click", neverCallMe );
+ $anchor2[ 0 ].removeEventListener( "click", neverCallMe );
}
-});
+} );
-QUnit.test("on(), iframes", function( assert ) {
+QUnit.test( "on(), iframes", function( assert ) {
assert.expect( 1 );
// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
- var doc = jQuery("#loadediframe").contents();
+ var doc = jQuery( "#loadediframe" ).contents();
- jQuery("div", doc).on("click", function() {
+ jQuery( "div", doc ).on( "click", function() {
assert.ok( true, "Binding to element inside iframe" );
- }).trigger("click").off("click");
-});
+ } ).trigger( "click" ).off( "click" );
+} );
-QUnit.test("on(), trigger change on select", function( assert ) {
- assert.expect(5);
+QUnit.test( "on(), trigger change on select", function( assert ) {
+ assert.expect( 5 );
var counter = 0;
- function selectOnChange(event) {
+ function selectOnChange( event ) {
assert.equal( event.data, counter++, "Event.data is not a global event object" );
}
- jQuery("#form select").each(function(i){
- jQuery(this).on("change", i, selectOnChange);
- }).trigger("change");
-});
+ jQuery( "#form select" ).each( function( i ) {
+ jQuery( this ).on( "change", i, selectOnChange );
+ } ).trigger( "change" );
+} );
-QUnit.test("on(), namespaced events, cloned events", function( assert ) {
+QUnit.test( "on(), namespaced events, cloned events", function( assert ) {
assert.expect( 18 );
var firstp = jQuery( "#firstp" );
- firstp.on("custom.test",function(){
- assert.ok(false, "Custom event triggered");
- });
+ firstp.on( "custom.test", function() {
+ assert.ok( false, "Custom event triggered" );
+ } );
- firstp.on("click",function(e){
- assert.ok(true, "Normal click triggered");
+ firstp.on( "click", function( e ) {
+ assert.ok( true, "Normal click triggered" );
assert.equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
- });
+ } );
- firstp.on("click.test",function(e){
+ firstp.on( "click.test", function( e ) {
var check = "click";
assert.ok( true, "Namespaced click triggered" );
if ( e.namespace ) {
check += "test";
}
assert.equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" );
- });
+ } );
//clone(true) element to verify events are cloned correctly
firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) );
// Trigger both bound fn (8)
- firstp.trigger("click");
+ firstp.trigger( "click" );
// Trigger one bound fn (4)
- firstp.trigger("click.test");
+ firstp.trigger( "click.test" );
// Remove only the one fn
- firstp.off("click.test");
+ firstp.off( "click.test" );
// Trigger the remaining fn (4)
- firstp.trigger("click");
+ firstp.trigger( "click" );
// Remove the remaining namespaced fn
- firstp.off(".test");
+ firstp.off( ".test" );
// Try triggering the custom event (0)
- firstp.trigger("custom");
+ firstp.trigger( "custom" );
// using contents will get comments regular, text, and comment nodes
- jQuery("#nonnodes").contents().on("tester", function () {
- assert.equal(this.nodeType, 1, "Check node,textnode,comment on just does real nodes" );
- }).trigger("tester");
+ jQuery( "#nonnodes" ).contents().on( "tester", function() {
+ assert.equal( this.nodeType, 1, "Check node,textnode,comment on just does real nodes" );
+ } ).trigger( "tester" );
// Make sure events stick with appendTo'd elements (which are cloned) #2027
- jQuery("<a href='#fail' class='test'>test</a>").on( "click", function(){ return false; }).appendTo("#qunit-fixture");
- assert.ok( jQuery("a.test").eq(0).triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
-});
+ jQuery( "<a href='#fail' class='test'>test</a>" ).on( "click", function() { return false; } ).appendTo( "#qunit-fixture" );
+ assert.ok( jQuery( "a.test" ).eq( 0 ).triggerHandler( "click" ) === false, "Handler is bound to appendTo'd elements" );
+} );
-QUnit.test("on(), multi-namespaced events", function( assert ) {
- assert.expect(6);
+QUnit.test( "on(), multi-namespaced events", function( assert ) {
+ assert.expect( 6 );
var order = [
"click.test.abc",
@@ -509,120 +513,120 @@ QUnit.test("on(), multi-namespaced events", function( assert ) {
"custom.test2"
];
- function check(name, msg){
+ function check( name, msg ) {
assert.deepEqual( name, order.shift(), msg );
}
- jQuery("#firstp").on("custom.test",function() {
- check("custom.test", "Custom event triggered");
- });
+ jQuery( "#firstp" ).on( "custom.test", function() {
+ check( "custom.test", "Custom event triggered" );
+ } );
- jQuery("#firstp").on("custom.test2",function() {
- check("custom.test2", "Custom event triggered");
- });
+ jQuery( "#firstp" ).on( "custom.test2", function() {
+ check( "custom.test2", "Custom event triggered" );
+ } );
- jQuery("#firstp").on("click.test",function() {
- check("click.test", "Normal click triggered");
- });
+ jQuery( "#firstp" ).on( "click.test", function() {
+ check( "click.test", "Normal click triggered" );
+ } );
- jQuery("#firstp").on("click.test.abc",function() {
- check("click.test.abc", "Namespaced click triggered");
- });
+ jQuery( "#firstp" ).on( "click.test.abc", function() {
+ check( "click.test.abc", "Namespaced click triggered" );
+ } );
// Those would not trigger/off (#5303)
- jQuery("#firstp").trigger("click.a.test");
- jQuery("#firstp").off("click.a.test");
+ jQuery( "#firstp" ).trigger( "click.a.test" );
+ jQuery( "#firstp" ).off( "click.a.test" );
// Trigger both bound fn (1)
- jQuery("#firstp").trigger("click.test.abc");
+ jQuery( "#firstp" ).trigger( "click.test.abc" );
// Trigger one bound fn (1)
- jQuery("#firstp").trigger("click.abc");
+ jQuery( "#firstp" ).trigger( "click.abc" );
// Trigger two bound fn (2)
- jQuery("#firstp").trigger("click.test");
+ jQuery( "#firstp" ).trigger( "click.test" );
// Remove only the one fn
- jQuery("#firstp").off("click.abc");
+ jQuery( "#firstp" ).off( "click.abc" );
// Trigger the remaining fn (1)
- jQuery("#firstp").trigger("click");
+ jQuery( "#firstp" ).trigger( "click" );
// Remove the remaining fn
- jQuery("#firstp").off(".test");
+ jQuery( "#firstp" ).off( ".test" );
// Trigger the remaining fn (1)
- jQuery("#firstp").trigger("custom");
-});
+ jQuery( "#firstp" ).trigger( "custom" );
+} );
-QUnit.test("namespace-only event binding is a no-op", function( assert ){
- assert.expect(2);
+QUnit.test( "namespace-only event binding is a no-op", function( assert ) {
+ assert.expect( 2 );
- jQuery("#firstp")
+ jQuery( "#firstp" )
.on( ".whoops", function() {
assert.ok( false, "called a namespace-only event" );
- })
+ } )
.on( "whoops", function() {
assert.ok( true, "called whoops" );
- })
- .trigger("whoops") // 1
- .off(".whoops")
- .trigger("whoops") // 2
- .off("whoops");
-});
-
-QUnit.test("Empty namespace is ignored", function( assert ){
+ } )
+ .trigger( "whoops" ) // 1
+ .off( ".whoops" )
+ .trigger( "whoops" ) // 2
+ .off( "whoops" );
+} );
+
+QUnit.test( "Empty namespace is ignored", function( assert ) {
assert.expect( 1 );
- jQuery("#firstp")
+ jQuery( "#firstp" )
.on( "meow.", function( e ) {
assert.equal( e.namespace, "", "triggered a namespace-less meow event" );
- })
- .trigger("meow.")
- .off("meow.");
-});
+ } )
+ .trigger( "meow." )
+ .off( "meow." );
+} );
-QUnit.test("on(), with same function", function( assert ) {
- assert.expect(2);
+QUnit.test( "on(), with same function", function( assert ) {
+ assert.expect( 2 );
- var count = 0, func = function(){
+ var count = 0, func = function() {
count++;
};
- jQuery("#liveHandlerOrder").on("foo.bar", func).on("foo.zar", func);
- jQuery("#liveHandlerOrder").trigger("foo.bar");
+ jQuery( "#liveHandlerOrder" ).on( "foo.bar", func ).on( "foo.zar", func );
+ jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" );
- assert.equal(count, 1, "Verify binding function with multiple namespaces." );
+ assert.equal( count, 1, "Verify binding function with multiple namespaces." );
- jQuery("#liveHandlerOrder").off("foo.bar", func).off("foo.zar", func);
- jQuery("#liveHandlerOrder").trigger("foo.bar");
+ jQuery( "#liveHandlerOrder" ).off( "foo.bar", func ).off( "foo.zar", func );
+ jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" );
- assert.equal(count, 1, "Verify that removing events still work." );
-});
+ assert.equal( count, 1, "Verify that removing events still work." );
+} );
-QUnit.test("on(), make sure order is maintained", function( assert ) {
- assert.expect(1);
+QUnit.test( "on(), make sure order is maintained", function( assert ) {
+ assert.expect( 1 );
- var elem = jQuery("#firstp"), log = [], check = [];
+ var elem = jQuery( "#firstp" ), log = [], check = [];
- jQuery.each( new Array(100), function( i ) {
- elem.on( "click", function(){
+ jQuery.each( new Array( 100 ), function( i ) {
+ elem.on( "click", function() {
log.push( i );
- });
+ } );
check.push( i );
- });
+ } );
- elem.trigger("click");
+ elem.trigger( "click" );
- assert.equal( log.join(","), check.join(","), "Make sure order was maintained." );
+ assert.equal( log.join( "," ), check.join( "," ), "Make sure order was maintained." );
- elem.off("click");
-});
+ elem.off( "click" );
+} );
-QUnit.test("on(), with different this object", function( assert ) {
- assert.expect(4);
+QUnit.test( "on(), with different this object", function( assert ) {
+ assert.expect( 4 );
var thisObject = { myThis: true },
data = { myData: true },
handler1 = function() {
@@ -633,367 +637,369 @@ QUnit.test("on(), with different this object", function( assert ) {
assert.equal( event.data, data, "on() with different this object and data" );
};
- jQuery("#firstp")
- .on("click", jQuery.proxy(handler1, thisObject)).trigger("click").off("click", handler1)
- .on("click", data, jQuery.proxy(handler2, thisObject)).trigger("click").off("click", handler2);
+ jQuery( "#firstp" )
+ .on( "click", jQuery.proxy( handler1, thisObject ) ).trigger( "click" ).off( "click", handler1 )
+ .on( "click", data, jQuery.proxy( handler2, thisObject ) ).trigger( "click" ).off( "click", handler2 );
- assert.ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
-});
+ assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using different this object and data." );
+} );
-QUnit.test("on(name, false), off(name, false)", function( assert ) {
- assert.expect(3);
+QUnit.test( "on(name, false), off(name, false)", function( assert ) {
+ assert.expect( 3 );
var main = 0;
- jQuery("#qunit-fixture").on("click", function(){ main++; });
- jQuery("#ap").trigger("click");
+ jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
+ jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
- jQuery("#ap").on("click", false);
- jQuery("#ap").trigger("click");
+ jQuery( "#ap" ).on( "click", false );
+ jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 0, "Verify that no bubble happened." );
main = 0;
- jQuery("#ap").off("click", false);
- jQuery("#ap").trigger("click");
+ jQuery( "#ap" ).off( "click", false );
+ jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
// manually clean up events from elements outside the fixture
- jQuery("#qunit-fixture").off("click");
-});
+ jQuery( "#qunit-fixture" ).off( "click" );
+} );
-QUnit.test("on(name, selector, false), off(name, selector, false)", function( assert ) {
- assert.expect(3);
+QUnit.test( "on(name, selector, false), off(name, selector, false)", function( assert ) {
+ assert.expect( 3 );
var main = 0;
- jQuery("#qunit-fixture").on("click", "#ap", function(){ main++; });
- jQuery("#ap").trigger("click");
+ jQuery( "#qunit-fixture" ).on( "click", "#ap", function() { main++; } );
+ jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
- jQuery("#ap").on("click", "#groups", false);
- jQuery("#groups").trigger("click");
+ jQuery( "#ap" ).on( "click", "#groups", false );
+ jQuery( "#groups" ).trigger( "click" );
assert.equal( main, 0, "Verify that no bubble happened." );
main = 0;
- jQuery("#ap").off("click", "#groups", false);
- jQuery("#groups").trigger("click");
+ jQuery( "#ap" ).off( "click", "#groups", false );
+ jQuery( "#groups" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
- jQuery("#qunit-fixture").off("click", "#ap");
-});
+ jQuery( "#qunit-fixture" ).off( "click", "#ap" );
+} );
-QUnit.test("on()/trigger()/off() on plain object", function( assert ) {
+QUnit.test( "on()/trigger()/off() on plain object", function( assert ) {
assert.expect( 7 );
var events,
obj = {};
// Make sure it doesn't complain when no events are found
- jQuery(obj).trigger("test");
+ jQuery( obj ).trigger( "test" );
// Make sure it doesn't complain when no events are found
- jQuery(obj).off("test");
+ jQuery( obj ).off( "test" );
- jQuery(obj).on({
+ jQuery( obj ).on( {
"test": function() {
assert.ok( true, "Custom event run." );
},
"submit": function() {
assert.ok( true, "Custom submit event run." );
}
- });
+ } );
- events = jQuery._data(obj, "events");
+ events = jQuery._data( obj, "events" );
assert.ok( events, "Object has events bound." );
- assert.equal( obj["events"], undefined, "Events object on plain objects is not events" );
- assert.equal( obj["test"], undefined, "Make sure that test event is not on the plain object." );
- assert.equal( obj["handle"], undefined, "Make sure that the event handler is not on the plain object." );
+ assert.equal( obj[ "events" ], undefined, "Events object on plain objects is not events" );
+ assert.equal( obj[ "test" ], undefined, "Make sure that test event is not on the plain object." );
+ assert.equal( obj[ "handle" ], undefined, "Make sure that the event handler is not on the plain object." );
// Should trigger 1
- jQuery(obj).trigger("test");
- jQuery(obj).trigger("submit");
+ jQuery( obj ).trigger( "test" );
+ jQuery( obj ).trigger( "submit" );
- jQuery(obj).off("test");
- jQuery(obj).off("submit");
+ jQuery( obj ).off( "test" );
+ jQuery( obj ).off( "submit" );
// Should trigger 0
- jQuery(obj).trigger("test");
+ jQuery( obj ).trigger( "test" );
// Make sure it doesn't complain when no events are found
- jQuery(obj).off("test");
+ jQuery( obj ).off( "test" );
assert.equal( obj && obj[ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] &&
- obj[ jQuery.expando ][ jQuery.expando ]["events"], undefined, "Make sure events object is removed" );
-});
+ obj[ jQuery.expando ][ jQuery.expando ][ "events" ], undefined, "Make sure events object is removed" );
+} );
-QUnit.test("off(type)", function( assert ) {
+QUnit.test( "off(type)", function( assert ) {
assert.expect( 1 );
var message, func,
- $elem = jQuery("#firstp");
+ $elem = jQuery( "#firstp" );
- function error(){
+ function error() {
assert.ok( false, message );
}
message = "unbind passing function";
- $elem.on("error1", error).off("error1", error).triggerHandler("error1");
+ $elem.on( "error1", error ).off( "error1", error ).triggerHandler( "error1" );
message = "unbind all from event";
- $elem.on("error1", error).off("error1").triggerHandler("error1");
+ $elem.on( "error1", error ).off( "error1" ).triggerHandler( "error1" );
message = "unbind all";
- $elem.on("error1", error).off().triggerHandler("error1");
+ $elem.on( "error1", error ).off().triggerHandler( "error1" );
message = "unbind many with function";
- $elem.on("error1 error2",error)
- .off("error1 error2", error )
- .trigger("error1").triggerHandler("error2");
+ $elem.on( "error1 error2", error )
+ .off( "error1 error2", error )
+ .trigger( "error1" ).triggerHandler( "error2" );
message = "unbind many"; // #3538
- $elem.on("error1 error2", error)
- .off("error1 error2")
- .trigger("error1").triggerHandler("error2");
+ $elem.on( "error1 error2", error )
+ .off( "error1 error2" )
+ .trigger( "error1" ).triggerHandler( "error2" );
message = "unbind without a type or handler";
- $elem.on("error1 error2.test",error)
+ $elem.on( "error1 error2.test", error )
.off()
- .trigger("error1").triggerHandler("error2");
+ .trigger( "error1" ).triggerHandler( "error2" );
// Should only unbind the specified function
- jQuery( document ).on( "click", function(){
- assert.ok( true, "called handler after selective removal");
- });
+ jQuery( document ).on( "click", function() {
+ assert.ok( true, "called handler after selective removal" );
+ } );
func = function() {};
jQuery( document )
.on( "click", func )
.off( "click", func )
- .trigger("click")
+ .trigger( "click" )
.off( "click" );
-});
+} );
-QUnit.test("off(eventObject)", function( assert ) {
- assert.expect(4);
+QUnit.test( "off(eventObject)", function( assert ) {
+ assert.expect( 4 );
- var $elem = jQuery("#firstp"),
+ var $elem = jQuery( "#firstp" ),
num;
- function check( expected ){
+ function check( expected ) {
num = 0;
- $elem.trigger("foo").triggerHandler("bar");
+ $elem.trigger( "foo" ).triggerHandler( "bar" );
assert.equal( num, expected, "Check the right handlers are triggered" );
}
$elem
+
// This handler shouldn't be unbound
- .on("foo", function(){
+ .on( "foo", function() {
num += 1;
- })
- .on("foo", function(e){
+ } )
+ .on( "foo", function( e ) {
$elem.off( e );
num += 2;
- })
+ } )
+
// Neither this one
- .on("bar", function(){
+ .on( "bar", function() {
num += 4;
- });
+ } );
check( 7 );
check( 5 );
- $elem.off("bar");
+ $elem.off( "bar" );
check( 1 );
$elem.off();
check( 0 );
-});
+} );
if ( jQuery.fn.hover ) {
- QUnit.test("hover() mouseenter mouseleave", function( assert ) {
- assert.expect(1);
+ QUnit.test( "hover() mouseenter mouseleave", function( assert ) {
+ assert.expect( 1 );
var times = 0,
handler1 = function() { ++times; },
handler2 = function() { ++times; };
- jQuery("#firstp")
- .hover(handler1, handler2)
+ jQuery( "#firstp" )
+ .hover( handler1, handler2 )
.mouseenter().mouseleave()
- .off("mouseenter", handler1)
- .off("mouseleave", handler2)
- .hover(handler1)
+ .off( "mouseenter", handler1 )
+ .off( "mouseleave", handler2 )
+ .hover( handler1 )
.mouseenter().mouseleave()
- .off("mouseenter mouseleave", handler1)
+ .off( "mouseenter mouseleave", handler1 )
.mouseenter().mouseleave();
assert.equal( times, 4, "hover handlers fired" );
- });
+ } );
}
-QUnit.test("mouseover triggers mouseenter", function( assert ) {
- assert.expect(1);
+QUnit.test( "mouseover triggers mouseenter", function( assert ) {
+ assert.expect( 1 );
var count = 0,
- elem = jQuery("<a />");
- elem.on( "mouseenter", function () {
+ elem = jQuery( "<a />" );
+ elem.on( "mouseenter", function() {
count++;
- });
- elem.trigger("mouseover");
- assert.equal(count, 1, "make sure mouseover triggers a mouseenter" );
+ } );
+ elem.trigger( "mouseover" );
+ assert.equal( count, 1, "make sure mouseover triggers a mouseenter" );
elem.remove();
-});
+} );
-QUnit.test("pointerover triggers pointerenter", function( assert ) {
- assert.expect(1);
+QUnit.test( "pointerover triggers pointerenter", function( assert ) {
+ assert.expect( 1 );
var count = 0,
- elem = jQuery("<a />");
- elem.on( "pointerenter", function () {
+ elem = jQuery( "<a />" );
+ elem.on( "pointerenter", function() {
count++;
- });
- elem.trigger("pointerover");
- assert.equal(count, 1, "make sure pointerover triggers a pointerenter" );
+ } );
+ elem.trigger( "pointerover" );
+ assert.equal( count, 1, "make sure pointerover triggers a pointerenter" );
elem.remove();
-});
+} );
-QUnit.test("withinElement implemented with jQuery.contains()", function( assert ) {
+QUnit.test( "withinElement implemented with jQuery.contains()", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
- jQuery("#qunit-fixture").append("<div id='jc-outer'><div id='jc-inner'></div></div>");
+ jQuery( "#qunit-fixture" ).append( "<div id='jc-outer'><div id='jc-inner'></div></div>" );
- jQuery("#jc-outer").on("mouseenter mouseleave", function( event ) {
+ jQuery( "#jc-outer" ).on( "mouseenter mouseleave", function( event ) {
assert.equal( this.id, "jc-outer", this.id + " " + event.type );
- }).trigger("mouseenter");
+ } ).trigger( "mouseenter" );
- jQuery("#jc-inner").trigger("mousenter");
+ jQuery( "#jc-inner" ).trigger( "mousenter" );
- jQuery("#jc-outer").off("mouseenter mouseleave").remove();
- jQuery("#jc-inner").remove();
+ jQuery( "#jc-outer" ).off( "mouseenter mouseleave" ).remove();
+ jQuery( "#jc-inner" ).remove();
-});
+} );
-QUnit.test("mouseenter, mouseleave don't catch exceptions", function( assert ) {
- assert.expect(2);
+QUnit.test( "mouseenter, mouseleave don't catch exceptions", function( assert ) {
+ assert.expect( 2 );
- var elem = jQuery("#firstp").on( "mouseenter mouseleave", function() {
+ var elem = jQuery( "#firstp" ).on( "mouseenter mouseleave", function() {
throw "an Exception";
- });
+ } );
try {
- elem.trigger("mouseenter");
- } catch (e) {
+ elem.trigger( "mouseenter" );
+ } catch ( e ) {
assert.equal( e, "an Exception", "mouseenter doesn't catch exceptions" );
}
try {
- elem.trigger("mouseleave");
- } catch (e) {
+ elem.trigger( "mouseleave" );
+ } catch ( e ) {
assert.equal( e, "an Exception", "mouseleave doesn't catch exceptions" );
}
-});
+} );
if ( jQuery.fn.click ) {
- QUnit.test("trigger() shortcuts", function( assert ) {
- assert.expect(5);
+ QUnit.test( "trigger() shortcuts", function( assert ) {
+ assert.expect( 5 );
var counter, clickCounter,
- elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
- elem.find("a").on("click", function() {
- var close = jQuery("spanx", this); // same with jQuery(this).find("span");
+ elem = jQuery( "<li><a href='#'>Change location</a></li>" ).prependTo( "#firstUL" );
+ elem.find( "a" ).on( "click", function() {
+ var close = jQuery( "spanx", this ); // same with jQuery(this).find("span");
assert.equal( close.length, 0, "Context element does not exist, length must be zero" );
- assert.ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
+ assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" );
return false;
- }).click();
+ } ).click();
// manually clean up detached elements
elem.remove();
- jQuery("#check1").click(function() {
+ jQuery( "#check1" ).click( function() {
assert.ok( true, "click event handler for checkbox gets fired twice, see #815" );
- }).click();
+ } ).click();
counter = 0;
- jQuery("#firstp")[0].onclick = function() {
+ jQuery( "#firstp" )[ 0 ].onclick = function() {
counter++;
};
- jQuery("#firstp").click();
+ jQuery( "#firstp" ).click();
assert.equal( counter, 1, "Check that click, triggers onclick event handler also" );
clickCounter = 0;
- jQuery("#simon1")[0].onclick = function() {
+ jQuery( "#simon1" )[ 0 ].onclick = function() {
clickCounter++;
};
- jQuery("#simon1").click();
+ jQuery( "#simon1" ).click();
assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
// test that special handlers do not blow up with VML elements (#7071)
- jQuery("<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />").appendTo("head");
- jQuery("<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>").appendTo("#form");
- jQuery("#oval").click().keydown();
- });
+ jQuery( "<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />" ).appendTo( "head" );
+ jQuery( "<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>" ).appendTo( "#form" );
+ jQuery( "#oval" ).click().keydown();
+ } );
}
-QUnit.test("trigger() bubbling", function( assert ) {
- assert.expect(18);
+QUnit.test( "trigger() bubbling", function( assert ) {
+ assert.expect( 18 );
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
- jQuery(window).on("click", function(){ win++; });
- jQuery(document).on("click", function( e ){ if ( e.target !== document) { doc++; } });
- jQuery("html").on("click", function(){ html++; });
- jQuery("body").on("click", function(){ body++; });
- jQuery("#qunit-fixture").on("click", function(){ main++; });
- jQuery("#ap").on("click", function(){ ap++; return false; });
+ jQuery( window ).on( "click", function() { win++; } );
+ jQuery( document ).on( "click", function( e ) { if ( e.target !== document ) { doc++; } } );
+ jQuery( "html" ).on( "click", function() { html++; } );
+ jQuery( "body" ).on( "click", function() { body++; } );
+ jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
+ jQuery( "#ap" ).on( "click", function() { ap++; return false; } );
- jQuery("html").trigger("click");
+ jQuery( "html" ).trigger( "click" );
assert.equal( win, 1, "HTML bubble" );
assert.equal( doc, 1, "HTML bubble" );
assert.equal( html, 1, "HTML bubble" );
- jQuery("body").trigger("click");
+ jQuery( "body" ).trigger( "click" );
assert.equal( win, 2, "Body bubble" );
assert.equal( doc, 2, "Body bubble" );
assert.equal( html, 2, "Body bubble" );
assert.equal( body, 1, "Body bubble" );
- jQuery("#qunit-fixture").trigger("click");
+ jQuery( "#qunit-fixture" ).trigger( "click" );
assert.equal( win, 3, "Main bubble" );
assert.equal( doc, 3, "Main bubble" );
assert.equal( html, 3, "Main bubble" );
assert.equal( body, 2, "Main bubble" );
assert.equal( main, 1, "Main bubble" );
- jQuery("#ap").trigger("click");
+ jQuery( "#ap" ).trigger( "click" );
assert.equal( doc, 3, "ap bubble" );
assert.equal( html, 3, "ap bubble" );
assert.equal( body, 2, "ap bubble" );
assert.equal( main, 1, "ap bubble" );
assert.equal( ap, 1, "ap bubble" );
- jQuery( document ).trigger("click");
+ jQuery( document ).trigger( "click" );
assert.equal( win, 4, "doc bubble" );
// manually clean up events from elements outside the fixture
- jQuery(window).off("click");
- jQuery(document).off("click");
- jQuery("html, body, #qunit-fixture").off("click");
-});
+ jQuery( window ).off( "click" );
+ jQuery( document ).off( "click" );
+ jQuery( "html, body, #qunit-fixture" ).off( "click" );
+} );
-QUnit.test("trigger(type, [data], [fn])", function( assert ) {
- assert.expect(16);
+QUnit.test( "trigger(type, [data], [fn])", function( assert ) {
+ assert.expect( 16 );
var $elem, pass, form, elem2,
- handler = function(event, a, b, c) {
+ handler = function( event, a, b, c ) {
assert.equal( event.type, "click", "check passed data" );
assert.equal( a, 1, "check passed data" );
assert.equal( b, "2", "check passed data" );
@@ -1001,92 +1007,91 @@ QUnit.test("trigger(type, [data], [fn])", function( assert ) {
return "test";
};
- $elem = jQuery("#firstp");
+ $elem = jQuery( "#firstp" );
// Simulate a "native" click
- $elem[0].click = function(){
+ $elem[ 0 ].click = function() {
assert.ok( true, "Native call was triggered" );
};
-
- jQuery( document ).on("mouseenter", "#firstp", function(){
+ jQuery( document ).on( "mouseenter", "#firstp", function() {
assert.ok( true, "Trigger mouseenter bound by on" );
- });
+ } );
- jQuery( document ).on("mouseleave", "#firstp", function(){
+ jQuery( document ).on( "mouseleave", "#firstp", function() {
assert.ok( true, "Trigger mouseleave bound by on" );
- });
+ } );
- $elem.trigger("mouseenter");
+ $elem.trigger( "mouseenter" );
- $elem.trigger("mouseleave");
+ $elem.trigger( "mouseleave" );
- jQuery( document ).off( "mouseenter mouseleave", "#firstp");
+ jQuery( document ).off( "mouseenter mouseleave", "#firstp" );
// Triggers handlers and native
// Trigger 5
- $elem.on("click", handler).trigger("click", [1, "2", "abc"]);
+ $elem.on( "click", handler ).trigger( "click", [ 1, "2", "abc" ] );
// Simulate a "native" click
- $elem[0].click = function(){
+ $elem[ 0 ].click = function() {
assert.ok( false, "Native call was triggered" );
};
// Trigger only the handlers (no native)
// Triggers 5
- assert.equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
+ assert.equal( $elem.triggerHandler( "click", [ 1, "2", "abc" ] ), "test", "Verify handler response" );
pass = true;
try {
- elem2 = jQuery("#form input").eq(0);
- elem2.get(0).style.display = "none";
- elem2.trigger("focus");
- } catch( e ) {
+ elem2 = jQuery( "#form input" ).eq( 0 );
+ elem2.get( 0 ).style.display = "none";
+ elem2.trigger( "focus" );
+ } catch ( e ) {
pass = false;
}
assert.ok( pass, "Trigger focus on hidden element" );
pass = true;
try {
- jQuery("#qunit-fixture table").eq(0).on("test:test", function(){}).trigger("test:test");
+ jQuery( "#qunit-fixture table" ).eq( 0 ).on( "test:test", function() {} ).trigger( "test:test" );
} catch ( e ) {
pass = false;
}
assert.ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
- form = jQuery("<form action=''></form>").appendTo("body");
+ form = jQuery( "<form action=''></form>" ).appendTo( "body" );
// Make sure it can be prevented locally
- form.on( "submit", function(){
+ form.on( "submit", function() {
assert.ok( true, "Local `on` still works." );
return false;
- });
+ } );
// Trigger 1
- form.trigger("submit");
+ form.trigger( "submit" );
- form.off("submit");
+ form.off( "submit" );
- jQuery(document).on( "submit", function(){
+ jQuery( document ).on( "submit", function() {
assert.ok( true, "Make sure bubble works up to document." );
return false;
- });
+ } );
// Trigger 1
- form.trigger("submit");
+ form.trigger( "submit" );
- jQuery(document).off("submit");
+ jQuery( document ).off( "submit" );
form.remove();
-});
+} );
QUnit.test( "submit event bubbles on copied forms (#11649)", function( assert ) {
assert.expect( 3 );
var $formByClone, $formByHTML,
- $testForm = jQuery("#testForm"),
- $fixture = jQuery("#qunit-fixture"),
- $wrapperDiv = jQuery("<div/>").appendTo( $fixture );
+ $testForm = jQuery( "#testForm" ),
+ $fixture = jQuery( "#qunit-fixture" ),
+ $wrapperDiv = jQuery( "<div/>" ).appendTo( $fixture );
function noSubmit( e ) {
e.preventDefault();
@@ -1100,29 +1105,29 @@ QUnit.test( "submit event bubbles on copied forms (#11649)", function( assert )
$fixture.on( "submit", "form", delegatedSubmit );
// Trigger form submission to introduce the _submit_attached property
- $testForm.on( "submit", noSubmit ).find("input[name=sub1]").trigger("click");
+ $testForm.on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" );
// Copy the form via .clone() and .html()
- $formByClone = $testForm.clone( true, true ).removeAttr("id");
- $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#testForm").removeAttr("id");
+ $formByClone = $testForm.clone( true, true ).removeAttr( "id" );
+ $formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#testForm" ).removeAttr( "id" );
$wrapperDiv.append( $formByClone, $formByHTML );
// Check submit bubbling on the copied forms
- $wrapperDiv.find("form").on( "submit", noSubmit ).find("input[name=sub1]").trigger("click");
+ $wrapperDiv.find( "form" ).on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" );
// Clean up
$wrapperDiv.remove();
$fixture.off( "submit", "form", delegatedSubmit );
$testForm.off( "submit", noSubmit );
-});
+} );
-QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ){
+QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ) {
assert.expect( 3 );
var $formByClone, $formByHTML,
- $form = jQuery("#form"),
- $fixture = jQuery("#qunit-fixture"),
- $wrapperDiv = jQuery("<div/>").appendTo( $fixture );
+ $form = jQuery( "#form" ),
+ $fixture = jQuery( "#qunit-fixture" ),
+ $wrapperDiv = jQuery( "<div/>" ).appendTo( $fixture );
function delegatedChange() {
assert.ok( true, "Make sure change event bubbles up." );
@@ -1133,31 +1138,31 @@ QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ){
$fixture.on( "change", "form", delegatedChange );
// Trigger change event to introduce the _change_attached property
- $form.find("select[name=select1]").val("1").trigger("change");
+ $form.find( "select[name=select1]" ).val( "1" ).trigger( "change" );
// Copy the form via .clone() and .html()
- $formByClone = $form.clone( true, true ).removeAttr("id");
- $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#form").removeAttr("id");
+ $formByClone = $form.clone( true, true ).removeAttr( "id" );
+ $formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#form" ).removeAttr( "id" );
$wrapperDiv.append( $formByClone, $formByHTML );
// Check change bubbling on the copied forms
- $wrapperDiv.find("form select[name=select1]").val("2").trigger("change");
+ $wrapperDiv.find( "form select[name=select1]" ).val( "2" ).trigger( "change" );
// Clean up
$wrapperDiv.remove();
$fixture.off( "change", "form", delegatedChange );
-});
+} );
-QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) {
- assert.expect(28);
+QUnit.test( "trigger(eventObject, [data], [fn])", function( assert ) {
+ assert.expect( 28 );
var event,
- $parent = jQuery("<div id='par' />").appendTo("body"),
- $child = jQuery("<p id='child'>foo</p>").appendTo( $parent );
+ $parent = jQuery( "<div id='par' />" ).appendTo( "body" ),
+ $child = jQuery( "<p id='child'>foo</p>" ).appendTo( $parent );
$parent.get( 0 ).style.display = "none";
- event = jQuery.Event("noNew");
+ event = jQuery.Event( "noNew" );
assert.ok( event !== window, "Instantiate jQuery.Event without the 'new' keyword" );
assert.equal( event.type, "noNew", "Verify its type" );
@@ -1170,40 +1175,41 @@ QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) {
event.stopPropagation();
assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
- event.isPropagationStopped = function(){ return false; };
+ event.isPropagationStopped = function() { return false; };
event.stopImmediatePropagation();
assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
assert.equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
- $parent.on("foo",function( e ) {
+ $parent.on( "foo", function( e ) {
+
// Tries bubbling
assert.equal( e.type, "foo", "Verify event type when passed passing an event object" );
assert.equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
assert.equal( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" );
assert.equal( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" );
- });
+ } );
// test with an event object
- event = new jQuery.Event("foo");
+ event = new jQuery.Event( "foo" );
event.secret = "boo!";
- $child.trigger(event);
+ $child.trigger( event );
// test with a literal object
- $child.trigger({"type": "foo", "secret": "boo!"});
+ $child.trigger( { "type": "foo", "secret": "boo!" } );
$parent.off();
- function error(){
- assert.ok( false, "This assertion shouldn't be reached");
+ function error() {
+ assert.ok( false, "This assertion shouldn't be reached" );
}
- $parent.on("foo", error );
+ $parent.on( "foo", error );
- $child.on("foo",function(e, a, b, c ){
- assert.equal( arguments.length, 4, "Check arguments length");
- assert.equal( a, 1, "Check first custom argument");
- assert.equal( b, 2, "Check second custom argument");
- assert.equal( c, 3, "Check third custom argument");
+ $child.on( "foo", function( e, a, b, c ) {
+ assert.equal( arguments.length, 4, "Check arguments length" );
+ assert.equal( a, 1, "Check first custom argument" );
+ assert.equal( b, 2, "Check second custom argument" );
+ assert.equal( c, 3, "Check third custom argument" );
assert.equal( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
assert.equal( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
@@ -1213,18 +1219,18 @@ QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) {
e.stopImmediatePropagation();
return "result";
- });
+ } );
// We should add this back in when we want to test the order
// in which event handlers are iterated.
//$child.on("foo", error );
- event = new jQuery.Event("foo");
- $child.trigger( event, [1,2,3] ).off();
- assert.equal( event.result, "result", "Check event.result attribute");
+ event = new jQuery.Event( "foo" );
+ $child.trigger( event, [ 1,2,3 ] ).off();
+ assert.equal( event.result, "result", "Check event.result attribute" );
// Will error if it bubbles
- $child.triggerHandler("foo");
+ $child.triggerHandler( "foo" );
$child.off();
$parent.off().remove();
@@ -1235,53 +1241,53 @@ QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) {
assert.equal( event.type, "zowie", "Verify its type" );
assert.equal( event.isPropagationStopped(), false, "propagation not stopped" );
assert.equal( event.isDefaultPrevented(), false, "default not prevented" );
-});
+} );
-QUnit.test(".trigger() bubbling on disconnected elements (#10489)", function( assert ) {
- assert.expect(2);
+QUnit.test( ".trigger() bubbling on disconnected elements (#10489)", function( assert ) {
+ assert.expect( 2 );
- jQuery( window ).on( "click", function(){
+ jQuery( window ).on( "click", function() {
assert.ok( false, "click fired on window" );
- });
+ } );
jQuery( "<div><p>hi</p></div>" )
.on( "click", function() {
assert.ok( true, "click fired on div" );
- })
+ } )
.find( "p" )
.on( "click", function() {
assert.ok( true, "click fired on p" );
- })
- .trigger("click")
+ } )
+ .trigger( "click" )
.off( "click" )
.end()
.off( "click" )
.remove();
jQuery( window ).off( "click" );
-});
+} );
-QUnit.test(".trigger() doesn't bubble load event (#10717)", function( assert ) {
- assert.expect(1);
+QUnit.test( ".trigger() doesn't bubble load event (#10717)", function( assert ) {
+ assert.expect( 1 );
- jQuery( window ).on( "load", function(){
+ jQuery( window ).on( "load", function() {
assert.ok( false, "load fired on window" );
- });
+ } );
// It's not an image, but as long as it fires load...
- jQuery("<img src='index.html' />")
+ jQuery( "<img src='index.html' />" )
.appendTo( "body" )
.on( "load", function() {
assert.ok( true, "load fired on img" );
- })
+ } )
.trigger( "load" )
.remove();
jQuery( window ).off( "load" );
-});
+} );
-QUnit.test("Delegated events in SVG (#10791; #13180)", function( assert ) {
- assert.expect(2);
+QUnit.test( "Delegated events in SVG (#10791; #13180)", function( assert ) {
+ assert.expect( 2 );
var useElem, e,
svg = jQuery(
@@ -1293,32 +1299,32 @@ QUnit.test("Delegated events in SVG (#10791; #13180)", function( assert ) {
"</svg>"
);
- jQuery("#qunit-fixture")
+ jQuery( "#qunit-fixture" )
.append( svg )
.on( "click", "#svg-by-id", function() {
assert.ok( true, "delegated id selector" );
- })
+ } )
.on( "click", "[class~='svg-by-class']", function() {
assert.ok( true, "delegated class selector" );
- })
+ } )
.find( "#svg-by-id, [class~='svg-by-class']" )
- .trigger("click")
+ .trigger( "click" )
.end();
// Fire a native click on an SVGElementInstance (the instance tree of an SVG <use>)
// to confirm that it doesn't break our event delegation handling (#13180)
- useElem = svg.find("#use")[0];
+ useElem = svg.find( "#use" )[ 0 ];
if ( document.createEvent && useElem && useElem.instanceRoot ) {
- e = document.createEvent("MouseEvents");
+ e = document.createEvent( "MouseEvents" );
e.initEvent( "click", true, true );
useElem.instanceRoot.dispatchEvent( e );
}
- jQuery("#qunit-fixture").off("click");
-});
+ jQuery( "#qunit-fixture" ).off( "click" );
+} );
-QUnit.test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function( assert ) {
- assert.expect(5);
+QUnit.test( "Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function( assert ) {
+ assert.expect( 5 );
// Alias names like "id" cause havoc
var form = jQuery(
@@ -1328,36 +1334,36 @@ QUnit.test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)",
)
.on( "submit", function( event ) {
event.preventDefault();
- })
- .appendTo("body");
+ } )
+ .appendTo( "body" );
- jQuery("body")
+ jQuery( "body" )
.on( "submit", "#myform", function() {
assert.ok( true, "delegated id selector with aliased id" );
- })
- .find("#myform")
- .trigger("submit")
+ } )
+ .find( "#myform" )
+ .trigger( "submit" )
.end()
- .off("submit");
+ .off( "submit" );
- form.append("<input type='text' name='disabled' value='differently abled' />");
- jQuery("body")
+ form.append( "<input type='text' name='disabled' value='differently abled' />" );
+ jQuery( "body" )
.on( "submit", "#myform", function() {
assert.ok( true, "delegated id selector with aliased disabled" );
- })
- .find("#myform")
- .trigger("submit")
+ } )
+ .find( "#myform" )
+ .trigger( "submit" )
.end()
- .off("submit");
+ .off( "submit" );
form
.append( "<button id='nestyDisabledBtn'><span>Zing</span></button>" )
.on( "click", "#nestyDisabledBtn", function() {
assert.ok( true, "click on enabled/disabled button with nesty elements" );
- })
+ } )
.on( "mouseover", "#nestyDisabledBtn", function() {
assert.ok( true, "mouse on enabled/disabled button with nesty elements" );
- })
+ } )
.find( "span" )
.trigger( "click" ) // yep
.trigger( "mouseover" ) // yep
@@ -1370,10 +1376,10 @@ QUnit.test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)",
.off( "click" );
form.remove();
-});
+} );
-QUnit.test("Submit event can be stopped (#11049)", function( assert ) {
- assert.expect(1);
+QUnit.test( "Submit event can be stopped (#11049)", function( assert ) {
+ assert.expect( 1 );
// Since we manually bubble in IE, make sure inner handlers get a chance to cancel
var form = jQuery(
@@ -1382,33 +1388,33 @@ QUnit.test("Submit event can be stopped (#11049)", function( assert ) {
"<input type='submit' />" +
"</form>"
)
- .appendTo("body");
+ .appendTo( "body" );
jQuery( "body" )
.on( "submit", function() {
assert.ok( true, "submit bubbled on first handler" );
return false;
- })
+ } )
.find( "#myform input[type=submit]" )
- .each( function(){ this.click(); } )
+ .each( function() { this.click(); } )
.end()
.on( "submit", function() {
assert.ok( false, "submit bubbled on second handler" );
return false;
- })
+ } )
.find( "#myform input[type=submit]" )
- .each( function(){
+ .each( function() {
jQuery( this.form ).on( "submit", function( e ) {
e.preventDefault();
e.stopPropagation();
- });
+ } );
this.click();
- })
+ } )
.end()
.off( "submit" );
form.remove();
-});
+} );
// Test beforeunload event only if it supported.
// Support: iOS 7+, Android<4.0
@@ -1416,8 +1422,8 @@ QUnit.test("Submit event can be stopped (#11049)", function( assert ) {
// handler making it impossible to feature-detect the support.
if ( window.onbeforeunload === null &&
!/(ipad|iphone|ipod|android 2\.3)/i.test( navigator.userAgent ) ) {
- QUnit.test("on(beforeunload)", 1, function( assert ) {
- var iframe = jQuery(jQuery.parseHTML("<iframe src='data/event/onbeforeunload.html'><iframe>"));
+ QUnit.test( "on(beforeunload)", 1, function( assert ) {
+ var iframe = jQuery( jQuery.parseHTML( "<iframe src='data/event/onbeforeunload.html'><iframe>" ) );
var done = assert.async();
window.onmessage = function( event ) {
@@ -1430,15 +1436,15 @@ if ( window.onbeforeunload === null &&
done();
};
- iframe.appendTo("#qunit-fixture");
- });
+ iframe.appendTo( "#qunit-fixture" );
+ } );
}
-QUnit.test("jQuery.Event( type, props )", function( assert ) {
+QUnit.test( "jQuery.Event( type, props )", function( assert ) {
- assert.expect(6);
+ assert.expect( 6 );
- var event = jQuery.Event( "keydown", { keyCode: 64 }),
+ var event = jQuery.Event( "keydown", { keyCode: 64 } ),
handler = function( event ) {
assert.ok( "keyCode" in event, "Special property 'keyCode' exists" );
assert.equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
@@ -1448,24 +1454,24 @@ QUnit.test("jQuery.Event( type, props )", function( assert ) {
assert.equal( event.type, "keydown", "Verify type" );
// ensure "type" in props won't clobber the one set by constructor
- assert.equal( jQuery.inArray("type", jQuery.event.props), -1, "'type' property not in props (#10375)" );
+ assert.equal( jQuery.inArray( "type", jQuery.event.props ), -1, "'type' property not in props (#10375)" );
assert.ok( "keyCode" in event, "Special 'keyCode' property exists" );
assert.strictEqual( jQuery.isPlainObject( event ), false, "Instances of $.Event should not be identified as a plain object." );
- jQuery("body").on( "keydown", handler ).trigger( event );
+ jQuery( "body" ).on( "keydown", handler ).trigger( event );
- jQuery("body").off( "keydown" );
+ jQuery( "body" ).off( "keydown" );
-});
+} );
-QUnit.test("jQuery.Event properties", function( assert ){
- assert.expect(12);
+QUnit.test( "jQuery.Event properties", function( assert ) {
+ assert.expect( 12 );
var handler,
- $structure = jQuery("<div id='ancestor'><p id='delegate'><span id='target'>shiny</span></p></div>"),
- $target = $structure.find("#target");
+ $structure = jQuery( "<div id='ancestor'><p id='delegate'><span id='target'>shiny</span></p></div>" ),
+ $target = $structure.find( "#target" );
handler = function( e ) {
assert.strictEqual( e.currentTarget, this, "currentTarget at " + this.id );
@@ -1474,43 +1480,43 @@ QUnit.test("jQuery.Event properties", function( assert ){
$structure.one( "click", handler );
$structure.one( "click", "p", handler );
$target.one( "click", handler );
- $target[0].onclick = function( e ) {
+ $target[ 0 ].onclick = function( e ) {
assert.strictEqual( e.currentTarget, this, "currentTarget at target (native handler)" );
assert.equal( e.isTrigger, 3, "trigger at target (native handler)" );
};
- $target.trigger("click");
+ $target.trigger( "click" );
$target.one( "click", function( e ) {
assert.equal( e.isTrigger, 2, "triggerHandler at target" );
- });
- $target[0].onclick = function( e ) {
+ } );
+ $target[ 0 ].onclick = function( e ) {
assert.equal( e.isTrigger, 2, "triggerHandler at target (native handler)" );
};
- $target.triggerHandler("click");
+ $target.triggerHandler( "click" );
handler = function( e ) {
assert.strictEqual( e.isTrigger, undefined, "native event at " + this.id );
};
$target.one( "click", handler );
- $target[0].onclick = function( e ) {
+ $target[ 0 ].onclick = function( e ) {
assert.strictEqual( e.isTrigger, undefined, "native event at target (native handler)" );
};
- fireNative( $target[0], "click" );
-});
+ fireNative( $target[ 0 ], "click" );
+} );
-QUnit.test(".on()/.off()", function( assert ) {
- assert.expect(65);
+QUnit.test( ".on()/.off()", function( assert ) {
+ assert.expect( 65 );
var event, clicked, hash, called, livec, lived, livee,
submit = 0, div = 0, livea = 0, liveb = 0;
- jQuery("#body").on("submit", "#qunit-fixture div", function(){ submit++; return false; });
- jQuery("#body").on("click", "#qunit-fixture div", function(){ div++; });
- jQuery("#body").on("click", "div#nothiddendiv", function(){ livea++; });
- jQuery("#body").on("click", "div#nothiddendivchild", function(){ liveb++; });
+ jQuery( "#body" ).on( "submit", "#qunit-fixture div", function() { submit++; return false; } );
+ jQuery( "#body" ).on( "click", "#qunit-fixture div", function() { div++; } );
+ jQuery( "#body" ).on( "click", "div#nothiddendiv", function() { livea++; } );
+ jQuery( "#body" ).on( "click", "div#nothiddendivchild", function() { liveb++; } );
// Nothing should trigger on the body
- jQuery("body").trigger("click");
+ jQuery( "body" ).trigger( "click" );
assert.equal( submit, 0, "Click on body" );
assert.equal( div, 0, "Click on body" );
assert.equal( livea, 0, "Click on body" );
@@ -1518,7 +1524,7 @@ QUnit.test(".on()/.off()", function( assert ) {
// This should trigger two events
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("div#nothiddendiv").trigger("click");
+ jQuery( "div#nothiddendiv" ).trigger( "click" );
assert.equal( submit, 0, "Click on div" );
assert.equal( div, 1, "Click on div" );
assert.equal( livea, 1, "Click on div" );
@@ -1526,7 +1532,7 @@ QUnit.test(".on()/.off()", function( assert ) {
// This should trigger three events (w/ bubbling)
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("div#nothiddendivchild").trigger("click");
+ jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "Click on inner div" );
assert.equal( div, 2, "Click on inner div" );
assert.equal( livea, 1, "Click on inner div" );
@@ -1534,7 +1540,7 @@ QUnit.test(".on()/.off()", function( assert ) {
// This should trigger one submit
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("div#nothiddendivchild").trigger("submit");
+ jQuery( "div#nothiddendivchild" ).trigger( "submit" );
assert.equal( submit, 1, "Submit on div" );
assert.equal( div, 0, "Submit on div" );
assert.equal( livea, 0, "Submit on div" );
@@ -1542,7 +1548,7 @@ QUnit.test(".on()/.off()", function( assert ) {
// Make sure no other events were removed in the process
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("div#nothiddendivchild").trigger("click");
+ jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "off Click on inner div" );
assert.equal( div, 2, "off Click on inner div" );
assert.equal( livea, 1, "off Click on inner div" );
@@ -1550,8 +1556,8 @@ QUnit.test(".on()/.off()", function( assert ) {
// Now make sure that the removal works
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("#body").off("click", "div#nothiddendivchild");
- jQuery("div#nothiddendivchild").trigger("click");
+ jQuery( "#body" ).off( "click", "div#nothiddendivchild" );
+ jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "off Click on inner div" );
assert.equal( div, 2, "off Click on inner div" );
assert.equal( livea, 1, "off Click on inner div" );
@@ -1559,7 +1565,7 @@ QUnit.test(".on()/.off()", function( assert ) {
// Make sure that the click wasn't removed too early
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("div#nothiddendiv").trigger("click");
+ jQuery( "div#nothiddendiv" ).trigger( "click" );
assert.equal( submit, 0, "off Click on inner div" );
assert.equal( div, 1, "off Click on inner div" );
assert.equal( livea, 1, "off Click on inner div" );
@@ -1567,8 +1573,8 @@ QUnit.test(".on()/.off()", function( assert ) {
// Make sure that stopPropagation doesn't stop live events
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("#body").on("click", "div#nothiddendivchild", function( e ){ liveb++; e.stopPropagation(); });
- jQuery("div#nothiddendivchild").trigger("click");
+ jQuery( "#body" ).on( "click", "div#nothiddendivchild", function( e ) { liveb++; e.stopPropagation(); } );
+ jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "stopPropagation Click on inner div" );
assert.equal( div, 1, "stopPropagation Click on inner div" );
assert.equal( livea, 0, "stopPropagation Click on inner div" );
@@ -1576,126 +1582,126 @@ QUnit.test(".on()/.off()", function( assert ) {
// Make sure click events only fire with primary click
submit = 0; div = 0; livea = 0; liveb = 0;
- event = jQuery.Event("click");
+ event = jQuery.Event( "click" );
event.button = 1;
- jQuery("div#nothiddendiv").trigger(event);
+ jQuery( "div#nothiddendiv" ).trigger( event );
assert.equal( livea, 0, "on secondary click" );
- jQuery("#body").off("click", "div#nothiddendivchild");
- jQuery("#body").off("click", "div#nothiddendiv");
- jQuery("#body").off("click", "#qunit-fixture div");
- jQuery("#body").off("submit", "#qunit-fixture div");
+ jQuery( "#body" ).off( "click", "div#nothiddendivchild" );
+ jQuery( "#body" ).off( "click", "div#nothiddendiv" );
+ jQuery( "#body" ).off( "click", "#qunit-fixture div" );
+ jQuery( "#body" ).off( "submit", "#qunit-fixture div" );
// Test binding with a different context
clicked = 0;
- jQuery("#qunit-fixture").on("click", "#foo", function(){ clicked++; });
- jQuery("#qunit-fixture div").trigger("click");
- jQuery("#foo").trigger("click");
- jQuery("#qunit-fixture").trigger("click");
- jQuery("body").trigger("click");
+ jQuery( "#qunit-fixture" ).on( "click", "#foo", function() { clicked++; } );
+ jQuery( "#qunit-fixture div" ).trigger( "click" );
+ jQuery( "#foo" ).trigger( "click" );
+ jQuery( "#qunit-fixture" ).trigger( "click" );
+ jQuery( "body" ).trigger( "click" );
assert.equal( clicked, 2, "on with a context" );
// Test unbinding with a different context
- jQuery("#qunit-fixture").off("click", "#foo");
- jQuery("#foo").trigger("click");
- assert.equal( clicked, 2, "off with a context");
+ jQuery( "#qunit-fixture" ).off( "click", "#foo" );
+ jQuery( "#foo" ).trigger( "click" );
+ assert.equal( clicked, 2, "off with a context" );
// Test binding with event data
- jQuery("#body").on("click", "#foo", true, function( e ){ equal( e.data, true, "on with event data" ); });
- jQuery("#foo").trigger("click");
- jQuery("#body").off("click", "#foo");
+ jQuery( "#body" ).on( "click", "#foo", true, function( e ) { equal( e.data, true, "on with event data" ); } );
+ jQuery( "#foo" ).trigger( "click" );
+ jQuery( "#body" ).off( "click", "#foo" );
// Test binding with trigger data
- jQuery("#body").on("click", "#foo", function(e, data){ equal( data, true, "on with trigger data" ); });
- jQuery("#foo").trigger("click", true);
- jQuery("#body").off("click", "#foo");
+ jQuery( "#body" ).on( "click", "#foo", function( e, data ) { equal( data, true, "on with trigger data" ); } );
+ jQuery( "#foo" ).trigger( "click", true );
+ jQuery( "#body" ).off( "click", "#foo" );
// Test binding with different this object
- jQuery("#body").on("click", "#foo", jQuery.proxy(function(){ equal( this["foo"], "bar", "on with event scope" ); }, { "foo": "bar" }));
- jQuery("#foo").trigger("click");
- jQuery("#body").off("click", "#foo");
+ jQuery( "#body" ).on( "click", "#foo", jQuery.proxy( function() { equal( this[ "foo" ], "bar", "on with event scope" ); }, { "foo": "bar" } ) );
+ jQuery( "#foo" ).trigger( "click" );
+ jQuery( "#body" ).off( "click", "#foo" );
// Test binding with different this object, event data, and trigger data
- jQuery("#body").on("click", "#foo", true, jQuery.proxy(function(e, data){
+ jQuery( "#body" ).on( "click", "#foo", true, jQuery.proxy( function( e, data ) {
assert.equal( e.data, true, "on with with different this object, event data, and trigger data" );
assert.equal( this.foo, "bar", "on with with different this object, event data, and trigger data" );
- assert.equal( data, true, "on with with different this object, event data, and trigger data");
- }, { "foo": "bar" }));
- jQuery("#foo").trigger("click", true);
- jQuery("#body").off("click", "#foo");
+ assert.equal( data, true, "on with with different this object, event data, and trigger data" );
+ }, { "foo": "bar" } ) );
+ jQuery( "#foo" ).trigger( "click", true );
+ jQuery( "#body" ).off( "click", "#foo" );
// Verify that return false prevents default action
- jQuery("#body").on("click", "#anchor2", function(){ return false; });
+ jQuery( "#body" ).on( "click", "#anchor2", function() { return false; } );
hash = window.location.hash;
- jQuery("#anchor2").trigger("click");
+ jQuery( "#anchor2" ).trigger( "click" );
assert.equal( window.location.hash, hash, "return false worked" );
- jQuery("#body").off("click", "#anchor2");
+ jQuery( "#body" ).off( "click", "#anchor2" );
// Verify that .preventDefault() prevents default action
- jQuery("#body").on("click", "#anchor2", function(e){ e.preventDefault(); });
+ jQuery( "#body" ).on( "click", "#anchor2", function( e ) { e.preventDefault(); } );
hash = window.location.hash;
- jQuery("#anchor2").trigger("click");
+ jQuery( "#anchor2" ).trigger( "click" );
assert.equal( window.location.hash, hash, "e.preventDefault() worked" );
- jQuery("#body").off("click", "#anchor2");
+ jQuery( "#body" ).off( "click", "#anchor2" );
// Test binding the same handler to multiple points
called = 0;
- function callback(){ called++; return false; }
+ function callback() { called++; return false; }
- jQuery("#body").on("click", "#nothiddendiv", callback);
- jQuery("#body").on("click", "#anchor2", callback);
+ jQuery( "#body" ).on( "click", "#nothiddendiv", callback );
+ jQuery( "#body" ).on( "click", "#anchor2", callback );
- jQuery("#nothiddendiv").trigger("click");
+ jQuery( "#nothiddendiv" ).trigger( "click" );
assert.equal( called, 1, "Verify that only one click occurred." );
called = 0;
- jQuery("#anchor2").trigger("click");
+ jQuery( "#anchor2" ).trigger( "click" );
assert.equal( called, 1, "Verify that only one click occurred." );
// Make sure that only one callback is removed
- jQuery("#body").off("click", "#anchor2", callback);
+ jQuery( "#body" ).off( "click", "#anchor2", callback );
called = 0;
- jQuery("#nothiddendiv").trigger("click");
+ jQuery( "#nothiddendiv" ).trigger( "click" );
assert.equal( called, 1, "Verify that only one click occurred." );
called = 0;
- jQuery("#anchor2").trigger("click");
+ jQuery( "#anchor2" ).trigger( "click" );
assert.equal( called, 0, "Verify that no click occurred." );
// Make sure that it still works if the selector is the same,
// but the event type is different
- jQuery("#body").on("foo", "#nothiddendiv", callback);
+ jQuery( "#body" ).on( "foo", "#nothiddendiv", callback );
// Cleanup
- jQuery("#body").off("click", "#nothiddendiv", callback);
+ jQuery( "#body" ).off( "click", "#nothiddendiv", callback );
called = 0;
- jQuery("#nothiddendiv").trigger("click");
+ jQuery( "#nothiddendiv" ).trigger( "click" );
assert.equal( called, 0, "Verify that no click occurred." );
called = 0;
- jQuery("#nothiddendiv").trigger("foo");
+ jQuery( "#nothiddendiv" ).trigger( "foo" );
assert.equal( called, 1, "Verify that one foo occurred." );
// Cleanup
- jQuery("#body").off("foo", "#nothiddendiv", callback);
+ jQuery( "#body" ).off( "foo", "#nothiddendiv", callback );
// Make sure we don't loose the target by DOM modifications
// after the bubble already reached the liveHandler
livec = 0;
- jQuery("#nothiddendivchild").html("<span></span>");
+ jQuery( "#nothiddendivchild" ).html( "<span></span>" );
- jQuery("#body").on("click", "#nothiddendivchild", function(){ jQuery("#nothiddendivchild").html(""); });
- jQuery("#body").on("click", "#nothiddendivchild", function(e){ if(e.target) {livec++;} });
+ jQuery( "#body" ).on( "click", "#nothiddendivchild", function() { jQuery( "#nothiddendivchild" ).html( "" ); } );
+ jQuery( "#body" ).on( "click", "#nothiddendivchild", function( e ) { if ( e.target ) {livec++;} } );
- jQuery("#nothiddendiv span").trigger("click");
- assert.equal( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
+ jQuery( "#nothiddendiv span" ).trigger( "click" );
+ assert.equal( jQuery( "#nothiddendiv span" ).length, 0, "Verify that first handler occurred and modified the DOM." );
assert.equal( livec, 1, "Verify that second handler occurred even with nuked target." );
// Cleanup
- jQuery("#body").off("click", "#nothiddendivchild");
+ jQuery( "#body" ).off( "click", "#nothiddendivchild" );
// Verify that .live() occurs and cancel bubble in the same order as
// we would expect .on() and .click() without delegation
@@ -1703,204 +1709,204 @@ QUnit.test(".on()/.off()", function( assert ) {
livee = 0;
// bind one pair in one order
- jQuery("#body").on("click", "span#liveSpan1 a", function(){ lived++; return false; });
- jQuery("#body").on("click", "span#liveSpan1", function(){ livee++; });
+ jQuery( "#body" ).on( "click", "span#liveSpan1 a", function() { lived++; return false; } );
+ jQuery( "#body" ).on( "click", "span#liveSpan1", function() { livee++; } );
- jQuery("span#liveSpan1 a").trigger("click");
+ jQuery( "span#liveSpan1 a" ).trigger( "click" );
assert.equal( lived, 1, "Verify that only one first handler occurred." );
assert.equal( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse
- jQuery("#body").on("click", "span#liveSpan2", function(){ livee++; });
- jQuery("#body").on("click", "span#liveSpan2 a", function(){ lived++; return false; });
+ jQuery( "#body" ).on( "click", "span#liveSpan2", function() { livee++; } );
+ jQuery( "#body" ).on( "click", "span#liveSpan2 a", function() { lived++; return false; } );
lived = 0;
livee = 0;
- jQuery("span#liveSpan2 a").trigger("click");
+ jQuery( "span#liveSpan2 a" ).trigger( "click" );
assert.equal( lived, 1, "Verify that only one first handler occurred." );
assert.equal( livee, 0, "Verify that second handler doesn't." );
// Cleanup
- jQuery("#body").off("click", "**");
+ jQuery( "#body" ).off( "click", "**" );
// Test this, target and currentTarget are correct
- jQuery("#body").on("click", "span#liveSpan1", function( e ) {
+ jQuery( "#body" ).on( "click", "span#liveSpan1", function( e ) {
assert.equal( this.id, "liveSpan1", "Check the this within a on handler" );
assert.equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a on handler" );
assert.equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a on handler" );
assert.equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a on handler" );
- });
+ } );
- jQuery("span#liveSpan1 a").trigger("click");
+ jQuery( "span#liveSpan1 a" ).trigger( "click" );
- jQuery("#body").off("click", "span#liveSpan1");
+ jQuery( "#body" ).off( "click", "span#liveSpan1" );
// Work with deep selectors
livee = 0;
function clickB() { livee++; }
- jQuery("#body").on("click", "#nothiddendiv div", function(){ livee++; });
- jQuery("#body").on("click", "#nothiddendiv div", clickB);
- jQuery("#body").on("mouseover", "#nothiddendiv div", function(){ livee++; });
+ jQuery( "#body" ).on( "click", "#nothiddendiv div", function() { livee++; } );
+ jQuery( "#body" ).on( "click", "#nothiddendiv div", clickB );
+ jQuery( "#body" ).on( "mouseover", "#nothiddendiv div", function() { livee++; } );
assert.equal( livee, 0, "No clicks, deep selector." );
livee = 0;
- jQuery("#nothiddendivchild").trigger("click");
+ jQuery( "#nothiddendivchild" ).trigger( "click" );
assert.equal( livee, 2, "Click, deep selector." );
livee = 0;
- jQuery("#nothiddendivchild").trigger("mouseover");
+ jQuery( "#nothiddendivchild" ).trigger( "mouseover" );
assert.equal( livee, 1, "Mouseover, deep selector." );
- jQuery("#body").off("mouseover", "#nothiddendiv div");
+ jQuery( "#body" ).off( "mouseover", "#nothiddendiv div" );
livee = 0;
- jQuery("#nothiddendivchild").trigger("click");
+ jQuery( "#nothiddendivchild" ).trigger( "click" );
assert.equal( livee, 2, "Click, deep selector." );
livee = 0;
- jQuery("#nothiddendivchild").trigger("mouseover");
+ jQuery( "#nothiddendivchild" ).trigger( "mouseover" );
assert.equal( livee, 0, "Mouseover, deep selector." );
- jQuery("#body").off("click", "#nothiddendiv div", clickB);
+ jQuery( "#body" ).off( "click", "#nothiddendiv div", clickB );
livee = 0;
- jQuery("#nothiddendivchild").trigger("click");
+ jQuery( "#nothiddendivchild" ).trigger( "click" );
assert.equal( livee, 1, "Click, deep selector." );
- jQuery("#body").off("click", "#nothiddendiv div");
-});
+ jQuery( "#body" ).off( "click", "#nothiddendiv div" );
+} );
-QUnit.test("jQuery.off using dispatched jQuery.Event", function( assert ) {
- assert.expect(1);
+QUnit.test( "jQuery.off using dispatched jQuery.Event", function( assert ) {
+ assert.expect( 1 );
- var markup = jQuery("<p><a href='#'>target</a></p>"),
+ var markup = jQuery( "<p><a href='#'>target</a></p>" ),
count = 0;
markup
.on( "click.name", "a", function( event ) {
assert.equal( ++count, 1, "event called once before removal" );
jQuery().off( event );
- })
- .find("a").trigger("click").trigger("click").end()
+ } )
+ .find( "a" ).trigger( "click" ).trigger( "click" ).end()
.remove();
-});
+} );
QUnit.test( "delegated event with delegateTarget-relative selector", function( assert ) {
- assert.expect(3);
- var markup = jQuery("<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>").appendTo("#qunit-fixture");
+ assert.expect( 3 );
+ var markup = jQuery( "<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>" ).appendTo( "#qunit-fixture" );
// Non-positional selector (#12383)
- markup.find("#ul0")
+ markup.find( "#ul0" )
.on( "click", "div li a", function() {
assert.ok( false, "div is ABOVE the delegation point!" );
- })
+ } )
.on( "click", "ul a", function() {
assert.ok( false, "ul IS the delegation point!" );
- })
+ } )
.on( "click", "li.test a", function() {
assert.ok( true, "li.test is below the delegation point." );
- })
- .find("#a0_0").trigger("click").end()
- .off("click");
+ } )
+ .find( "#a0_0" ).trigger( "click" ).end()
+ .off( "click" );
// Positional selector (#11315)
- markup.find("ul").eq(0)
+ markup.find( "ul" ).eq( 0 )
.on( "click", ">li>a", function() {
assert.ok( this.id === "a0", "child li was clicked" );
- })
- .find("#ul0")
+ } )
+ .find( "#ul0" )
.on( "click", "li:first>a", function() {
- assert.ok( this.id === "a0_0" , "first li under #u10 was clicked" );
- })
+ assert.ok( this.id === "a0_0", "first li under #u10 was clicked" );
+ } )
.end()
- .find("a").trigger("click").end()
- .find("#ul0").off();
+ .find( "a" ).trigger( "click" ).end()
+ .find( "#ul0" ).off();
markup.remove();
-});
+} );
QUnit.test( "delegated event with selector matching Object.prototype property (#13203)", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var matched = 0;
- jQuery("#foo").on( "click", "toString", function() {
+ jQuery( "#foo" ).on( "click", "toString", function() {
matched++;
- });
+ } );
- jQuery("#anchor2").trigger("click");
+ jQuery( "#anchor2" ).trigger( "click" );
assert.equal( matched, 0, "Nothing matched 'toString'" );
-});
+} );
QUnit.test( "delegated event with intermediate DOM manipulation (#13208)", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
- jQuery("#foo").on( "click", "[id=sap]", function() {});
- jQuery("#sap").on( "click", "[id=anchor2]", function() {
+ jQuery( "#foo" ).on( "click", "[id=sap]", function() {} );
+ jQuery( "#sap" ).on( "click", "[id=anchor2]", function() {
document.createDocumentFragment().appendChild( this.parentNode );
assert.ok( true, "Element removed" );
- });
- jQuery("#anchor2").trigger("click");
-});
+ } );
+ jQuery( "#anchor2" ).trigger( "click" );
+} );
-QUnit.test("stopPropagation() stops directly-bound events on delegated target", function( assert ) {
- assert.expect(1);
+QUnit.test( "stopPropagation() stops directly-bound events on delegated target", function( assert ) {
+ assert.expect( 1 );
- var markup = jQuery("<div><p><a href=\"#\">target</a></p></div>");
+ var markup = jQuery( "<div><p><a href=\"#\">target</a></p></div>" );
markup
.on( "click", function() {
assert.ok( false, "directly-bound event on delegate target was called" );
- })
+ } )
.on( "click", "a", function( e ) {
e.stopPropagation();
assert.ok( true, "delegated handler was called" );
- })
- .find("a").trigger("click").end()
+ } )
+ .find( "a" ).trigger( "click" ).end()
.remove();
-});
+} );
-QUnit.test("off all bound delegated events", function( assert ){
- assert.expect(2);
+QUnit.test( "off all bound delegated events", function( assert ) {
+ assert.expect( 2 );
var count = 0,
clicks = 0,
- div = jQuery("#body");
+ div = jQuery( "#body" );
- div.on( "click submit", "div#nothiddendivchild", function(){ count++; } );
- div.on( "click", function(){ clicks++; } );
+ div.on( "click submit", "div#nothiddendivchild", function() { count++; } );
+ div.on( "click", function() { clicks++; } );
div.off( undefined, "**" );
- jQuery("div#nothiddendivchild").trigger("click");
- jQuery("div#nothiddendivchild").trigger("submit");
+ jQuery( "div#nothiddendivchild" ).trigger( "click" );
+ jQuery( "div#nothiddendivchild" ).trigger( "submit" );
assert.equal( count, 0, "Make sure no events were triggered." );
- div.trigger("click");
+ div.trigger( "click" );
assert.equal( clicks, 2, "Make sure delegated and directly bound event occurred." );
- div.off("click");
-});
+ div.off( "click" );
+} );
-QUnit.test("on with multiple delegated events", function( assert ){
- assert.expect(1);
+QUnit.test( "on with multiple delegated events", function( assert ) {
+ assert.expect( 1 );
var count = 0,
- div = jQuery("#body");
+ div = jQuery( "#body" );
- div.on("click submit", "div#nothiddendivchild", function(){ count++; });
+ div.on( "click submit", "div#nothiddendivchild", function() { count++; } );
- jQuery("div#nothiddendivchild").trigger("click");
- jQuery("div#nothiddendivchild").trigger("submit");
+ jQuery( "div#nothiddendivchild" ).trigger( "click" );
+ jQuery( "div#nothiddendivchild" ).trigger( "submit" );
assert.equal( count, 2, "Make sure both the click and submit were triggered." );
- jQuery("#body").off( undefined, "**" );
-});
+ jQuery( "#body" ).off( undefined, "**" );
+} );
-QUnit.test("delegated on with change", function( assert ){
- assert.expect(8);
+QUnit.test( "delegated on with change", function( assert ) {
+ assert.expect( 8 );
var select, checkbox, checkboxFunction,
text, textChange, oldTextVal,
@@ -1908,182 +1914,182 @@ QUnit.test("delegated on with change", function( assert ){
selectChange = 0,
checkboxChange = 0;
- select = jQuery("select[name='S1']");
- jQuery("#body").on("change", "select[name='S1']", function() {
+ select = jQuery( "select[name='S1']" );
+ jQuery( "#body" ).on( "change", "select[name='S1']", function() {
selectChange++;
- });
+ } );
- checkbox = jQuery("#check2");
- checkboxFunction = function(){
+ checkbox = jQuery( "#check2" );
+ checkboxFunction = function() {
checkboxChange++;
};
- jQuery("#body").on("change", "#check2", checkboxFunction);
+ jQuery( "#body" ).on( "change", "#check2", checkboxFunction );
// test click on select
// second click that changed it
selectChange = 0;
- select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
- select.trigger("change");
+ select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
+ select.trigger( "change" );
assert.equal( selectChange, 1, "Change on click." );
// test keys on select
selectChange = 0;
- select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
- select.trigger("change");
+ select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
+ select.trigger( "change" );
assert.equal( selectChange, 1, "Change on keyup." );
// test click on checkbox
- checkbox.trigger("change");
+ checkbox.trigger( "change" );
assert.equal( checkboxChange, 1, "Change on checkbox." );
// test blur/focus on text
- text = jQuery("#name");
+ text = jQuery( "#name" );
textChange = 0;
oldTextVal = text.val();
- jQuery("#body").on("change", "#name", function() {
+ jQuery( "#body" ).on( "change", "#name", function() {
textChange++;
- });
+ } );
- text.val(oldTextVal+"foo");
- text.trigger("change");
+ text.val( oldTextVal + "foo" );
+ text.trigger( "change" );
assert.equal( textChange, 1, "Change on text input." );
- text.val(oldTextVal);
- jQuery("#body").off("change", "#name");
+ text.val( oldTextVal );
+ jQuery( "#body" ).off( "change", "#name" );
// test blur/focus on password
- password = jQuery("#name");
+ password = jQuery( "#name" );
passwordChange = 0;
oldPasswordVal = password.val();
- jQuery("#body").on("change", "#name", function() {
+ jQuery( "#body" ).on( "change", "#name", function() {
passwordChange++;
- });
+ } );
- password.val(oldPasswordVal + "foo");
- password.trigger("change");
+ password.val( oldPasswordVal + "foo" );
+ password.trigger( "change" );
assert.equal( passwordChange, 1, "Change on password input." );
- password.val(oldPasswordVal);
- jQuery("#body").off("change", "#name");
+ password.val( oldPasswordVal );
+ jQuery( "#body" ).off( "change", "#name" );
// make sure die works
// die all changes
selectChange = 0;
- jQuery("#body").off("change", "select[name='S1']");
- select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
- select.trigger("change");
+ jQuery( "#body" ).off( "change", "select[name='S1']" );
+ select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
+ select.trigger( "change" );
assert.equal( selectChange, 0, "Die on click works." );
selectChange = 0;
- select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
- select.trigger("change");
+ select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
+ select.trigger( "change" );
assert.equal( selectChange, 0, "Die on keyup works." );
// die specific checkbox
- jQuery("#body").off("change", "#check2", checkboxFunction);
- checkbox.trigger("change");
+ jQuery( "#body" ).off( "change", "#check2", checkboxFunction );
+ checkbox.trigger( "change" );
assert.equal( checkboxChange, 1, "Die on checkbox." );
-});
+} );
-QUnit.test("delegated on with submit", function( assert ) {
+QUnit.test( "delegated on with submit", function( assert ) {
assert.expect( 2 );
var count1 = 0, count2 = 0;
- jQuery("#body").on("submit", "#testForm", function(ev) {
+ jQuery( "#body" ).on( "submit", "#testForm", function( ev ) {
count1++;
ev.preventDefault();
- });
+ } );
- jQuery(document).on("submit", "body", function(ev) {
+ jQuery( document ).on( "submit", "body", function( ev ) {
count2++;
ev.preventDefault();
- });
+ } );
- jQuery("#testForm input[name=sub1]").trigger("submit");
+ jQuery( "#testForm input[name=sub1]" ).trigger( "submit" );
assert.equal( count1, 1, "Verify form submit." );
assert.equal( count2, 1, "Verify body submit." );
- jQuery("#body").off( undefined, "**" );
- jQuery(document).off( undefined, "**" );
-});
+ jQuery( "#body" ).off( undefined, "**" );
+ jQuery( document ).off( undefined, "**" );
+} );
-QUnit.test("delegated off() with only namespaces", function( assert ) {
- assert.expect(2);
+QUnit.test( "delegated off() with only namespaces", function( assert ) {
+ assert.expect( 2 );
- var $delegate = jQuery("#liveHandlerOrder"),
+ var $delegate = jQuery( "#liveHandlerOrder" ),
count = 0;
- $delegate.on("click.ns", "a", function() {
+ $delegate.on( "click.ns", "a", function() {
count++;
- });
+ } );
- jQuery("a", $delegate).eq(0).trigger("click.ns");
+ jQuery( "a", $delegate ).eq( 0 ).trigger( "click.ns" );
- assert.equal( count, 1, "delegated click.ns");
+ assert.equal( count, 1, "delegated click.ns" );
$delegate.off( ".ns", "**" );
- jQuery("a", $delegate).eq(1).trigger("click.ns");
+ jQuery( "a", $delegate ).eq( 1 ).trigger( "click.ns" );
- assert.equal( count, 1, "no more .ns after off");
-});
+ assert.equal( count, 1, "no more .ns after off" );
+} );
-QUnit.test("Non DOM element events", function( assert ) {
- assert.expect(1);
+QUnit.test( "Non DOM element events", function( assert ) {
+ assert.expect( 1 );
var o = {};
- jQuery(o).on("nonelementobj", function() {
+ jQuery( o ).on( "nonelementobj", function() {
assert.ok( true, "Event on non-DOM object triggered" );
- });
+ } );
- jQuery(o).trigger("nonelementobj").off("nonelementobj");
-});
+ jQuery( o ).trigger( "nonelementobj" ).off( "nonelementobj" );
+} );
-QUnit.test("inline handler returning false stops default", function( assert ) {
- assert.expect(1);
+QUnit.test( "inline handler returning false stops default", function( assert ) {
+ assert.expect( 1 );
- var markup = jQuery("<div><a href=\"#\" onclick=\"return false\">x</a></div>");
- markup.on( "click", function(e) {
- assert.ok( e.isDefaultPrevented(), "inline handler prevented default");
+ var markup = jQuery( "<div><a href=\"#\" onclick=\"return false\">x</a></div>" );
+ markup.on( "click", function( e ) {
+ assert.ok( e.isDefaultPrevented(), "inline handler prevented default" );
return false;
- });
- markup.find("a").trigger("click");
- markup.off("click");
-});
+ } );
+ markup.find( "a" ).trigger( "click" );
+ markup.off( "click" );
+} );
-QUnit.test("window resize", function( assert ) {
- assert.expect(2);
+QUnit.test( "window resize", function( assert ) {
+ assert.expect( 2 );
- jQuery(window).off();
+ jQuery( window ).off();
- jQuery(window).on( "resize", function(){
+ jQuery( window ).on( "resize", function() {
assert.ok( true, "Resize event fired." );
- }).trigger("resize").off("resize");
+ } ).trigger( "resize" ).off( "resize" );
- assert.ok( !jQuery._data(window, "events"), "Make sure all the events are gone." );
-});
+ assert.ok( !jQuery._data( window, "events" ), "Make sure all the events are gone." );
+} );
-QUnit.test("focusin bubbles", function( assert ) {
- assert.expect(2);
+QUnit.test( "focusin bubbles", function( assert ) {
+ assert.expect( 2 );
var input = jQuery( "<input type='text' />" ).prependTo( "body" ),
order = 0;
// focus the element so DOM focus won't fire
- input[0].focus();
+ input[ 0 ].focus();
- jQuery( "body" ).on( "focusin.focusinBubblesTest", function(){
+ jQuery( "body" ).on( "focusin.focusinBubblesTest", function() {
assert.equal( 1, order++, "focusin on the body second" );
- });
+ } );
- input.on( "focusin.focusinBubblesTest", function(){
+ input.on( "focusin.focusinBubblesTest", function() {
assert.equal( 0, order++, "focusin on the element first" );
- });
+ } );
// Removed since DOM focus is unreliable on test swarm
// DOM focus method
@@ -2100,32 +2106,32 @@ QUnit.test("focusin bubbles", function( assert ) {
input.remove();
jQuery( "body" ).off( "focusin.focusinBubblesTest" );
-});
+} );
-QUnit.test("custom events with colons (#3533, #8272)", function( assert ) {
- assert.expect(1);
+QUnit.test( "custom events with colons (#3533, #8272)", function( assert ) {
+ assert.expect( 1 );
- var tab = jQuery("<table><tr><td>trigger</td></tr></table>").appendTo("body");
+ var tab = jQuery( "<table><tr><td>trigger</td></tr></table>" ).appendTo( "body" );
try {
- tab.trigger("back:forth");
+ tab.trigger( "back:forth" );
assert.ok( true, "colon events don't throw" );
} catch ( e ) {
assert.ok( false, "colon events die" );
}
tab.remove();
-});
+} );
-QUnit.test(".on and .off", function( assert ) {
- assert.expect(9);
+QUnit.test( ".on and .off", function( assert ) {
+ assert.expect( 9 );
var counter, mixfn, data,
- $onandoff = jQuery("<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>").appendTo("body");
+ $onandoff = jQuery( "<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>" ).appendTo( "body" );
// Simple case
jQuery( "#onandoff" )
.on( "whip", function() {
assert.ok( true, "whipped it good" );
- })
+ } )
.trigger( "whip" )
.off();
@@ -2133,12 +2139,12 @@ QUnit.test(".on and .off", function( assert ) {
counter = 0;
jQuery( "#onandoff b" )
.on( "click", 5, function( e, trig ) {
- counter += e.data + (trig || 9); // twice, 5+9+5+17=36
- })
+ counter += e.data + ( trig || 9 ); // twice, 5+9+5+17=36
+ } )
.one( "click", 7, function( e, trig ) {
- counter += e.data + (trig || 11); // once, 7+11=18
- })
- .trigger("click")
+ counter += e.data + ( trig || 11 ); // once, 7+11=18
+ } )
+ .trigger( "click" )
.trigger( "click", 17 )
.off( "click" );
assert.equal( counter, 54, "direct event bindings with data" );
@@ -2147,23 +2153,22 @@ QUnit.test(".on and .off", function( assert ) {
counter = 0;
jQuery( "#onandoff" )
.on( "click", "em", 5, function( e, trig ) {
- counter += e.data + (trig || 9); // twice, 5+9+5+17=36
- })
+ counter += e.data + ( trig || 9 ); // twice, 5+9+5+17=36
+ } )
.one( "click", "em", 7, function( e, trig ) {
- counter += e.data + (trig || 11); // once, 7+11=18
- })
- .find("em")
- .trigger("click")
+ counter += e.data + ( trig || 11 ); // once, 7+11=18
+ } )
+ .find( "em" )
+ .trigger( "click" )
.trigger( "click", 17 )
.end()
.off( "click", "em" );
assert.equal( counter, 54, "delegated event bindings with data" );
-
// Mixed event bindings and types
counter = 0;
- mixfn = function(e, trig) {
- counter += (e.data || 0) + (trig || 1);
+ mixfn = function( e, trig ) {
+ counter += ( e.data || 0 ) + ( trig || 1 );
};
jQuery( "#onandoff" )
.on( " click clack cluck ", "em", 2, mixfn )
@@ -2172,7 +2177,7 @@ QUnit.test(".on and .off", function( assert ) {
.trigger( "what!" )
.each( function() {
assert.equal( counter, 0, "nothing triggered yet" );
- })
+ } )
.find( "em" )
.one( "cluck", 3, mixfn )
.trigger( "cluck", 8 ) // 3+8 2+8 + 0+8 = 29
@@ -2181,12 +2186,12 @@ QUnit.test(".on and .off", function( assert ) {
.end()
.each( function() {
assert.equal( counter, 49, "after triggering em element" );
- })
- .off( "cluck", function(){} ) // shouldn't remove anything
+ } )
+ .off( "cluck", function() {} ) // shouldn't remove anything
.trigger( "cluck", 2 ) // 0+2 = 2
.each( function() {
assert.equal( counter, 51, "after triggering #onandoff cluck" );
- })
+ } )
.find( "b" )
.on( "click", 95, mixfn )
.on( "clack", "p", 97, mixfn )
@@ -2196,7 +2201,7 @@ QUnit.test(".on and .off", function( assert ) {
.end()
.each( function() {
assert.equal( counter, 51, "after triggering b" );
- })
+ } )
.trigger( "cluck", 3 ) // 0+3 = 3
.off( "clack", "em", mixfn )
.find( "em" )
@@ -2204,20 +2209,20 @@ QUnit.test(".on and .off", function( assert ) {
.end()
.each( function() {
assert.equal( counter, 54, "final triggers" );
- })
+ } )
.off( "click cluck" );
// We should have removed all the event handlers ... kinda hacky way to check this
- data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
- assert.equal( data["events"], undefined, "no events left" );
+ data = jQuery.data[ jQuery( "#onandoff" )[ 0 ].expando ] || {};
+ assert.equal( data[ "events" ], undefined, "no events left" );
$onandoff.remove();
-});
+} );
-QUnit.test("special on name mapping", function( assert ) {
+QUnit.test( "special on name mapping", function( assert ) {
assert.expect( 7 );
- jQuery.event.special["slap"] = {
+ jQuery.event.special[ "slap" ] = {
bindType: "click",
delegateType: "swing",
handle: function( event ) {
@@ -2229,7 +2234,7 @@ QUnit.test("special on name mapping", function( assert ) {
assert.ok( true, "event " + event.type + " triggered" );
};
- jQuery("<div><button id=\"mammy\">Are We Not Men?</button></div>")
+ jQuery( "<div><button id=\"mammy\">Are We Not Men?</button></div>" )
.on( "slap", "button", jQuery.noop )
.on( "swing", "button", comeback )
.find( "button" )
@@ -2248,15 +2253,16 @@ QUnit.test("special on name mapping", function( assert ) {
.trigger( "swing" )
.end()
.remove();
- delete jQuery.event.special["slap"];
+ delete jQuery.event.special[ "slap" ];
- jQuery.event.special["gutfeeling"] = {
+ jQuery.event.special[ "gutfeeling" ] = {
bindType: "click",
delegateType: "click",
handle: function( event ) {
assert.equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" );
+
// Need to call the handler since .one() uses it to unbind
- return event.handleObj.handler.call( this , event );
+ return event.handleObj.handler.call( this, event );
}
};
@@ -2282,11 +2288,11 @@ QUnit.test("special on name mapping", function( assert ) {
.trigger( "gutfeeling" ) // This one should not
.remove();
- delete jQuery.event.special["gutfeeling"];
-});
+ delete jQuery.event.special[ "gutfeeling" ];
+} );
-QUnit.test(".on and .off, selective mixed removal (#10705)", function( assert ) {
- assert.expect(7);
+QUnit.test( ".on and .off, selective mixed removal (#10705)", function( assert ) {
+ assert.expect( 7 );
var timingx = function( e ) {
assert.ok( true, "triggered " + e.type );
@@ -2305,13 +2311,13 @@ QUnit.test(".on and .off, selective mixed removal (#10705)", function( assert )
.trigger( "click" ) // 2
.off( "future click" )
.trigger( "click" ); // 0
-});
+} );
-QUnit.test(".on( event-map, null-selector, data ) #11130", function( assert ) {
+QUnit.test( ".on( event-map, null-selector, data ) #11130", function( assert ) {
assert.expect( 1 );
- var $p = jQuery("<p>Strange Pursuit</p>"),
+ var $p = jQuery( "<p>Strange Pursuit</p>" ),
data = "bar",
map = {
"foo": function( event ) {
@@ -2320,15 +2326,15 @@ QUnit.test(".on( event-map, null-selector, data ) #11130", function( assert ) {
}
};
- $p.on( map, null, data ).trigger("foo");
-});
+ $p.on( map, null, data ).trigger( "foo" );
+} );
-QUnit.test("clone() delegated events (#11076)", function( assert ) {
- assert.expect(3);
+QUnit.test( "clone() delegated events (#11076)", function( assert ) {
+ assert.expect( 3 );
var counter = { "center": 0, "fold": 0, "centerfold": 0 },
clicked = function() {
- counter[ jQuery(this).text().replace(/\s+/, "") ]++;
+ counter[ jQuery( this ).text().replace( /\s+/, "" ) ]++;
},
table =
jQuery( "<table><tr><td>center</td><td>fold</td></tr></table>" )
@@ -2337,27 +2343,27 @@ QUnit.test("clone() delegated events (#11076)", function( assert ) {
.on( "click", "td:last-child", clicked ),
clone = table.clone( true );
- clone.find("td").trigger("click");
- assert.equal( counter["center"], 1, "first child" );
- assert.equal( counter["fold"], 1, "last child" );
- assert.equal( counter["centerfold"], 2, "all children" );
+ clone.find( "td" ).trigger( "click" );
+ assert.equal( counter[ "center" ], 1, "first child" );
+ assert.equal( counter[ "fold" ], 1, "last child" );
+ assert.equal( counter[ "centerfold" ], 2, "all children" );
table.remove();
clone.remove();
-});
+} );
-QUnit.test("checkbox state (#3827)", function( assert ) {
+QUnit.test( "checkbox state (#3827)", function( assert ) {
assert.expect( 9 );
- var markup = jQuery("<div><input type=checkbox><div>").appendTo("#qunit-fixture"),
- cb = markup.find("input")[0];
+ var markup = jQuery( "<div><input type=checkbox><div>" ).appendTo( "#qunit-fixture" ),
+ cb = markup.find( "input" )[ 0 ];
- jQuery(cb).on( "click", function(){
+ jQuery( cb ).on( "click", function() {
assert.equal( this.checked, false, "just-clicked checkbox is not checked" );
- });
- markup.on( "click", function(){
+ } );
+ markup.on( "click", function() {
assert.equal( cb.checked, false, "checkbox is not checked in bubbled event" );
- });
+ } );
// Native click
cb.checked = true;
@@ -2368,23 +2374,23 @@ QUnit.test("checkbox state (#3827)", function( assert ) {
// jQuery click
cb.checked = true;
assert.equal( cb.checked, true, "jQuery - checkbox is initially checked" );
- jQuery( cb ).trigger("click");
+ jQuery( cb ).trigger( "click" );
assert.equal( cb.checked, false, "jQuery - checkbox is no longer checked" );
// Handlers only; checkbox state remains false
jQuery( cb ).triggerHandler( "click" );
-});
+} );
-QUnit.test("hover event no longer special since 1.9", function( assert ) {
+QUnit.test( "hover event no longer special since 1.9", function( assert ) {
assert.expect( 1 );
- jQuery("<div>craft</div>")
+ jQuery( "<div>craft</div>" )
.on( "hover", function( e ) {
assert.equal( e.type, "hover", "I am hovering!" );
- })
- .trigger("hover")
- .off("hover");
-});
+ } )
+ .trigger( "hover" )
+ .off( "hover" );
+} );
QUnit.test( "event object properties on natively-triggered event", function( assert ) {
assert.expect( 3 );
@@ -2395,17 +2401,18 @@ QUnit.test( "event object properties on natively-triggered event", function( ass
// IE9+ requires element to be in the body before it will dispatch
$link.appendTo( "body" ).on( "click", function( e ) {
+
// Not trying to assert specific values here, just ensure the property exists
assert.equal( "detail" in e, true, "has .detail" );
assert.equal( "cancelable" in e, true, "has .cancelable" );
assert.equal( "bubbles" in e, true, "has .bubbles" );
- });
+ } );
evt.initEvent( "click", true, true );
link.dispatchEvent( evt );
$link.off( "click" ).remove();
-});
+} );
-QUnit.test("fixHooks extensions", function( assert ) {
+QUnit.test( "fixHooks extensions", function( assert ) {
assert.expect( 2 );
// IE requires focusable elements to be visible, so append to body
@@ -2414,9 +2421,9 @@ QUnit.test("fixHooks extensions", function( assert ) {
// Ensure the property doesn't exist
$fixture.on( "click", function( event ) {
- assert.ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" );
- });
- fireNative( $fixture[0], "click" );
+ assert.ok( !( "blurrinessLevel" in event ), "event.blurrinessLevel does not exist" );
+ } );
+ fireNative( $fixture[ 0 ], "click" );
$fixture.off( "click" );
jQuery.event.fixHooks.click = {
@@ -2429,13 +2436,13 @@ QUnit.test("fixHooks extensions", function( assert ) {
// Trigger a native click and ensure the property is set
$fixture.on( "click", function( event ) {
assert.equal( event.blurrinessLevel, 42, "event.blurrinessLevel was set" );
- });
- fireNative( $fixture[0], "click" );
+ } );
+ fireNative( $fixture[ 0 ], "click" );
delete jQuery.event.fixHooks.click;
$fixture.off( "click" ).remove();
jQuery.event.fixHooks.click = saved;
-});
+} );
QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2009)", function( assert ) {
assert.expect( 4 );
@@ -2445,48 +2452,48 @@ QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2
$fixture.on( "dragmove", function( evt ) {
assert.ok( "pageX" in evt, "checking for pageX property on dragmove" );
assert.ok( "pageY" in evt, "checking for pageY property on dragmove" );
- });
+ } );
fireNative( $fixture[ 0 ], "dragmove" );
$fixture.on( "drop", function( evt ) {
assert.ok( "pageX" in evt, "checking for pageX property on drop" );
assert.ok( "pageY" in evt, "checking for pageY property on drop" );
- });
+ } );
fireNative( $fixture[ 0 ], "drop" );
$fixture.unbind( "dragmove drop" ).remove();
-});
+} );
QUnit.test( "focusin using non-element targets", function( assert ) {
assert.expect( 2 );
jQuery( document ).on( "focusin", function( e ) {
assert.ok( e.type === "focusin", "got a focusin event on a document" );
- }).trigger( "focusin" ).off( "focusin" );
+ } ).trigger( "focusin" ).off( "focusin" );
jQuery( window ).on( "focusin", function( e ) {
assert.ok( e.type === "focusin", "got a focusin event on a window" );
- }).trigger( "focusin" ).off( "focusin" );
+ } ).trigger( "focusin" ).off( "focusin" );
-});
+} );
testIframeWithCallback(
"focusin from an iframe",
"event/focusinCrossFrame.html",
function( frameDoc, assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var input = jQuery( frameDoc ).find( "#frame-input" );
// Create a focusin handler on the parent; shouldn't affect the iframe's fate
jQuery ( "body" ).on( "focusin.iframeTest", function() {
assert.ok( false, "fired a focusin event in the parent document" );
- });
+ } );
input.on( "focusin", function() {
assert.ok( true, "fired a focusin event in the iframe" );
- });
+ } );
// Avoid a native event; Chrome can't force focus to another frame
input.trigger( "focusin" );
@@ -2506,7 +2513,7 @@ testIframeWithCallback(
"jQuery.ready promise",
"event/promiseReady.html",
function( isOk, assert ) {
- assert.expect(1);
+ assert.expect( 1 );
assert.ok( isOk, "$.when( $.ready ) works" );
}
);
@@ -2515,7 +2522,7 @@ testIframeWithCallback(
"Focusing iframe element",
"event/focusElem.html",
function( isOk, assert ) {
- assert.expect(1);
+ assert.expect( 1 );
assert.ok( isOk, "Focused an element in an iframe" );
}
);
@@ -2535,46 +2542,47 @@ if ( hasPHP ) {
"jQuery.ready synchronous load with long loading subresources",
"event/syncReady.html",
function( isOk, assert ) {
- assert.expect(1);
+ assert.expect( 1 );
assert.ok( isOk, "jQuery loaded synchronously fires ready when the DOM can truly be interacted with" );
}
);
}
-QUnit.test("change handler should be detached from element", function( assert ) {
+QUnit.test( "change handler should be detached from element", function( assert ) {
assert.expect( 2 );
var $fixture = jQuery( "<input type='text' id='change-ie-leak' />" ).appendTo( "body" ),
originRemoveEvent = jQuery.removeEvent,
- wrapperRemoveEvent = function(elem, type, handle){
- assert.equal("change", type, "Event handler for 'change' event should be removed");
- assert.equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element");
- originRemoveEvent(elem, type, handle);
+ wrapperRemoveEvent = function( elem, type, handle ) {
+ assert.equal( "change", type, "Event handler for 'change' event should be removed" );
+ assert.equal( "change-ie-leak", jQuery( elem ).attr( "id" ), "Event handler for 'change' event should be removed from appropriate element" );
+ originRemoveEvent( elem, type, handle );
};
jQuery.removeEvent = wrapperRemoveEvent ;
- $fixture.on( "change", function() {});
+ $fixture.on( "change", function() {} );
$fixture.off( "change" );
$fixture.remove();
jQuery.removeEvent = originRemoveEvent;
-});
+} );
-QUnit.test("trigger click on checkbox, fires change event", function( assert ) {
- assert.expect(1);
+QUnit.test( "trigger click on checkbox, fires change event", function( assert ) {
+ assert.expect( 1 );
- var check = jQuery("#check2");
+ var check = jQuery( "#check2" );
var done = assert.async();
check.on( "change", function() {
+
// get it?
- check.off("change");
+ check.off( "change" );
assert.ok( true, "Change event fired as a result of triggered click" );
done();
- }).trigger("click");
-});
+ } ).trigger( "click" );
+} );
QUnit.test( "Namespace preserved when passed an Event (#12739)", function( assert ) {
assert.expect( 4 );
@@ -2585,84 +2593,84 @@ QUnit.test( "Namespace preserved when passed an Event (#12739)", function( asser
triggered = 0,
fooEvent;
- markup.find("div")
+ markup.find( "div" )
.addBack()
.on( "foo.bar", function( e ) {
if ( !e.handled ) {
triggered++;
e.handled = true;
assert.equal( e.namespace, "bar", "namespace is bar" );
- jQuery( e.target ).find("div").each(function() {
+ jQuery( e.target ).find( "div" ).each( function() {
jQuery( this ).triggerHandler( e );
- });
+ } );
}
- })
+ } )
.on( "foo.bar2", function() {
assert.ok( false, "foo.bar2 called on trigger " + triggered + " id " + this.id );
- });
+ } );
- markup.trigger("foo.bar");
- markup.trigger( jQuery.Event("foo.bar") );
- fooEvent = jQuery.Event("foo");
+ markup.trigger( "foo.bar" );
+ markup.trigger( jQuery.Event( "foo.bar" ) );
+ fooEvent = jQuery.Event( "foo" );
fooEvent.namespace = "bar";
markup.trigger( fooEvent );
markup.remove();
assert.equal( triggered, 3, "foo.bar triggered" );
-});
+} );
QUnit.test( "make sure events cloned correctly", function( assert ) {
assert.expect( 18 );
var clone,
- fixture = jQuery("#qunit-fixture"),
- checkbox = jQuery("#check1"),
- p = jQuery("#firstp");
+ fixture = jQuery( "#qunit-fixture" ),
+ checkbox = jQuery( "#check1" ),
+ p = jQuery( "#firstp" );
fixture.on( "click change", function( event, result ) {
assert.ok( result, event.type + " on original element is fired" );
- }).on( "click", "#firstp", function( event, result ) {
+ } ).on( "click", "#firstp", function( event, result ) {
assert.ok( result, "Click on original child element though delegation is fired" );
- }).on( "change", "#check1", function( event, result ) {
+ } ).on( "change", "#check1", function( event, result ) {
assert.ok( result, "Change on original child element though delegation is fired" );
- });
+ } );
- p.on("click", function() {
+ p.on( "click", function() {
assert.ok( true, "Click on original child element is fired" );
- });
+ } );
- checkbox.on("change", function() {
+ checkbox.on( "change", function() {
assert.ok( true, "Change on original child element is fired" );
- });
+ } );
- fixture.clone().trigger("click").trigger("change"); // 0 events should be fired
+ fixture.clone().trigger( "click" ).trigger( "change" ); // 0 events should be fired
clone = fixture.clone( true );
- clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
- clone.find("#check1").trigger( "change", true ); // 3 events should fire
+ clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire
+ clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire
clone.remove();
clone = fixture.clone( true, true );
- clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
- clone.find("#check1").trigger( "change", true ); // 3 events should fire
+ clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire
+ clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire
fixture.off();
p.off();
checkbox.off();
- p.trigger("click"); // 0 should be fired
- checkbox.trigger("change"); // 0 should be fired
+ p.trigger( "click" ); // 0 should be fired
+ checkbox.trigger( "change" ); // 0 should be fired
- clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire
- clone.find("#check1").trigger( "change", true ); // 3 events should fire
+ clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire
+ clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire
clone.remove();
- clone.find("p").eq(0).trigger("click"); // 0 should be fired
- clone.find("#check1").trigger("change"); // 0 events should fire
-});
+ clone.find( "p" ).eq( 0 ).trigger( "click" ); // 0 should be fired
+ clone.find( "#check1" ).trigger( "change" ); // 0 events should fire
+} );
QUnit.test( "String.prototype.namespace does not cause trigger() to throw (#13360)", function( assert ) {
assert.expect( 1 );
@@ -2671,21 +2679,21 @@ QUnit.test( "String.prototype.namespace does not cause trigger() to throw (#1336
String.prototype.namespace = function() {};
try {
- jQuery("<p>").trigger("foo.bar");
- } catch( e ) {
+ jQuery( "<p>" ).trigger( "foo.bar" );
+ } catch ( e ) {
errored = true;
}
assert.equal( errored, false, "trigger() did not throw exception" );
delete String.prototype.namespace;
-});
+} );
QUnit.test( "Inline event result is returned (#13993)", function( assert ) {
assert.expect( 1 );
- var result = jQuery("<p onclick='return 42'>hello</p>").triggerHandler("click");
+ var result = jQuery( "<p onclick='return 42'>hello</p>" ).triggerHandler( "click" );
assert.equal( result, 42, "inline handler returned value" );
-});
+} );
QUnit.test( ".off() removes the expando when there's no more data", function( assert ) {
assert.expect( 1 );
@@ -2706,7 +2714,7 @@ QUnit.test( ".off() removes the expando when there's no more data", function( as
assert.ok( false, "Expando was not removed when there was no more data" );
}
}
-});
+} );
QUnit.test( "preventDefault() on focusin does not throw exception", function( assert ) {
assert.expect( 1 );
@@ -2765,7 +2773,7 @@ QUnit.test( "Donor event interference", function( assert ) {
QUnit.test( "originalEvent property for Chrome, Safari and FF of simulated event", function( assert ) {
var userAgent = window.navigator.userAgent;
- if ( !(/chrome/i.test( userAgent ) ||
+ if ( !( /chrome/i.test( userAgent ) ||
/firefox/i.test( userAgent ) ||
/safari/i.test( userAgent ) ) ) {
assert.expect( 1 );
@@ -2796,7 +2804,7 @@ QUnit.test( "originalEvent property for Chrome, Safari and FF of simulated event
} );
// This tests are unreliable in Firefox
-if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
+if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) {
QUnit.test( "Check order of focusin/focusout events", function( assert ) {
assert.expect( 2 );
@@ -2806,15 +2814,15 @@ if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
input.on( "focus", function() {
focus = true;
- }).on( "focusin", function() {
+ } ).on( "focusin", function() {
assert.ok( !focus, "Focusin event should fire before focus does" );
- }).on( "blur", function() {
+ } ).on( "blur", function() {
blur = true;
- }).on( "focusout", function() {
+ } ).on( "focusout", function() {
assert.ok( !blur, "Focusout event should fire before blur does" );
- });
+ } );
// gain focus
input.trigger( "focus" );
@@ -2824,43 +2832,43 @@ if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
// cleanup
input.off();
- });
+ } );
- QUnit.test("focus-blur order (#12868)", function( assert ) {
+ QUnit.test( "focus-blur order (#12868)", function( assert ) {
assert.expect( 5 );
var order,
- $text = jQuery("#text1"),
- $radio = jQuery("#radio1").trigger("focus");
+ $text = jQuery( "#text1" ),
+ $radio = jQuery( "#radio1" ).trigger( "focus" );
// IE8-10 fire focus/blur events asynchronously; this is the resulting mess.
// IE's browser window must be topmost for this to work properly!!
QUnit.stop();
- $radio[0].focus();
+ $radio[ 0 ].focus();
setTimeout( function() {
$text
- .on( "focus", function(){
+ .on( "focus", function() {
assert.equal( order++, 1, "text focus" );
- })
- .on( "blur", function(){
+ } )
+ .on( "blur", function() {
assert.equal( order++, 0, "text blur" );
- });
+ } );
$radio
- .on( "focus", function(){
+ .on( "focus", function() {
assert.equal( order++, 1, "radio focus" );
- })
- .on( "blur", function(){
+ } )
+ .on( "blur", function() {
assert.equal( order++, 0, "radio blur" );
- });
+ } );
// Enabled input getting focus
order = 0;
- assert.equal( document.activeElement, $radio[0], "radio has focus" );
- $text.trigger("focus");
+ assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" );
+ $text.trigger( "focus" );
setTimeout( function() {
- assert.equal( document.activeElement, $text[0], "text has focus" );
+ assert.equal( document.activeElement, $text[ 0 ], "text has focus" );
// Run handlers without native method on an input
order = 1;
@@ -2869,5 +2877,5 @@ if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
QUnit.start();
}, 50 );
}, 50 );
- });
+ } );
}
diff --git a/test/unit/exports.js b/test/unit/exports.js
index 39e4b1b47..bca8954cf 100644
--- a/test/unit/exports.js
+++ b/test/unit/exports.js
@@ -1,7 +1,7 @@
-QUnit.module("exports", { teardown: moduleTeardown });
+QUnit.module( "exports", { teardown: moduleTeardown } );
-QUnit.test("amdModule", function( assert ) {
- assert.expect(1);
+QUnit.test( "amdModule", function( assert ) {
+ assert.expect( 1 );
assert.equal( jQuery, amdDefined, "Make sure defined module matches jQuery" );
-});
+} );
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 5cd91a30d..2daa78fc4 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -1,6 +1,6 @@
QUnit.module( "manipulation", {
teardown: moduleTeardown
-});
+} );
// Ensure that an extended Array prototype doesn't break jQuery
Array.prototype.arrayProtoFn = function() {
@@ -35,31 +35,31 @@ QUnit.test( "text()", function( assert ) {
var expected, frag, $newLineTest;
expected = "This link has class=\"blog\": Simon Willison's Weblog";
- assert.equal( jQuery("#sap").text(), expected, "Check for merged text of more then one element." );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for merged text of more then one element." );
// Check serialization of text values
- assert.equal( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retrieved from .text()." );
- assert.notEqual( jQuery(document).text(), "", "Retrieving text for the document retrieves all text (#10724)." );
+ assert.equal( jQuery( document.createTextNode( "foo" ) ).text(), "foo", "Text node was retrieved from .text()." );
+ assert.notEqual( jQuery( document ).text(), "", "Retrieving text for the document retrieves all text (#10724)." );
// Retrieve from document fragments #10864
frag = document.createDocumentFragment();
- frag.appendChild( document.createTextNode("foo") );
+ frag.appendChild( document.createTextNode( "foo" ) );
- assert.equal( jQuery(frag).text(), "foo", "Document Fragment Text node was retrieved from .text()." );
+ assert.equal( jQuery( frag ).text(), "foo", "Document Fragment Text node was retrieved from .text()." );
- $newLineTest = jQuery("<div>test<br/>testy</div>").appendTo("#moretests");
- $newLineTest.find("br").replaceWith("\n");
+ $newLineTest = jQuery( "<div>test<br/>testy</div>" ).appendTo( "#moretests" );
+ $newLineTest.find( "br" ).replaceWith( "\n" );
assert.equal( $newLineTest.text(), "test\ntesty", "text() does not remove new lines (#11153)" );
$newLineTest.remove();
-});
+} );
QUnit.test( "text(undefined)", function( assert ) {
assert.expect( 1 );
- assert.equal( jQuery("#foo").text("<div").text(undefined)[ 0 ].innerHTML, "&lt;div", ".text(undefined) is chainable (#5571)" );
-});
+ assert.equal( jQuery( "#foo" ).text( "<div" ).text( undefined )[ 0 ].innerHTML, "&lt;div", ".text(undefined) is chainable (#5571)" );
+} );
function testText( valueObj, assert ) {
@@ -67,12 +67,12 @@ function testText( valueObj, assert ) {
var val, j, expected, $multipleElements, $parentDiv, $childDiv;
- val = valueObj("<div><b>Hello</b> cruel world!</div>");
- assert.equal( jQuery("#foo").text(val)[ 0 ].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
+ val = valueObj( "<div><b>Hello</b> cruel world!</div>" );
+ assert.equal( jQuery( "#foo" ).text( val )[ 0 ].innerHTML.replace( />/g, "&gt;" ), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
// using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
- j.text( valueObj("hi!") );
+ j = jQuery( "#nonnodes" ).contents();
+ j.text( valueObj( "hi!" ) );
assert.equal( jQuery( j[ 0 ] ).text(), "hi!", "Check node,textnode,comment with text()" );
assert.equal( j[ 1 ].nodeValue, " there ", "Check node,textnode,comment with text()" );
@@ -84,24 +84,24 @@ function testText( valueObj, assert ) {
$multipleElements = jQuery( "<div>Hello</div>" ).add( "<div>World</div>" );
$multipleElements.text( expected );
- assert.equal( $multipleElements.eq(0).text(), expected, "text() updates multiple elements (#11809)" );
- assert.equal( $multipleElements.eq(1).text(), expected, "text() updates multiple elements (#11809)" );
+ assert.equal( $multipleElements.eq( 0 ).text(), expected, "text() updates multiple elements (#11809)" );
+ assert.equal( $multipleElements.eq( 1 ).text(), expected, "text() updates multiple elements (#11809)" );
// Prevent memory leaks #11809
$childDiv = jQuery( "<div/>" );
- $childDiv.data("leak", true);
+ $childDiv.data( "leak", true );
$parentDiv = jQuery( "<div/>" );
$parentDiv.append( $childDiv );
- $parentDiv.text("Dry off");
+ $parentDiv.text( "Dry off" );
}
QUnit.test( "text(String)", function( assert ) {
testText( manipulationBareObj, assert );
-});
+} );
QUnit.test( "text(Function)", function( assert ) {
testText( manipulationFunctionReturningObj, assert );
-});
+} );
QUnit.test( "text(Function) with incoming value", function( assert ) {
@@ -109,43 +109,43 @@ QUnit.test( "text(Function) with incoming value", function( assert ) {
var old = "This link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#sap").text(function( i, val ) {
+ jQuery( "#sap" ).text( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
return "foobar";
- });
+ } );
- assert.equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
-});
+ assert.equal( jQuery( "#sap" ).text(), "foobar", "Check for merged text of more then one element." );
+} );
function testAppendForObject( valueObj, isFragment, assert ) {
var $base,
type = isFragment ? " (DocumentFragment)" : " (Element)",
text = "This link has class=\"blog\": Simon Willison's Weblog",
- el = document.getElementById("sap").cloneNode( true ),
- first = document.getElementById("first"),
- yahoo = document.getElementById("yahoo");
+ el = document.getElementById( "sap" ).cloneNode( true ),
+ first = document.getElementById( "first" ),
+ yahoo = document.getElementById( "yahoo" );
if ( isFragment ) {
$base = document.createDocumentFragment();
- jQuery( el ).contents().each(function() {
+ jQuery( el ).contents().each( function() {
$base.appendChild( this );
- });
+ } );
$base = jQuery( $base );
} else {
$base = jQuery( el );
}
- assert.equal( $base.clone().append( valueObj(first.cloneNode(true)) ).text(),
+ assert.equal( $base.clone().append( valueObj( first.cloneNode( true ) ) ).text(),
text + "Try them out:",
"Check for appending of element" + type
);
- assert.equal( $base.clone().append( valueObj([ first.cloneNode(true), yahoo.cloneNode(true) ]) ).text(),
+ assert.equal( $base.clone().append( valueObj( [ first.cloneNode( true ), yahoo.cloneNode( true ) ] ) ).text(),
text + "Try them out:Yahoo",
"Check for appending of array of elements" + type
);
- assert.equal( $base.clone().append( valueObj(jQuery("#yahoo, #first").clone()) ).text(),
+ assert.equal( $base.clone().append( valueObj( jQuery( "#yahoo, #first" ).clone() ) ).text(),
text + "YahooTry them out:",
"Check for appending of jQuery object" + type
);
@@ -155,27 +155,27 @@ function testAppendForObject( valueObj, isFragment, assert ) {
"Check for appending a number" + type
);
- assert.equal( $base.clone().append( valueObj([ jQuery("#first").clone(), jQuery("#yahoo, #google").clone() ]) ).text(),
+ assert.equal( $base.clone().append( valueObj( [ jQuery( "#first" ).clone(), jQuery( "#yahoo, #google" ).clone() ] ) ).text(),
text + "Try them out:GoogleYahoo",
"Check for appending of array of jQuery objects"
);
- assert.equal( $base.clone().append( valueObj(" text with spaces ") ).text(),
+ assert.equal( $base.clone().append( valueObj( " text with spaces " ) ).text(),
text + " text with spaces ",
"Check for appending text with spaces" + type
);
- assert.equal( $base.clone().append( valueObj([]) ).text(),
+ assert.equal( $base.clone().append( valueObj( [] ) ).text(),
text,
"Check for appending an empty array" + type
);
- assert.equal( $base.clone().append( valueObj("") ).text(),
+ assert.equal( $base.clone().append( valueObj( "" ) ).text(),
text,
"Check for appending an empty string" + type
);
- assert.equal( $base.clone().append( valueObj(document.getElementsByTagName("foo")) ).text(),
+ assert.equal( $base.clone().append( valueObj( document.getElementsByTagName( "foo" ) ) ).text(),
text,
"Check for appending an empty nodelist" + type
);
@@ -185,7 +185,7 @@ function testAppendForObject( valueObj, isFragment, assert ) {
"Make sure that multiple arguments works." + type
);
- assert.equal( $base.clone().append( valueObj(document.getElementById("form").cloneNode(true)) ).children("form").length,
+ assert.equal( $base.clone().append( valueObj( document.getElementById( "form" ).cloneNode( true ) ) ).children( "form" ).length,
1,
"Check for appending a form (#910)" + type
);
@@ -202,130 +202,130 @@ function testAppend( valueObj, assert ) {
$input, $radioChecked, $radioUnchecked, $radioParent, $map, $table;
defaultText = "Try them out:";
- result = jQuery("#first").append( valueObj("<b>buga</b>") );
+ result = jQuery( "#first" ).append( valueObj( "<b>buga</b>" ) );
assert.equal( result.text(), defaultText + "buga", "Check if text appending works" );
- assert.equal( jQuery("#select3").append( valueObj("<option value='appendTest'>Append Test</option>") ).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" );
+ assert.equal( jQuery( "#select3" ).append( valueObj( "<option value='appendTest'>Append Test</option>" ) ).find( "option:last-child" ).attr( "value" ), "appendTest", "Appending html options to select element" );
- jQuery("#qunit-fixture form").append( valueObj("<input name='radiotest' type='radio' checked='checked' />") );
- jQuery("#qunit-fixture form input[name=radiotest]").each(function() {
- assert.ok( jQuery(this).is(":checked"), "Append checked radio" );
- }).remove();
+ jQuery( "#qunit-fixture form" ).append( valueObj( "<input name='radiotest' type='radio' checked='checked' />" ) );
+ jQuery( "#qunit-fixture form input[name=radiotest]" ).each( function() {
+ assert.ok( jQuery( this ).is( ":checked" ), "Append checked radio" );
+ } ).remove();
- jQuery("#qunit-fixture form").append( valueObj("<input name='radiotest2' type='radio' checked = 'checked' />") );
- jQuery("#qunit-fixture form input[name=radiotest2]").each(function() {
- assert.ok( jQuery(this).is(":checked"), "Append alternately formated checked radio" );
- }).remove();
+ jQuery( "#qunit-fixture form" ).append( valueObj( "<input name='radiotest2' type='radio' checked = 'checked' />" ) );
+ jQuery( "#qunit-fixture form input[name=radiotest2]" ).each( function() {
+ assert.ok( jQuery( this ).is( ":checked" ), "Append alternately formated checked radio" );
+ } ).remove();
- jQuery("#qunit-fixture form").append( valueObj("<input name='radiotest3' type='radio' checked />") );
- jQuery("#qunit-fixture form input[name=radiotest3]").each(function() {
- assert.ok( jQuery(this).is(":checked"), "Append HTML5-formated checked radio" );
- }).remove();
+ jQuery( "#qunit-fixture form" ).append( valueObj( "<input name='radiotest3' type='radio' checked />" ) );
+ jQuery( "#qunit-fixture form input[name=radiotest3]" ).each( function() {
+ assert.ok( jQuery( this ).is( ":checked" ), "Append HTML5-formated checked radio" );
+ } ).remove();
- jQuery("#qunit-fixture form").append( valueObj("<input type='radio' checked='checked' name='radiotest4' />") );
- jQuery("#qunit-fixture form input[name=radiotest4]").each(function() {
- assert.ok( jQuery(this).is(":checked"), "Append with name attribute after checked attribute" );
- }).remove();
+ jQuery( "#qunit-fixture form" ).append( valueObj( "<input type='radio' checked='checked' name='radiotest4' />" ) );
+ jQuery( "#qunit-fixture form input[name=radiotest4]" ).each( function() {
+ assert.ok( jQuery( this ).is( ":checked" ), "Append with name attribute after checked attribute" );
+ } ).remove();
message = "Test for appending a DOM node to the contents of an iframe";
- iframe = jQuery("#iframe")[ 0 ];
+ iframe = jQuery( "#iframe" )[ 0 ];
iframeDoc = iframe.contentDocument || iframe.contentWindow && iframe.contentWindow.document;
try {
if ( iframeDoc && iframeDoc.body ) {
- assert.equal( jQuery(iframeDoc.body).append( valueObj("<div id='success'>test</div>") )[ 0 ].lastChild.id, "success", message );
+ assert.equal( jQuery( iframeDoc.body ).append( valueObj( "<div id='success'>test</div>" ) )[ 0 ].lastChild.id, "success", message );
} else {
assert.ok( true, message + " - can't test" );
}
- } catch( e ) {
+ } catch ( e ) {
assert.strictEqual( e.message || e, undefined, message );
}
- jQuery("<fieldset/>").appendTo("#form").append( valueObj("<legend id='legend'>test</legend>") );
+ jQuery( "<fieldset/>" ).appendTo( "#form" ).append( valueObj( "<legend id='legend'>test</legend>" ) );
t( "Append legend", "#legend", [ "legend" ] );
- $map = jQuery("<map/>").append( valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>") );
+ $map = jQuery( "<map/>" ).append( valueObj( "<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>" ) );
assert.equal( $map[ 0 ].childNodes.length, 1, "The area was inserted." );
assert.equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
- jQuery("#select1").append( valueObj("<OPTION>Test</OPTION>") );
- assert.equal( jQuery("#select1 option:last-child").text(), "Test", "Appending OPTION (all caps)" );
+ jQuery( "#select1" ).append( valueObj( "<OPTION>Test</OPTION>" ) );
+ assert.equal( jQuery( "#select1 option:last-child" ).text(), "Test", "Appending OPTION (all caps)" );
- jQuery("#select1").append( valueObj("<optgroup label='optgroup'><option>optgroup</option></optgroup>") );
- assert.equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" );
- assert.equal( jQuery("#select1 option").last().text(), "optgroup", "Appending optgroup" );
+ jQuery( "#select1" ).append( valueObj( "<optgroup label='optgroup'><option>optgroup</option></optgroup>" ) );
+ assert.equal( jQuery( "#select1 optgroup" ).attr( "label" ), "optgroup", "Label attribute in newly inserted optgroup is correct" );
+ assert.equal( jQuery( "#select1 option" ).last().text(), "optgroup", "Appending optgroup" );
- $table = jQuery("#table");
+ $table = jQuery( "#table" );
- jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) {
+ jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) {
$table.append( valueObj( "<" + name + "/>" ) );
assert.equal( $table.find( name ).length, 1, "Append " + name );
assert.ok( jQuery.parseHTML( "<" + name + "/>" ).length, name + " wrapped correctly" );
- });
+ } );
- jQuery("#table colgroup").append( valueObj("<col/>") );
- assert.equal( jQuery("#table colgroup col").length, 1, "Append col" );
+ jQuery( "#table colgroup" ).append( valueObj( "<col/>" ) );
+ assert.equal( jQuery( "#table colgroup col" ).length, 1, "Append col" );
- jQuery("#form")
- .append( valueObj("<select id='appendSelect1'></select>") )
- .append( valueObj("<select id='appendSelect2'><option>Test</option></select>") );
+ jQuery( "#form" )
+ .append( valueObj( "<select id='appendSelect1'></select>" ) )
+ .append( valueObj( "<select id='appendSelect2'><option>Test</option></select>" ) );
t( "Append Select", "#appendSelect1, #appendSelect2", [ "appendSelect1", "appendSelect2" ] );
- assert.equal( "Two nodes", jQuery("<div />").append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" );
- assert.equal( jQuery("<div />").append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" );
+ assert.equal( "Two nodes", jQuery( "<div />" ).append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" );
+ assert.equal( jQuery( "<div />" ).append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" );
// using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
- d = jQuery("<div/>").appendTo("#nonnodes").append( j );
+ j = jQuery( "#nonnodes" ).contents();
+ d = jQuery( "<div/>" ).appendTo( "#nonnodes" ).append( j );
- assert.equal( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
+ assert.equal( jQuery( "#nonnodes" ).length, 1, "Check node,textnode,comment append moved leaving just the div" );
assert.equal( d.contents().length, 3, "Check node,textnode,comment append works" );
- d.contents().appendTo("#nonnodes");
+ d.contents().appendTo( "#nonnodes" );
d.remove();
- assert.equal( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment append cleanup worked" );
+ assert.equal( jQuery( "#nonnodes" ).contents().length, 3, "Check node,textnode,comment append cleanup worked" );
- $input = jQuery("<input type='checkbox'/>").prop( "checked", true ).appendTo("#testForm");
+ $input = jQuery( "<input type='checkbox'/>" ).prop( "checked", true ).appendTo( "#testForm" );
assert.equal( $input[ 0 ].checked, true, "A checked checkbox that is appended stays checked" );
- $radioChecked = jQuery("input[type='radio'][name='R1']").eq( 1 );
+ $radioChecked = jQuery( "input[type='radio'][name='R1']" ).eq( 1 );
$radioParent = $radioChecked.parent();
- $radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent );
- $radioChecked.trigger("click");
+ $radioUnchecked = jQuery( "<input type='radio' name='R1' checked='checked'/>" ).appendTo( $radioParent );
+ $radioChecked.trigger( "click" );
$radioUnchecked[ 0 ].checked = false;
- jQuery("<div/>").insertBefore($radioParent).append($radioParent);
+ jQuery( "<div/>" ).insertBefore( $radioParent ).append( $radioParent );
assert.equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" );
assert.equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" );
- assert.equal( jQuery("<div/>").append( valueObj("option<area/>") )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
+ assert.equal( jQuery( "<div/>" ).append( valueObj( "option<area/>" ) )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
}
QUnit.test( "append(String|Element|Array<Element>|jQuery)", function( assert ) {
testAppend( manipulationBareObj, assert );
-});
+} );
QUnit.test( "append(Function)", function( assert ) {
testAppend( manipulationFunctionReturningObj, assert );
-});
+} );
QUnit.test( "append(param) to object, see #11280", function( assert ) {
assert.expect( 5 );
- var object = jQuery( document.createElement("object") ).appendTo( document.body );
+ var object = jQuery( document.createElement( "object" ) ).appendTo( document.body );
assert.equal( object.children().length, 0, "object does not start with children" );
- object.append( jQuery("<param type='wmode' name='foo'>") );
+ object.append( jQuery( "<param type='wmode' name='foo'>" ) );
assert.equal( object.children().length, 1, "appended param" );
- assert.equal( object.children().eq(0).attr("name"), "foo", "param has name=foo" );
+ assert.equal( object.children().eq( 0 ).attr( "name" ), "foo", "param has name=foo" );
- object = jQuery("<object><param type='baz' name='bar'></object>");
+ object = jQuery( "<object><param type='baz' name='bar'></object>" );
assert.equal( object.children().length, 1, "object created with child param" );
- assert.equal( object.children().eq(0).attr("name"), "bar", "param has name=bar" );
-});
+ assert.equal( object.children().eq( 0 ).attr( "name" ), "bar", "param has name=bar" );
+} );
QUnit.test( "append(Function) returns String", function( assert ) {
@@ -334,86 +334,86 @@ QUnit.test( "append(Function) returns String", function( assert ) {
var defaultText, result, select, old;
defaultText = "Try them out:";
- old = jQuery("#first").html();
+ old = jQuery( "#first" ).html();
- result = jQuery("#first").append(function( i, val ) {
+ result = jQuery( "#first" ).append( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
return "<b>buga</b>";
- });
+ } );
assert.equal( result.text(), defaultText + "buga", "Check if text appending works" );
- select = jQuery("#select3");
+ select = jQuery( "#select3" );
old = select.html();
- assert.equal( select.append(function( i, val ) {
+ assert.equal( select.append( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
return "<option value='appendTest'>Append Test</option>";
- }).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" );
-});
+ } ).find( "option:last-child" ).attr( "value" ), "appendTest", "Appending html options to select element" );
+} );
QUnit.test( "append(Function) returns Element", function( assert ) {
assert.expect( 2 );
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:",
- old = jQuery("#sap").html();
+ old = jQuery( "#sap" ).html();
- jQuery("#sap").append(function( i, val ) {
+ jQuery( "#sap" ).append( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
- return document.getElementById("first");
- });
- assert.equal( jQuery("#sap").text(), expected, "Check for appending of element" );
-});
+ return document.getElementById( "first" );
+ } );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of element" );
+} );
QUnit.test( "append(Function) returns Array<Element>", function( assert ) {
assert.expect( 2 );
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo",
- old = jQuery("#sap").html();
+ old = jQuery( "#sap" ).html();
- jQuery("#sap").append(function( i, val ) {
+ jQuery( "#sap" ).append( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
- return [ document.getElementById("first"), document.getElementById("yahoo") ];
- });
- assert.equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
-});
+ return [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ];
+ } );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of array of elements" );
+} );
QUnit.test( "append(Function) returns jQuery", function( assert ) {
assert.expect( 2 );
var expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:",
- old = jQuery("#sap").html();
+ old = jQuery( "#sap" ).html();
- jQuery("#sap").append(function( i, val ) {
+ jQuery( "#sap" ).append( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
- return jQuery("#yahoo, #first");
- });
- assert.equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
-});
+ return jQuery( "#yahoo, #first" );
+ } );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of jQuery object" );
+} );
QUnit.test( "append(Function) returns Number", function( assert ) {
assert.expect( 2 );
- var old = jQuery("#sap").html();
+ var old = jQuery( "#sap" ).html();
- jQuery("#sap").append(function( i, val ) {
+ jQuery( "#sap" ).append( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
return 5;
- });
- assert.ok( jQuery("#sap")[ 0 ].innerHTML.match( /5$/ ), "Check for appending a number" );
-});
+ } );
+ assert.ok( jQuery( "#sap" )[ 0 ].innerHTML.match( /5$/ ), "Check for appending a number" );
+} );
QUnit.test( "XML DOM manipulation (#9960)", function( assert ) {
assert.expect( 5 );
var scxml1Adopted,
- xmlDoc1 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state x='100' y='100' initial='actions' id='provisioning'></state><state x='100' y='100' id='error'></state><state x='100' y='100' id='finished' final='true'></state></scxml>"),
- xmlDoc2 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>"),
+ xmlDoc1 = jQuery.parseXML( "<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state x='100' y='100' initial='actions' id='provisioning'></state><state x='100' y='100' id='error'></state><state x='100' y='100' id='finished' final='true'></state></scxml>" ),
+ xmlDoc2 = jQuery.parseXML( "<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>" ),
xml1 = jQuery( xmlDoc1 ),
xml2 = jQuery( xmlDoc2 ),
scxml1 = jQuery( "scxml", xml1 ),
scxml2 = jQuery( "scxml", xml2 ),
- state = scxml2.find("state");
+ state = scxml2.find( "state" );
// Android 2.3 doesn't automatically adopt nodes from foreign documents.
// Although technically this is compliant behavior, no other browser
@@ -425,16 +425,16 @@ QUnit.test( "XML DOM manipulation (#9960)", function( assert ) {
}
scxml1.append( state );
- assert.strictEqual( scxml1[0].lastChild, state[0], "append" );
+ assert.strictEqual( scxml1[ 0 ].lastChild, state[ 0 ], "append" );
scxml1.prepend( state );
- assert.strictEqual( scxml1[0].firstChild, state[0], "prepend" );
+ assert.strictEqual( scxml1[ 0 ].firstChild, state[ 0 ], "prepend" );
- scxml1.find("#finished").after( state );
- assert.strictEqual( scxml1[0].lastChild, state[0], "after" );
+ scxml1.find( "#finished" ).after( state );
+ assert.strictEqual( scxml1[ 0 ].lastChild, state[ 0 ], "after" );
- scxml1.find("#provisioning").before( state );
- assert.strictEqual( scxml1[0].firstChild, state[0], "before" );
+ scxml1.find( "#provisioning" ).before( state );
+ assert.strictEqual( scxml1[ 0 ].firstChild, state[ 0 ], "before" );
// Support: Android 2.3
if ( /android 2\.3/i.test( navigator.userAgent ) ) {
@@ -443,8 +443,8 @@ QUnit.test( "XML DOM manipulation (#9960)", function( assert ) {
} else {
scxml2.replaceWith( scxml1 );
}
- assert.deepEqual( jQuery( "state", xml2 ).get(), scxml1.find("state").get(), "replaceWith" );
-});
+ assert.deepEqual( jQuery( "state", xml2 ).get(), scxml1.find( "state" ).get(), "replaceWith" );
+} );
QUnit.test( "append HTML5 sectioning elements (Bug #6485)", function( assert ) {
@@ -452,75 +452,75 @@ QUnit.test( "append HTML5 sectioning elements (Bug #6485)", function( assert ) {
var article, aside;
- jQuery("#qunit-fixture").append("<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>");
+ jQuery( "#qunit-fixture" ).append( "<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>" );
- article = jQuery("article");
- aside = jQuery("aside");
+ article = jQuery( "article" );
+ aside = jQuery( "aside" );
assert.equal( article.get( 0 ).style.fontSize, "10px", "HTML5 elements are styleable" );
assert.equal( aside.length, 1, "HTML5 elements do not collapse their children" );
-});
+} );
if ( jQuery.css ) {
QUnit.test( "HTML5 Elements inherit styles from style rules (Bug #10501)", function( assert ) {
assert.expect( 1 );
- jQuery("#qunit-fixture").append("<article id='article'></article>");
- jQuery("#article").append("<section>This section should have a pink background.</section>");
+ jQuery( "#qunit-fixture" ).append( "<article id='article'></article>" );
+ jQuery( "#article" ).append( "<section>This section should have a pink background.</section>" );
// In IE, the missing background color will claim its value is "transparent"
- assert.notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles" );
- });
+ assert.notEqual( jQuery( "section" ).css( "background-color" ), "transparent", "HTML5 elements inherit styles" );
+ } );
}
QUnit.test( "html(String) with HTML5 (Bug #6485)", function( assert ) {
assert.expect( 2 );
- jQuery("#qunit-fixture").html("<article><section><aside>HTML5 elements</aside></section></article>");
- assert.equal( jQuery("#qunit-fixture").children().children().length, 1, "Make sure HTML5 article elements can hold children. innerHTML shortcut path" );
- assert.equal( jQuery("#qunit-fixture").children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." );
-});
+ jQuery( "#qunit-fixture" ).html( "<article><section><aside>HTML5 elements</aside></section></article>" );
+ assert.equal( jQuery( "#qunit-fixture" ).children().children().length, 1, "Make sure HTML5 article elements can hold children. innerHTML shortcut path" );
+ assert.equal( jQuery( "#qunit-fixture" ).children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." );
+} );
QUnit.test( "html(String) tag-hyphenated elements (Bug #1987)", function( assert ) {
assert.expect( 27 );
- jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) {
- var j = jQuery("<" + name + "-d></" + name + "-d><" + name + "-d></" + name + "-d>");
- assert.ok( j[0], "Create a tag-hyphenated element" );
- assert.ok( jQuery.nodeName(j[0], name.toUpperCase() + "-D"), "Hyphenated node name" );
- assert.ok( jQuery.nodeName(j[1], name.toUpperCase() + "-D"), "Hyphenated node name" );
- });
+ jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) {
+ var j = jQuery( "<" + name + "-d></" + name + "-d><" + name + "-d></" + name + "-d>" );
+ assert.ok( j[ 0 ], "Create a tag-hyphenated element" );
+ assert.ok( jQuery.nodeName( j[ 0 ], name.toUpperCase() + "-D" ), "Hyphenated node name" );
+ assert.ok( jQuery.nodeName( j[ 1 ], name.toUpperCase() + "-D" ), "Hyphenated node name" );
+ } );
- var j = jQuery("<tr-multiple-hyphens><td-with-hyphen>text</td-with-hyphen></tr-multiple-hyphens>");
- assert.ok( jQuery.nodeName(j[0], "TR-MULTIPLE-HYPHENS"), "Tags with multiple hypens" );
- assert.ok( jQuery.nodeName(j.children()[0], "TD-WITH-HYPHEN"), "Tags with multiple hypens" );
+ var j = jQuery( "<tr-multiple-hyphens><td-with-hyphen>text</td-with-hyphen></tr-multiple-hyphens>" );
+ assert.ok( jQuery.nodeName( j[ 0 ], "TR-MULTIPLE-HYPHENS" ), "Tags with multiple hypens" );
+ assert.ok( jQuery.nodeName( j.children()[ 0 ], "TD-WITH-HYPHEN" ), "Tags with multiple hypens" );
assert.equal( j.children().text(), "text", "Tags with multiple hypens behave normally" );
-});
+} );
QUnit.test( "IE8 serialization bug", function( assert ) {
assert.expect( 2 );
- var wrapper = jQuery("<div></div>");
+ var wrapper = jQuery( "<div></div>" );
- wrapper.html("<div></div><article></article>");
- assert.equal( wrapper.children("article").length, 1, "HTML5 elements are insertable with .html()" );
+ wrapper.html( "<div></div><article></article>" );
+ assert.equal( wrapper.children( "article" ).length, 1, "HTML5 elements are insertable with .html()" );
- wrapper.html("<div></div><link></link>");
- assert.equal( wrapper.children("link").length, 1, "Link elements are insertable with .html()" );
-});
+ wrapper.html( "<div></div><link></link>" );
+ assert.equal( wrapper.children( "link" ).length, 1, "Link elements are insertable with .html()" );
+} );
QUnit.test( "html() object element #10324", function( assert ) {
assert.expect( 1 );
- var object = jQuery("<object id='object2'><param name='object2test' value='test'></param></object>?").appendTo("#qunit-fixture"),
+ var object = jQuery( "<object id='object2'><param name='object2test' value='test'></param></object>?" ).appendTo( "#qunit-fixture" ),
clone = object.clone();
assert.equal( clone.html(), object.html(), "html() returns correct innerhtml of cloned object elements" );
-});
+} );
QUnit.test( "append(xml)", function( assert ) {
@@ -529,6 +529,7 @@ QUnit.test( "append(xml)", function( assert ) {
var xmlDoc, xml1, xml2;
function createXMLDoc() {
+
// Initialize DOM based upon latest installed MSXML or Netscape
var elem, n, len,
aActiveX =
@@ -541,23 +542,24 @@ QUnit.test( "append(xml)", function( assert ) {
if ( document.implementation && "createDocument" in document.implementation ) {
return document.implementation.createDocument( "", "", null );
} else {
+
// IE
for ( n = 0, len = aActiveX.length; n < len; n++ ) {
try {
elem = new ActiveXObject( aActiveX[ n ] );
return elem;
- } catch(_) {}
+ } catch ( _ ) {}
}
}
}
xmlDoc = createXMLDoc();
- xml1 = xmlDoc.createElement("head");
- xml2 = xmlDoc.createElement("test");
+ xml1 = xmlDoc.createElement( "head" );
+ xml2 = xmlDoc.createElement( "test" );
- assert.ok( jQuery(xml1).append(xml2), "Append an xml element to another without raising an exception." );
+ assert.ok( jQuery( xml1 ).append( xml2 ), "Append an xml element to another without raising an exception." );
-});
+} );
QUnit.test( "appendTo(String)", function( assert ) {
@@ -566,76 +568,76 @@ QUnit.test( "appendTo(String)", function( assert ) {
var l, defaultText;
defaultText = "Try them out:";
- jQuery("<b>buga</b>").appendTo("#first");
- assert.equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" );
- assert.equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" );
-
- l = jQuery("#first").children().length + 2;
- jQuery("<strong>test</strong>");
- jQuery("<strong>test</strong>");
- jQuery([ jQuery("<strong>test</strong>")[ 0 ], jQuery("<strong>test</strong>")[ 0 ] ])
- .appendTo("#first");
- assert.equal( jQuery("#first").children().length, l, "Make sure the elements were inserted." );
- assert.equal( jQuery("#first").children().last()[ 0 ].nodeName.toLowerCase(), "strong", "Verify the last element." );
-});
+ jQuery( "<b>buga</b>" ).appendTo( "#first" );
+ assert.equal( jQuery( "#first" ).text(), defaultText + "buga", "Check if text appending works" );
+ assert.equal( jQuery( "<option value='appendTest'>Append Test</option>" ).appendTo( "#select3" ).parent().find( "option:last-child" ).attr( "value" ), "appendTest", "Appending html options to select element" );
+
+ l = jQuery( "#first" ).children().length + 2;
+ jQuery( "<strong>test</strong>" );
+ jQuery( "<strong>test</strong>" );
+ jQuery( [ jQuery( "<strong>test</strong>" )[ 0 ], jQuery( "<strong>test</strong>" )[ 0 ] ] )
+ .appendTo( "#first" );
+ assert.equal( jQuery( "#first" ).children().length, l, "Make sure the elements were inserted." );
+ assert.equal( jQuery( "#first" ).children().last()[ 0 ].nodeName.toLowerCase(), "strong", "Verify the last element." );
+} );
QUnit.test( "appendTo(Element|Array<Element>)", function( assert ) {
assert.expect( 2 );
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
- jQuery( document.getElementById("first") ).appendTo("#sap");
- assert.equal( jQuery("#sap").text(), expected, "Check for appending of element" );
+ jQuery( document.getElementById( "first" ) ).appendTo( "#sap" );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of element" );
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
- jQuery([ document.getElementById("first"), document.getElementById("yahoo") ]).appendTo("#sap");
- assert.equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
+ jQuery( [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ] ).appendTo( "#sap" );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of array of elements" );
-});
+} );
QUnit.test( "appendTo(jQuery)", function( assert ) {
assert.expect( 10 );
var expected, num, div;
- assert.ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
+ assert.ok( jQuery( document.createElement( "script" ) ).appendTo( "body" ).length, "Make sure a disconnected script can be appended." );
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
- jQuery("#yahoo, #first").appendTo("#sap");
- assert.equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
+ jQuery( "#yahoo, #first" ).appendTo( "#sap" );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of jQuery object" );
- jQuery("#select1").appendTo("#foo");
+ jQuery( "#select1" ).appendTo( "#foo" );
t( "Append select", "#foo select", [ "select1" ] );
- div = jQuery("<div/>").on( "click", function() {
+ div = jQuery( "<div/>" ).on( "click", function() {
assert.ok( true, "Running a cloned click." );
- });
- div.appendTo("#qunit-fixture, #moretests");
+ } );
+ div.appendTo( "#qunit-fixture, #moretests" );
- jQuery("#qunit-fixture div").last().trigger("click");
- jQuery("#moretests div").last().trigger("click");
+ jQuery( "#qunit-fixture div" ).last().trigger( "click" );
+ jQuery( "#moretests div" ).last().trigger( "click" );
- div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");
+ div = jQuery( "<div/>" ).appendTo( "#qunit-fixture, #moretests" );
assert.equal( div.length, 2, "appendTo returns the inserted elements" );
- div.addClass("test");
+ div.addClass( "test" );
- assert.ok( jQuery("#qunit-fixture div").last().hasClass("test"), "appendTo element was modified after the insertion" );
- assert.ok( jQuery("#moretests div").last().hasClass("test"), "appendTo element was modified after the insertion" );
+ assert.ok( jQuery( "#qunit-fixture div" ).last().hasClass( "test" ), "appendTo element was modified after the insertion" );
+ assert.ok( jQuery( "#moretests div" ).last().hasClass( "test" ), "appendTo element was modified after the insertion" );
- div = jQuery("<div/>");
- jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
+ div = jQuery( "<div/>" );
+ jQuery( "<span>a</span><b>b</b>" ).filter( "span" ).appendTo( div );
assert.equal( div.children().length, 1, "Make sure the right number of children were inserted." );
- div = jQuery("#moretests div");
+ div = jQuery( "#moretests div" );
- num = jQuery("#qunit-fixture div").length;
- div.remove().appendTo("#qunit-fixture");
+ num = jQuery( "#qunit-fixture div" ).length;
+ div.remove().appendTo( "#qunit-fixture" );
- assert.equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );
-});
+ assert.equal( jQuery( "#qunit-fixture div" ).length, num, "Make sure all the removed divs were inserted." );
+} );
QUnit.test( "prepend(String)", function( assert ) {
@@ -643,10 +645,10 @@ QUnit.test( "prepend(String)", function( assert ) {
var result, expected;
expected = "Try them out:";
- result = jQuery("#first").prepend( "<b>buga</b>" );
+ result = jQuery( "#first" ).prepend( "<b>buga</b>" );
assert.equal( result.text(), "buga" + expected, "Check if text prepending works" );
- assert.equal( jQuery("#select3").prepend( "<option value='prependTest'>Prepend Test</option>" ).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" );
-});
+ assert.equal( jQuery( "#select3" ).prepend( "<option value='prependTest'>Prepend Test</option>" ).find( "option:first-child" ).attr( "value" ), "prependTest", "Prepending html options to select element" );
+} );
QUnit.test( "prepend(Element)", function( assert ) {
@@ -654,9 +656,9 @@ QUnit.test( "prepend(Element)", function( assert ) {
var expected;
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#sap").prepend( document.getElementById("first") );
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
-});
+ jQuery( "#sap" ).prepend( document.getElementById( "first" ) );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of element" );
+} );
QUnit.test( "prepend(Array<Element>)", function( assert ) {
@@ -664,9 +666,9 @@ QUnit.test( "prepend(Array<Element>)", function( assert ) {
var expected;
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#sap").prepend( [ document.getElementById("first"), document.getElementById("yahoo") ] );
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
-});
+ jQuery( "#sap" ).prepend( [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ] );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of elements" );
+} );
QUnit.test( "prepend(jQuery)", function( assert ) {
@@ -674,9 +676,9 @@ QUnit.test( "prepend(jQuery)", function( assert ) {
var expected;
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#sap").prepend( jQuery("#yahoo, #first") );
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
-});
+ jQuery( "#sap" ).prepend( jQuery( "#yahoo, #first" ) );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of jQuery object" );
+} );
QUnit.test( "prepend(Array<jQuery>)", function( assert ) {
@@ -684,9 +686,9 @@ QUnit.test( "prepend(Array<jQuery>)", function( assert ) {
var expected;
expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#sap").prepend( [ jQuery("#first"), jQuery("#yahoo, #google") ] );
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" );
-});
+ jQuery( "#sap" ).prepend( [ jQuery( "#first" ), jQuery( "#yahoo, #google" ) ] );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of jQuery objects" );
+} );
QUnit.test( "prepend(Function) with incoming value -- String", function( assert ) {
@@ -695,21 +697,21 @@ QUnit.test( "prepend(Function) with incoming value -- String", function( assert
var defaultText, old, result;
defaultText = "Try them out:";
- old = jQuery("#first").html();
- result = jQuery("#first").prepend(function( i, val ) {
+ old = jQuery( "#first" ).html();
+ result = jQuery( "#first" ).prepend( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
return "<b>buga</b>";
- });
+ } );
assert.equal( result.text(), "buga" + defaultText, "Check if text prepending works" );
- old = jQuery("#select3").html();
+ old = jQuery( "#select3" ).html();
- assert.equal( jQuery("#select3").prepend(function( i, val ) {
+ assert.equal( jQuery( "#select3" ).prepend( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
return "<option value='prependTest'>Prepend Test</option>";
- }).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" );
-});
+ } ).find( "option:first-child" ).attr( "value" ), "prependTest", "Prepending html options to select element" );
+} );
QUnit.test( "prepend(Function) with incoming value -- Element", function( assert ) {
@@ -717,15 +719,15 @@ QUnit.test( "prepend(Function) with incoming value -- Element", function( assert
var old, expected;
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
- old = jQuery("#sap").html();
+ old = jQuery( "#sap" ).html();
- jQuery("#sap").prepend(function( i, val ) {
+ jQuery( "#sap" ).prepend( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
- return document.getElementById("first");
- });
+ return document.getElementById( "first" );
+ } );
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
-});
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of element" );
+} );
QUnit.test( "prepend(Function) with incoming value -- Array<Element>", function( assert ) {
@@ -733,15 +735,15 @@ QUnit.test( "prepend(Function) with incoming value -- Array<Element>", function(
var old, expected;
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
- old = jQuery("#sap").html();
+ old = jQuery( "#sap" ).html();
- jQuery("#sap").prepend(function( i, val ) {
+ jQuery( "#sap" ).prepend( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
- return [ document.getElementById("first"), document.getElementById("yahoo") ];
- });
+ return [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ];
+ } );
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
-});
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of elements" );
+} );
QUnit.test( "prepend(Function) with incoming value -- jQuery", function( assert ) {
@@ -749,15 +751,15 @@ QUnit.test( "prepend(Function) with incoming value -- jQuery", function( assert
var old, expected;
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
- old = jQuery("#sap").html();
+ old = jQuery( "#sap" ).html();
- jQuery("#sap").prepend(function( i, val ) {
+ jQuery( "#sap" ).prepend( function( i, val ) {
assert.equal( val, old, "Make sure the incoming value is correct." );
- return jQuery("#yahoo, #first");
- });
+ return jQuery( "#yahoo, #first" );
+ } );
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
-});
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of jQuery object" );
+} );
QUnit.test( "prependTo(String)", function( assert ) {
@@ -766,11 +768,11 @@ QUnit.test( "prependTo(String)", function( assert ) {
var defaultText;
defaultText = "Try them out:";
- jQuery("<b>buga</b>").prependTo("#first");
- assert.equal( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" );
- assert.equal( jQuery("<option value='prependTest'>Prepend Test</option>").prependTo("#select3").parent().find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" );
+ jQuery( "<b>buga</b>" ).prependTo( "#first" );
+ assert.equal( jQuery( "#first" ).text(), "buga" + defaultText, "Check if text prepending works" );
+ assert.equal( jQuery( "<option value='prependTest'>Prepend Test</option>" ).prependTo( "#select3" ).parent().find( "option:first-child" ).attr( "value" ), "prependTest", "Prepending html options to select element" );
-});
+} );
QUnit.test( "prependTo(Element)", function( assert ) {
@@ -779,9 +781,9 @@ QUnit.test( "prependTo(Element)", function( assert ) {
var expected;
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
- jQuery( document.getElementById("first") ).prependTo("#sap");
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
-});
+ jQuery( document.getElementById( "first" ) ).prependTo( "#sap" );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of element" );
+} );
QUnit.test( "prependTo(Array<Element>)", function( assert ) {
@@ -790,9 +792,9 @@ QUnit.test( "prependTo(Array<Element>)", function( assert ) {
var expected;
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
- jQuery( [ document.getElementById("first"), document.getElementById("yahoo") ] ).prependTo("#sap");
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
-});
+ jQuery( [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ] ).prependTo( "#sap" );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of elements" );
+} );
QUnit.test( "prependTo(jQuery)", function( assert ) {
@@ -801,19 +803,19 @@ QUnit.test( "prependTo(jQuery)", function( assert ) {
var expected;
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#yahoo, #first").prependTo("#sap");
- assert.equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
-});
+ jQuery( "#yahoo, #first" ).prependTo( "#sap" );
+ assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of jQuery object" );
+} );
QUnit.test( "prependTo(Array<jQuery>)", function( assert ) {
assert.expect( 1 );
- jQuery("<select id='prependSelect1'></select>").prependTo("#form");
- jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("#form");
+ jQuery( "<select id='prependSelect1'></select>" ).prependTo( "#form" );
+ jQuery( "<select id='prependSelect2'><option>Test</option></select>" ).prependTo( "#form" );
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
-});
+} );
QUnit.test( "before(String)", function( assert ) {
@@ -822,9 +824,9 @@ QUnit.test( "before(String)", function( assert ) {
var expected;
expected = "This is a normal link: bugaYahoo";
- jQuery("#yahoo").before( manipulationBareObj("<b>buga</b>") );
- assert.equal( jQuery("#en").text(), expected, "Insert String before" );
-});
+ jQuery( "#yahoo" ).before( manipulationBareObj( "<b>buga</b>" ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert String before" );
+} );
QUnit.test( "before(Element)", function( assert ) {
@@ -833,9 +835,9 @@ QUnit.test( "before(Element)", function( assert ) {
var expected;
expected = "This is a normal link: Try them out:Yahoo";
- jQuery("#yahoo").before( manipulationBareObj(document.getElementById("first")) );
- assert.equal( jQuery("#en").text(), expected, "Insert element before" );
-});
+ jQuery( "#yahoo" ).before( manipulationBareObj( document.getElementById( "first" ) ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert element before" );
+} );
QUnit.test( "before(Array<Element>)", function( assert ) {
@@ -843,9 +845,9 @@ QUnit.test( "before(Array<Element>)", function( assert ) {
var expected;
expected = "This is a normal link: Try them out:diveintomarkYahoo";
- jQuery("#yahoo").before( manipulationBareObj([ document.getElementById("first"), document.getElementById("mark") ]) );
- assert.equal( jQuery("#en").text(), expected, "Insert array of elements before" );
-});
+ jQuery( "#yahoo" ).before( manipulationBareObj( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements before" );
+} );
QUnit.test( "before(jQuery)", function( assert ) {
@@ -853,9 +855,9 @@ QUnit.test( "before(jQuery)", function( assert ) {
var expected;
expected = "This is a normal link: diveintomarkTry them out:Yahoo";
- jQuery("#yahoo").before( manipulationBareObj(jQuery("#mark, #first")) );
- assert.equal( jQuery("#en").text(), expected, "Insert jQuery before" );
-});
+ jQuery( "#yahoo" ).before( manipulationBareObj( jQuery( "#mark, #first" ) ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery before" );
+} );
QUnit.test( "before(Array<jQuery>)", function( assert ) {
@@ -863,9 +865,9 @@ QUnit.test( "before(Array<jQuery>)", function( assert ) {
var expected;
expected = "This is a normal link: Try them out:GooglediveintomarkYahoo";
- jQuery("#yahoo").before( manipulationBareObj([ jQuery("#first"), jQuery("#mark, #google") ]) );
- assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects before" );
-});
+ jQuery( "#yahoo" ).before( manipulationBareObj( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects before" );
+} );
QUnit.test( "before(Function) -- Returns String", function( assert ) {
@@ -874,9 +876,9 @@ QUnit.test( "before(Function) -- Returns String", function( assert ) {
var expected;
expected = "This is a normal link: bugaYahoo";
- jQuery("#yahoo").before( manipulationFunctionReturningObj("<b>buga</b>") );
- assert.equal( jQuery("#en").text(), expected, "Insert String before" );
-});
+ jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( "<b>buga</b>" ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert String before" );
+} );
QUnit.test( "before(Function) -- Returns Element", function( assert ) {
@@ -885,9 +887,9 @@ QUnit.test( "before(Function) -- Returns Element", function( assert ) {
var expected;
expected = "This is a normal link: Try them out:Yahoo";
- jQuery("#yahoo").before( manipulationFunctionReturningObj(document.getElementById("first")) );
- assert.equal( jQuery("#en").text(), expected, "Insert element before" );
-});
+ jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( document.getElementById( "first" ) ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert element before" );
+} );
QUnit.test( "before(Function) -- Returns Array<Element>", function( assert ) {
@@ -895,9 +897,9 @@ QUnit.test( "before(Function) -- Returns Array<Element>", function( assert ) {
var expected;
expected = "This is a normal link: Try them out:diveintomarkYahoo";
- jQuery("#yahoo").before( manipulationFunctionReturningObj([ document.getElementById("first"), document.getElementById("mark") ]) );
- assert.equal( jQuery("#en").text(), expected, "Insert array of elements before" );
-});
+ jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements before" );
+} );
QUnit.test( "before(Function) -- Returns jQuery", function( assert ) {
@@ -905,9 +907,9 @@ QUnit.test( "before(Function) -- Returns jQuery", function( assert ) {
var expected;
expected = "This is a normal link: diveintomarkTry them out:Yahoo";
- jQuery("#yahoo").before( manipulationFunctionReturningObj(jQuery("#mark, #first")) );
- assert.equal( jQuery("#en").text(), expected, "Insert jQuery before" );
-});
+ jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( jQuery( "#mark, #first" ) ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery before" );
+} );
QUnit.test( "before(Function) -- Returns Array<jQuery>", function( assert ) {
@@ -915,19 +917,19 @@ QUnit.test( "before(Function) -- Returns Array<jQuery>", function( assert ) {
var expected;
expected = "This is a normal link: Try them out:GooglediveintomarkYahoo";
- jQuery("#yahoo").before( manipulationFunctionReturningObj([ jQuery("#first"), jQuery("#mark, #google") ]) );
- assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects before" );
-});
+ jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects before" );
+} );
QUnit.test( "before(no-op)", function( assert ) {
assert.expect( 2 );
var set;
- set = jQuery("<div/>").before("<span>test</span>");
+ set = jQuery( "<div/>" ).before( "<span>test</span>" );
assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert before a disconnected node should be a no-op" );
assert.equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" );
-});
+} );
QUnit.test( "before and after w/ empty object (#10812)", function( assert ) {
@@ -937,127 +939,127 @@ QUnit.test( "before and after w/ empty object (#10812)", function( assert ) {
res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" );
assert.equal( res.length, 0, "didn't choke on empty object" );
-});
+} );
QUnit.test( ".before() and .after() disconnected node", function( assert ) {
- assert.expect(2);
+ assert.expect( 2 );
- assert.equal( jQuery("<input type='checkbox'/>").before("<div/>").length, 1, "before() on disconnected node is no-op" );
- assert.equal( jQuery("<input type='checkbox'/>").after("<div/>").length, 1, "after() on disconnected node is no-op" );
-});
+ assert.equal( jQuery( "<input type='checkbox'/>" ).before( "<div/>" ).length, 1, "before() on disconnected node is no-op" );
+ assert.equal( jQuery( "<input type='checkbox'/>" ).after( "<div/>" ).length, 1, "after() on disconnected node is no-op" );
+} );
QUnit.test( "insert with .before() on disconnected node last", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var expectedBefore = "This is a normal link: bugaYahoo";
- jQuery("#yahoo").add("<span/>").before("<b>buga</b>");
- assert.equal( jQuery("#en").text(), expectedBefore, "Insert String before with disconnected node last" );
-});
+ jQuery( "#yahoo" ).add( "<span/>" ).before( "<b>buga</b>" );
+ assert.equal( jQuery( "#en" ).text(), expectedBefore, "Insert String before with disconnected node last" );
+} );
QUnit.test( "insert with .before() on disconnected node first", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var expectedBefore = "This is a normal link: bugaYahoo";
- jQuery("<span/>").add("#yahoo").before("<b>buga</b>");
- assert.equal( jQuery("#en").text(), expectedBefore, "Insert String before with disconnected node first" );
-});
+ jQuery( "<span/>" ).add( "#yahoo" ).before( "<b>buga</b>" );
+ assert.equal( jQuery( "#en" ).text(), expectedBefore, "Insert String before with disconnected node first" );
+} );
QUnit.test( "insert with .before() on disconnected node last", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var expectedAfter = "This is a normal link: Yahoobuga";
- jQuery("#yahoo").add("<span/>").after("<b>buga</b>");
- assert.equal( jQuery("#en").text(), expectedAfter, "Insert String after with disconnected node last" );
-});
+ jQuery( "#yahoo" ).add( "<span/>" ).after( "<b>buga</b>" );
+ assert.equal( jQuery( "#en" ).text(), expectedAfter, "Insert String after with disconnected node last" );
+} );
QUnit.test( "insert with .before() on disconnected node last", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var expectedAfter = "This is a normal link: Yahoobuga";
- jQuery("<span/>").add("#yahoo").after("<b>buga</b>");
- assert.equal( jQuery("#en").text(), expectedAfter, "Insert String after with disconnected node first" );
-});
+ jQuery( "<span/>" ).add( "#yahoo" ).after( "<b>buga</b>" );
+ assert.equal( jQuery( "#en" ).text(), expectedAfter, "Insert String after with disconnected node first" );
+} );
QUnit.test( "insertBefore(String)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: bugaYahoo";
- jQuery("<b>buga</b>").insertBefore("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert String before" );
-});
+ jQuery( "<b>buga</b>" ).insertBefore( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert String before" );
+} );
QUnit.test( "insertBefore(Element)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: Try them out:Yahoo";
- jQuery( document.getElementById("first") ).insertBefore("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert element before" );
-});
+ jQuery( document.getElementById( "first" ) ).insertBefore( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert element before" );
+} );
QUnit.test( "insertBefore(Array<Element>)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: Try them out:diveintomarkYahoo";
- jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).insertBefore("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert array of elements before" );
-});
+ jQuery( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ).insertBefore( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements before" );
+} );
QUnit.test( "insertBefore(jQuery)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: diveintomarkTry them out:Yahoo";
- jQuery("#mark, #first").insertBefore("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert jQuery before" );
-});
+ jQuery( "#mark, #first" ).insertBefore( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery before" );
+} );
QUnit.test( ".after(String)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: Yahoobuga";
- jQuery("#yahoo").after( "<b>buga</b>" );
- assert.equal( jQuery("#en").text(), expected, "Insert String after" );
-});
+ jQuery( "#yahoo" ).after( "<b>buga</b>" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert String after" );
+} );
QUnit.test( ".after(Element)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: YahooTry them out:";
- jQuery("#yahoo").after( document.getElementById("first") );
- assert.equal( jQuery("#en").text(), expected, "Insert element after" );
-});
+ jQuery( "#yahoo" ).after( document.getElementById( "first" ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert element after" );
+} );
QUnit.test( ".after(Array<Element>)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: YahooTry them out:diveintomark";
- jQuery("#yahoo").after( [ document.getElementById("first"), document.getElementById("mark") ] );
- assert.equal( jQuery("#en").text(), expected, "Insert array of elements after" );
-});
+ jQuery( "#yahoo" ).after( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements after" );
+} );
QUnit.test( ".after(jQuery)", function( assert ) {
assert.expect( 1 );
var expected = "This is a normal link: YahooTry them out:Googlediveintomark";
- jQuery("#yahoo").after( [ jQuery("#first"), jQuery("#mark, #google") ] );
- assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects after" );
-});
+ jQuery( "#yahoo" ).after( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects after" );
+} );
QUnit.test( ".after(Function) returns String", function( assert ) {
@@ -1065,9 +1067,9 @@ QUnit.test( ".after(Function) returns String", function( assert ) {
var expected = "This is a normal link: Yahoobuga",
val = manipulationFunctionReturningObj;
- jQuery("#yahoo").after( val("<b>buga</b>") );
- assert.equal( jQuery("#en").text(), expected, "Insert String after" );
-});
+ jQuery( "#yahoo" ).after( val( "<b>buga</b>" ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert String after" );
+} );
QUnit.test( ".after(Function) returns Element", function( assert ) {
@@ -1075,9 +1077,9 @@ QUnit.test( ".after(Function) returns Element", function( assert ) {
var expected = "This is a normal link: YahooTry them out:",
val = manipulationFunctionReturningObj;
- jQuery("#yahoo").after( val(document.getElementById("first")) );
- assert.equal( jQuery("#en").text(), expected, "Insert element after" );
-});
+ jQuery( "#yahoo" ).after( val( document.getElementById( "first" ) ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert element after" );
+} );
QUnit.test( ".after(Function) returns Array<Element>", function( assert ) {
@@ -1085,9 +1087,9 @@ QUnit.test( ".after(Function) returns Array<Element>", function( assert ) {
var expected = "This is a normal link: YahooTry them out:diveintomark",
val = manipulationFunctionReturningObj;
- jQuery("#yahoo").after( val([ document.getElementById("first"), document.getElementById("mark") ]) );
- assert.equal( jQuery("#en").text(), expected, "Insert array of elements after" );
-});
+ jQuery( "#yahoo" ).after( val( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements after" );
+} );
QUnit.test( ".after(Function) returns jQuery", function( assert ) {
@@ -1095,54 +1097,54 @@ QUnit.test( ".after(Function) returns jQuery", function( assert ) {
var expected = "This is a normal link: YahooTry them out:Googlediveintomark",
val = manipulationFunctionReturningObj;
- jQuery("#yahoo").after( val([ jQuery("#first"), jQuery("#mark, #google") ]) );
- assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects after" );
-});
+ jQuery( "#yahoo" ).after( val( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] ) );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects after" );
+} );
QUnit.test( ".after(disconnected node)", function( assert ) {
assert.expect( 2 );
- var set = jQuery("<div/>").before("<span>test</span>");
+ var set = jQuery( "<div/>" ).before( "<span>test</span>" );
assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert after a disconnected node should be a no-op" );
assert.equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" );
-});
+} );
QUnit.test( "insertAfter(String)", function( assert ) {
assert.expect( 1 ) ;
var expected = "This is a normal link: Yahoobuga";
- jQuery("<b>buga</b>").insertAfter("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert String after" );
-});
+ jQuery( "<b>buga</b>" ).insertAfter( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert String after" );
+} );
QUnit.test( "insertAfter(Element)", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var expected = "This is a normal link: YahooTry them out:";
- jQuery( document.getElementById("first") ).insertAfter("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert element after" );
-});
+ jQuery( document.getElementById( "first" ) ).insertAfter( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert element after" );
+} );
QUnit.test( "insertAfter(Array<Element>)", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var expected = "This is a normal link: YahooTry them out:diveintomark";
- jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).insertAfter("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert array of elements after" );
-});
+ jQuery( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ).insertAfter( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements after" );
+} );
QUnit.test( "insertAfter(jQuery)", function( assert ) {
- assert.expect(1);
+ assert.expect( 1 );
var expected = "This is a normal link: YahoodiveintomarkTry them out:";
- jQuery("#mark, #first").insertAfter("#yahoo");
- assert.equal( jQuery("#en").text(), expected, "Insert jQuery after" );
-});
+ jQuery( "#mark, #first" ).insertAfter( "#yahoo" );
+ assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery after" );
+} );
function testReplaceWith( val, assert ) {
@@ -1151,132 +1153,127 @@ function testReplaceWith( val, assert ) {
assert.expect( expected );
- jQuery("#yahoo").replaceWith( val("<b id='replace'>buga</b>") );
- assert.ok( jQuery("#replace")[ 0 ], "Replace element with element from string" );
- assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after string" );
+ jQuery( "#yahoo" ).replaceWith( val( "<b id='replace'>buga</b>" ) );
+ assert.ok( jQuery( "#replace" )[ 0 ], "Replace element with element from string" );
+ assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after string" );
- jQuery("#anchor2").replaceWith( val(document.getElementById("first")) );
- assert.ok( jQuery("#first")[ 0 ], "Replace element with element" );
- assert.ok( !jQuery("#anchor2")[ 0 ], "Verify that original element is gone, after element" );
+ jQuery( "#anchor2" ).replaceWith( val( document.getElementById( "first" ) ) );
+ assert.ok( jQuery( "#first" )[ 0 ], "Replace element with element" );
+ assert.ok( !jQuery( "#anchor2" )[ 0 ], "Verify that original element is gone, after element" );
- jQuery("#qunit-fixture").append("<div id='bar'><div id='baz'></div></div>");
- jQuery("#baz").replaceWith( val("Baz") );
- assert.equal( jQuery("#bar").text(),"Baz", "Replace element with text" );
- assert.ok( !jQuery("#baz")[ 0 ], "Verify that original element is gone, after element" );
+ jQuery( "#qunit-fixture" ).append( "<div id='bar'><div id='baz'></div></div>" );
+ jQuery( "#baz" ).replaceWith( val( "Baz" ) );
+ assert.equal( jQuery( "#bar" ).text(), "Baz", "Replace element with text" );
+ assert.ok( !jQuery( "#baz" )[ 0 ], "Verify that original element is gone, after element" );
- jQuery("#bar").replaceWith( "<div id='yahoo'></div>", "...", "<div id='baz'></div>" );
- assert.deepEqual( jQuery("#yahoo, #baz").get(), q( "yahoo", "baz" ), "Replace element with multiple arguments (#13722)" );
- assert.strictEqual( jQuery("#yahoo")[0].nextSibling, jQuery("#baz")[0].previousSibling, "Argument order preserved" );
- assert.deepEqual( jQuery("#bar").get(), [], "Verify that original element is gone, after multiple arguments" );
+ jQuery( "#bar" ).replaceWith( "<div id='yahoo'></div>", "...", "<div id='baz'></div>" );
+ assert.deepEqual( jQuery( "#yahoo, #baz" ).get(), q( "yahoo", "baz" ), "Replace element with multiple arguments (#13722)" );
+ assert.strictEqual( jQuery( "#yahoo" )[ 0 ].nextSibling, jQuery( "#baz" )[ 0 ].previousSibling, "Argument order preserved" );
+ assert.deepEqual( jQuery( "#bar" ).get(), [], "Verify that original element is gone, after multiple arguments" );
- jQuery("#google").replaceWith( val([ document.getElementById("first"), document.getElementById("mark") ]) );
- assert.deepEqual( jQuery("#mark, #first").get(), q( "first", "mark" ), "Replace element with array of elements" );
- assert.ok( !jQuery("#google")[ 0 ], "Verify that original element is gone, after array of elements" );
+ jQuery( "#google" ).replaceWith( val( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) );
+ assert.deepEqual( jQuery( "#mark, #first" ).get(), q( "first", "mark" ), "Replace element with array of elements" );
+ assert.ok( !jQuery( "#google" )[ 0 ], "Verify that original element is gone, after array of elements" );
- jQuery("#groups").replaceWith( val(jQuery("#mark, #first")) );
- assert.deepEqual( jQuery("#mark, #first").get(), q( "first", "mark" ), "Replace element with jQuery collection" );
- assert.ok( !jQuery("#groups")[ 0 ], "Verify that original element is gone, after jQuery collection" );
+ jQuery( "#groups" ).replaceWith( val( jQuery( "#mark, #first" ) ) );
+ assert.deepEqual( jQuery( "#mark, #first" ).get(), q( "first", "mark" ), "Replace element with jQuery collection" );
+ assert.ok( !jQuery( "#groups" )[ 0 ], "Verify that original element is gone, after jQuery collection" );
- jQuery("#mark, #first").replaceWith( val("<span class='replacement'></span><span class='replacement'></span>") );
- assert.equal( jQuery("#qunit-fixture .replacement").length, 4, "Replace multiple elements (#12449)" );
- assert.deepEqual( jQuery("#mark, #first").get(), [], "Verify that original elements are gone, after replace multiple" );
+ jQuery( "#mark, #first" ).replaceWith( val( "<span class='replacement'></span><span class='replacement'></span>" ) );
+ assert.equal( jQuery( "#qunit-fixture .replacement" ).length, 4, "Replace multiple elements (#12449)" );
+ assert.deepEqual( jQuery( "#mark, #first" ).get(), [], "Verify that original elements are gone, after replace multiple" );
- tmp = jQuery("<b>content</b>")[0];
- jQuery("#anchor1").contents().replaceWith( val(tmp) );
- assert.deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" );
+ tmp = jQuery( "<b>content</b>" )[ 0 ];
+ jQuery( "#anchor1" ).contents().replaceWith( val( tmp ) );
+ assert.deepEqual( jQuery( "#anchor1" ).contents().get(), [ tmp ], "Replace text node with element" );
-
- tmp = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
+ tmp = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( true, "Newly bound click run." );
- });
- y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
+ } );
+ y = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( false, "Previously bound click run." );
- });
- child = y.append("<b>test</b>").find("b").on( "click", function() {
+ } );
+ child = y.append( "<b>test</b>" ).find( "b" ).on( "click", function() {
assert.ok( true, "Child bound click run." );
return false;
- });
-
- y.replaceWith( val(tmp) );
+ } );
- tmp.trigger("click");
- y.trigger("click"); // Shouldn't be run
- child.trigger("click"); // Shouldn't be run
+ y.replaceWith( val( tmp ) );
+ tmp.trigger( "click" );
+ y.trigger( "click" ); // Shouldn't be run
+ child.trigger( "click" ); // Shouldn't be run
- y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
+ y = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( false, "Previously bound click run." );
- });
- child2 = y.append("<u>test</u>").find("u").on( "click", function() {
+ } );
+ child2 = y.append( "<u>test</u>" ).find( "u" ).on( "click", function() {
assert.ok( true, "Child 2 bound click run." );
return false;
- });
-
- y.replaceWith( val(child2) );
+ } );
- child2.trigger("click");
+ y.replaceWith( val( child2 ) );
+ child2.trigger( "click" );
- set = jQuery("<div/>").replaceWith( val("<span>test</span>") );
- assert.equal( set[0].nodeName.toLowerCase(), "div", "No effect on a disconnected node." );
+ set = jQuery( "<div/>" ).replaceWith( val( "<span>test</span>" ) );
+ assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "No effect on a disconnected node." );
assert.equal( set.length, 1, "No effect on a disconnected node." );
- assert.equal( set[0].childNodes.length, 0, "No effect on a disconnected node." );
-
+ assert.equal( set[ 0 ].childNodes.length, 0, "No effect on a disconnected node." );
- child = jQuery("#qunit-fixture").children().first();
- $div = jQuery("<div class='pathological'/>").insertBefore( child );
+ child = jQuery( "#qunit-fixture" ).children().first();
+ $div = jQuery( "<div class='pathological'/>" ).insertBefore( child );
$div.replaceWith( $div );
assert.deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), $div.get(),
"Self-replacement" );
$div.replaceWith( child );
- assert.deepEqual( jQuery("#qunit-fixture").children().first().get(), child.get(),
+ assert.deepEqual( jQuery( "#qunit-fixture" ).children().first().get(), child.get(),
"Replacement with following sibling (#13810)" );
assert.deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), [],
"Replacement with following sibling (context removed)" );
-
- non_existent = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") );
+ non_existent = jQuery( "#does-not-exist" ).replaceWith( val( "<b>should not throw an error</b>" ) );
assert.equal( non_existent.length, 0, "Length of non existent element." );
- $div = jQuery("<div class='replacewith'></div>").appendTo("#qunit-fixture");
- $div.replaceWith( val("<div class='replacewith'></div><script>" +
+ $div = jQuery( "<div class='replacewith'></div>" ).appendTo( "#qunit-fixture" );
+ $div.replaceWith( val( "<div class='replacewith'></div><script>" +
"equal( jQuery('.replacewith').length, 1, 'Check number of elements in page.' );" +
- "</script>") );
+ "</script>" ) );
- jQuery("#qunit-fixture").append("<div id='replaceWith'></div>");
- assert.equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
- jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
- assert.equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after replacement." );
- jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
- assert.equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after subsequent replacement." );
+ jQuery( "#qunit-fixture" ).append( "<div id='replaceWith'></div>" );
+ assert.equal( jQuery( "#qunit-fixture" ).find( "div[id=replaceWith]" ).length, 1, "Make sure only one div exists." );
+ jQuery( "#replaceWith" ).replaceWith( val( "<div id='replaceWith'></div>" ) );
+ assert.equal( jQuery( "#qunit-fixture" ).find( "div[id=replaceWith]" ).length, 1, "Make sure only one div exists after replacement." );
+ jQuery( "#replaceWith" ).replaceWith( val( "<div id='replaceWith'></div>" ) );
+ assert.equal( jQuery( "#qunit-fixture" ).find( "div[id=replaceWith]" ).length, 1, "Make sure only one div exists after subsequent replacement." );
return expected;
}
QUnit.test( "replaceWith(String|Element|Array<Element>|jQuery)", function( assert ) {
testReplaceWith( manipulationBareObj, assert );
-});
+} );
QUnit.test( "replaceWith(Function)", function( assert ) {
- assert.expect( testReplaceWith(manipulationFunctionReturningObj, assert ) + 1 );
+ assert.expect( testReplaceWith( manipulationFunctionReturningObj, assert ) + 1 );
- var y = jQuery("#foo")[ 0 ];
+ var y = jQuery( "#foo" )[ 0 ];
- jQuery( y ).replaceWith(function() {
+ jQuery( y ).replaceWith( function() {
assert.equal( this, y, "Make sure the context is coming in correctly." );
- });
-});
+ } );
+} );
QUnit.test( "replaceWith(string) for more than one element", function( assert ) {
assert.expect( 3 );
- assert.equal( jQuery("#foo p").length, 3, "ensuring that test data has not changed" );
+ assert.equal( jQuery( "#foo p" ).length, 3, "ensuring that test data has not changed" );
- jQuery("#foo p").replaceWith("<span>bar</span>");
- assert.equal(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced");
- assert.equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced");
-});
+ jQuery( "#foo p" ).replaceWith( "<span>bar</span>" );
+ assert.equal( jQuery( "#foo span" ).length, 3, "verify that all the three original element have been replaced" );
+ assert.equal( jQuery( "#foo p" ).length, 0, "verify that all the three original element have been replaced" );
+} );
QUnit.test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function( assert ) {
@@ -1297,97 +1294,97 @@ QUnit.test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function( ass
jQuery.each( tests, function( label, input ) {
$el.html( "<a/>" ).children().replaceWith( input );
assert.strictEqual( $el.html(), "", "replaceWith(" + label + ")" );
- $el.html( "<b/>" ).children().replaceWith(function() { return input; });
+ $el.html( "<b/>" ).children().replaceWith( function() { return input; } );
assert.strictEqual( $el.html(), "", "replaceWith(function returning " + label + ")" );
- $el.html( "<i/>" ).children().replaceWith(function( i ) { i; return input; });
+ $el.html( "<i/>" ).children().replaceWith( function( i ) { i; return input; } );
assert.strictEqual( $el.html(), "", "replaceWith(other function returning " + label + ")" );
- $el.html( "<p/>" ).children().replaceWith(function( i ) {
+ $el.html( "<p/>" ).children().replaceWith( function( i ) {
return i ?
input :
jQuery( this ).html( i + "" );
- });
+ } );
assert.strictEqual( $el.eq( 0 ).html(), expectedHTML,
"replaceWith(function conditionally returning context)" );
assert.strictEqual( $el.eq( 1 ).html(), "",
"replaceWith(function conditionally returning " + label + ")" );
- });
-});
+ } );
+} );
QUnit.test( "replaceAll(String)", function( assert ) {
assert.expect( 2 );
- jQuery("<b id='replace'>buga</b>").replaceAll("#yahoo");
- assert.ok( jQuery("#replace")[ 0 ], "Replace element with string" );
- assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after string" );
-});
+ jQuery( "<b id='replace'>buga</b>" ).replaceAll( "#yahoo" );
+ assert.ok( jQuery( "#replace" )[ 0 ], "Replace element with string" );
+ assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after string" );
+} );
QUnit.test( "replaceAll(Element)", function( assert ) {
assert.expect( 2 );
- jQuery( document.getElementById("first") ).replaceAll("#yahoo");
- assert.ok( jQuery("#first")[ 0 ], "Replace element with element" );
- assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after element" );
-});
+ jQuery( document.getElementById( "first" ) ).replaceAll( "#yahoo" );
+ assert.ok( jQuery( "#first" )[ 0 ], "Replace element with element" );
+ assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after element" );
+} );
QUnit.test( "replaceAll(Array<Element>)", function( assert ) {
assert.expect( 3 );
- jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).replaceAll("#yahoo");
- assert.ok( jQuery("#first")[ 0 ], "Replace element with array of elements" );
- assert.ok( jQuery("#mark")[ 0 ], "Replace element with array of elements" );
- assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after array of elements" );
-});
+ jQuery( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ).replaceAll( "#yahoo" );
+ assert.ok( jQuery( "#first" )[ 0 ], "Replace element with array of elements" );
+ assert.ok( jQuery( "#mark" )[ 0 ], "Replace element with array of elements" );
+ assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after array of elements" );
+} );
QUnit.test( "replaceAll(jQuery)", function( assert ) {
assert.expect( 3 );
- jQuery("#mark, #first").replaceAll("#yahoo");
- assert.ok( jQuery("#first")[ 0 ], "Replace element with set of elements" );
- assert.ok( jQuery("#mark")[ 0 ], "Replace element with set of elements" );
- assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after set of elements" );
-});
+ jQuery( "#mark, #first" ).replaceAll( "#yahoo" );
+ assert.ok( jQuery( "#first" )[ 0 ], "Replace element with set of elements" );
+ assert.ok( jQuery( "#mark" )[ 0 ], "Replace element with set of elements" );
+ assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after set of elements" );
+} );
QUnit.test( "jQuery.clone() (#8017)", function( assert ) {
assert.expect( 2 );
- assert.ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function.");
+ assert.ok( jQuery.clone && jQuery.isFunction( jQuery.clone ), "jQuery.clone() utility exists and is a function." );
- var main = jQuery("#qunit-fixture")[ 0 ],
+ var main = jQuery( "#qunit-fixture" )[ 0 ],
clone = jQuery.clone( main );
assert.equal( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
-});
+} );
QUnit.test( "append to multiple elements (#8070)", function( assert ) {
assert.expect( 2 );
- var selects = jQuery("<select class='test8070'></select><select class='test8070'></select>").appendTo("#qunit-fixture");
- selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>");
+ var selects = jQuery( "<select class='test8070'></select><select class='test8070'></select>" ).appendTo( "#qunit-fixture" );
+ selects.append( "<OPTION>1</OPTION><OPTION>2</OPTION>" );
assert.equal( selects[ 0 ].childNodes.length, 2, "First select got two nodes" );
assert.equal( selects[ 1 ].childNodes.length, 2, "Second select got two nodes" );
-});
+} );
QUnit.test( "table manipulation", function( assert ) {
assert.expect( 2 );
- var table = jQuery("<table style='font-size:16px'></table>").appendTo("#qunit-fixture").empty(),
- height = table[0].offsetHeight;
+ var table = jQuery( "<table style='font-size:16px'></table>" ).appendTo( "#qunit-fixture" ).empty(),
+ height = table[ 0 ].offsetHeight;
- table.append("<tr><td>DATA</td></tr>");
- assert.ok( table[0].offsetHeight - height >= 15, "appended rows are visible" );
+ table.append( "<tr><td>DATA</td></tr>" );
+ assert.ok( table[ 0 ].offsetHeight - height >= 15, "appended rows are visible" );
table.empty();
- height = table[0].offsetHeight;
- table.prepend("<tr><td>DATA</td></tr>");
- assert.ok( table[0].offsetHeight - height >= 15, "prepended rows are visible" );
-});
+ height = table[ 0 ].offsetHeight;
+ table.prepend( "<tr><td>DATA</td></tr>" );
+ assert.ok( table[ 0 ].offsetHeight - height >= 15, "prepended rows are visible" );
+} );
QUnit.test( "clone()", function( assert ) {
@@ -1395,61 +1392,61 @@ QUnit.test( "clone()", function( assert ) {
var div, clone, form, body;
- assert.equal( jQuery("#en").text(), "This is a normal link: Yahoo", "Assert text for #en" );
- assert.equal( jQuery("#first").append( jQuery("#yahoo").clone() ).text(), "Try them out:Yahoo", "Check for clone" );
- assert.equal( jQuery("#en").text(), "This is a normal link: Yahoo", "Reassert text for #en" );
+ assert.equal( jQuery( "#en" ).text(), "This is a normal link: Yahoo", "Assert text for #en" );
+ assert.equal( jQuery( "#first" ).append( jQuery( "#yahoo" ).clone() ).text(), "Try them out:Yahoo", "Check for clone" );
+ assert.equal( jQuery( "#en" ).text(), "This is a normal link: Yahoo", "Reassert text for #en" );
- jQuery.each( "table thead tbody tfoot tr td div button ul ol li select option textarea iframe".split(" "), function( i, nodeName ) {
+ jQuery.each( "table thead tbody tfoot tr td div button ul ol li select option textarea iframe".split( " " ), function( i, nodeName ) {
assert.equal( jQuery( "<" + nodeName + "/>" ).clone()[ 0 ].nodeName.toLowerCase(), nodeName, "Clone a " + nodeName );
- });
- assert.equal( jQuery("<input type='checkbox' />").clone()[ 0 ].nodeName.toLowerCase(), "input", "Clone a <input type='checkbox' />" );
+ } );
+ assert.equal( jQuery( "<input type='checkbox' />" ).clone()[ 0 ].nodeName.toLowerCase(), "input", "Clone a <input type='checkbox' />" );
// Check cloning non-elements
- assert.equal( jQuery("#nonnodes").contents().clone().length, 3, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
+ assert.equal( jQuery( "#nonnodes" ).contents().clone().length, 3, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
// Verify that clones of clones can keep event listeners
- div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() {
+ div = jQuery( "<div><ul><li>test</li></ul></div>" ).on( "click", function() {
assert.ok( true, "Bound event still exists." );
- });
+ } );
clone = div.clone( true ); div.remove();
div = clone.clone( true ); clone.remove();
assert.equal( div.length, 1, "One element cloned" );
assert.equal( div[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
- div.trigger("click");
+ div.trigger( "click" );
// Manually clean up detached elements
div.remove();
// Verify that cloned children can keep event listeners
- div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
- div.find("table").on( "click", function() {
+ div = jQuery( "<div/>" ).append( [ document.createElement( "table" ), document.createElement( "table" ) ] );
+ div.find( "table" ).on( "click", function() {
assert.ok( true, "Bound event still exists." );
- });
+ } );
clone = div.clone( true );
assert.equal( clone.length, 1, "One element cloned" );
assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
- clone.find("table").trigger("click");
+ clone.find( "table" ).trigger( "click" );
// Manually clean up detached elements
div.remove();
clone.remove();
// Make sure that doing .clone() doesn't clone event listeners
- div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() {
+ div = jQuery( "<div><ul><li>test</li></ul></div>" ).on( "click", function() {
assert.ok( false, "Bound event still exists after .clone()." );
- });
+ } );
clone = div.clone();
- clone.trigger("click");
+ clone.trigger( "click" );
// Manually clean up detached elements
clone.remove();
div.remove();
// Test both html() and clone() for <embed> and <object> types
- div = jQuery("<div/>").html("<embed height='355' width='425' src='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'></embed>");
+ div = jQuery( "<div/>" ).html( "<embed height='355' width='425' src='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'></embed>" );
clone = div.clone( true );
assert.equal( clone.length, 1, "One element cloned" );
@@ -1459,76 +1456,77 @@ QUnit.test( "clone()", function( assert ) {
// this is technically an invalid object, but because of the special
// classid instantiation it is the only kind that IE has trouble with,
// so let's test with it too.
- div = jQuery("<div/>").html("<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>");
+ div = jQuery( "<div/>" ).html( "<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>" );
clone = div.clone( true );
assert.equal( clone.length, 1, "One element cloned" );
assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
- div = div.find("object");
- clone = clone.find("object");
+ div = div.find( "object" );
+ clone = clone.find( "object" );
+
// oldIE adds extra attributes and <param> elements, so just test for existence of the defined set
jQuery.each( [ "height", "width", "classid" ], function( i, attr ) {
assert.equal( clone.attr( attr ), div.attr( attr ), "<object> attribute cloned: " + attr );
} );
- (function() {
+ ( function() {
var params = {};
- clone.find("param").each(function( index, param ) {
+ clone.find( "param" ).each( function( index, param ) {
params[ param.attributes.name.nodeValue.toLowerCase() ] =
param.attributes.value.nodeValue.toLowerCase();
- });
+ } );
- div.find("param").each(function( index, param ) {
+ div.find( "param" ).each( function( index, param ) {
var key = param.attributes.name.nodeValue.toLowerCase();
assert.equal( params[ key ], param.attributes.value.nodeValue.toLowerCase(), "<param> cloned: " + key );
- });
- })();
+ } );
+ } )();
// and here's a valid one.
- div = jQuery("<div/>").html("<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>");
+ div = jQuery( "<div/>" ).html( "<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>" );
- clone = div.clone(true);
+ clone = div.clone( true );
assert.equal( clone.length, 1, "One element cloned" );
assert.equal( clone.html(), div.html(), "Element contents cloned" );
assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
- div = jQuery("<div/>").data({ "a": true });
+ div = jQuery( "<div/>" ).data( { "a": true } );
clone = div.clone( true );
- assert.equal( clone.data("a"), true, "Data cloned." );
+ assert.equal( clone.data( "a" ), true, "Data cloned." );
clone.data( "a", false );
- assert.equal( clone.data("a"), false, "Ensure cloned element data object was correctly modified" );
- assert.equal( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" );
+ assert.equal( clone.data( "a" ), false, "Ensure cloned element data object was correctly modified" );
+ assert.equal( div.data( "a" ), true, "Ensure cloned element data object is copied, not referenced" );
// manually clean up detached elements
div.remove();
clone.remove();
- form = document.createElement("form");
+ form = document.createElement( "form" );
form.action = "/test/";
- div = document.createElement("div");
- div.appendChild( document.createTextNode("test") );
+ div = document.createElement( "div" );
+ div.appendChild( document.createTextNode( "test" ) );
form.appendChild( div );
- assert.equal( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
+ assert.equal( jQuery( form ).clone().children().length, 1, "Make sure we just get the form back." );
- body = jQuery("body").clone();
+ body = jQuery( "body" ).clone();
assert.equal( body.children()[ 0 ].id, "qunit", "Make sure cloning body works" );
body.remove();
-});
+} );
QUnit.test( "clone(script type=non-javascript) (#11359)", function( assert ) {
assert.expect( 3 );
- var src = jQuery("<script type='text/filler'>Lorem ipsum dolor sit amet</script><q><script type='text/filler'>consectetur adipiscing elit</script></q>"),
+ var src = jQuery( "<script type='text/filler'>Lorem ipsum dolor sit amet</script><q><script type='text/filler'>consectetur adipiscing elit</script></q>" ),
dest = src.clone();
assert.equal( dest[ 0 ].text, "Lorem ipsum dolor sit amet", "Cloning preserves script text" );
assert.equal( dest.last().html(), src.last().html(), "Cloning preserves nested script text" );
assert.ok( /^\s*<scr.pt\s+type=['"]?text\/filler['"]?\s*>consectetur adipiscing elit<\/scr.pt>\s*$/i.test( dest.last().html() ), "Cloning preserves nested script text" );
dest.remove();
-});
+} );
QUnit.test( "clone(form element) (Bug #3879, #6655)", function( assert ) {
@@ -1536,49 +1534,49 @@ QUnit.test( "clone(form element) (Bug #3879, #6655)", function( assert ) {
var clone, element;
- element = jQuery("<select><option>Foo</option><option value='selected' selected>Bar</option></select>");
+ element = jQuery( "<select><option>Foo</option><option value='selected' selected>Bar</option></select>" );
- assert.equal( element.clone().find("option").filter(function() { return this.selected; }).val(), "selected", "Selected option cloned correctly" );
+ assert.equal( element.clone().find( "option" ).filter( function() { return this.selected; } ).val(), "selected", "Selected option cloned correctly" );
- element = jQuery("<input type='checkbox' value='foo'>").attr( "checked", "checked" );
+ element = jQuery( "<input type='checkbox' value='foo'>" ).attr( "checked", "checked" );
clone = element.clone();
- assert.equal( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
+ assert.equal( clone.is( ":checked" ), element.is( ":checked" ), "Checked input cloned correctly" );
assert.equal( clone[ 0 ].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
- element = jQuery("<input type='text' value='foo'>");
+ element = jQuery( "<input type='text' value='foo'>" );
clone = element.clone();
assert.equal( clone[ 0 ].defaultValue, "foo", "Text input defaultValue cloned correctly" );
- element = jQuery("<textarea>foo</textarea>");
+ element = jQuery( "<textarea>foo</textarea>" );
clone = element.clone();
assert.equal( clone[ 0 ].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
-});
+} );
QUnit.test( "clone(multiple selected options) (Bug #8129)", function( assert ) {
assert.expect( 1 );
- var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>");
+ var element = jQuery( "<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>" );
- assert.equal( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" );
+ assert.equal( element.clone().find( "option:selected" ).length, element.find( "option:selected" ).length, "Multiple selected options cloned correctly" );
-});
+} );
QUnit.test( "clone() on XML nodes", function( assert ) {
assert.expect( 2 );
var xml = createDashboardXML(),
- root = jQuery(xml.documentElement).clone(),
- origTab = jQuery("tab", xml).eq( 0 ),
- cloneTab = jQuery("tab", root).eq( 0 );
+ root = jQuery( xml.documentElement ).clone(),
+ origTab = jQuery( "tab", xml ).eq( 0 ),
+ cloneTab = jQuery( "tab", root ).eq( 0 );
- origTab.text("origval");
- cloneTab.text("cloneval");
+ origTab.text( "origval" );
+ cloneTab.text( "cloneval" );
assert.equal( origTab.text(), "origval", "Check original XML node was correctly set" );
assert.equal( cloneTab.text(), "cloneval", "Check cloned XML node was correctly set" );
-});
+} );
QUnit.test( "clone() on local XML nodes with html5 nodename", function( assert ) {
@@ -1589,54 +1587,54 @@ QUnit.test( "clone() on local XML nodes with html5 nodename", function( assert )
assert.equal( $meter[ 0 ].nodeName, "meter", "Check if nodeName was not changed due to cloning" );
assert.equal( $meter[ 0 ].nodeType, 1, "Check if nodeType is not changed due to cloning" );
-});
+} );
QUnit.test( "html(undefined)", function( assert ) {
assert.expect( 1 );
- assert.equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
-});
+ assert.equal( jQuery( "#foo" ).html( "<i>test</i>" ).html( undefined ).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
+} );
QUnit.test( "html() on empty set", function( assert ) {
assert.expect( 1 );
assert.strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" );
-});
+} );
function childNodeNames( node ) {
return jQuery.map( node.childNodes, function( child ) {
return child.nodeName.toUpperCase();
- }).join(" ");
+ } ).join( " " );
}
function testHtml( valueObj, assert ) {
assert.expect( 40 );
var actual, expected, tmp,
- div = jQuery("<div></div>"),
- fixture = jQuery("#qunit-fixture");
+ div = jQuery( "<div></div>" ),
+ fixture = jQuery( "#qunit-fixture" );
- div.html( valueObj("<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>") );
+ div.html( valueObj( "<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>" ) );
assert.equal( div.children().length, 2, "Found children" );
assert.equal( div.children().children().length, 1, "Found grandchild" );
actual = []; expected = [];
- tmp = jQuery("<map/>").html( valueObj("<area alt='area'/>") ).each(function() {
- expected.push("AREA");
+ tmp = jQuery( "<map/>" ).html( valueObj( "<area alt='area'/>" ) ).each( function() {
+ expected.push( "AREA" );
actual.push( childNodeNames( this ) );
- });
+ } );
assert.equal( expected.length, 1, "Expecting one parent" );
assert.deepEqual( actual, expected, "Found the inserted area element" );
- assert.equal( div.html(valueObj(5)).html(), "5", "Setting a number as html" );
- assert.equal( div.html(valueObj(0)).html(), "0", "Setting a zero as html" );
- assert.equal( div.html(valueObj(Infinity)).html(), "Infinity", "Setting Infinity as html" );
- assert.equal( div.html(valueObj(NaN)).html(), "", "Setting NaN as html" );
- assert.equal( div.html(valueObj(1e2)).html(), "100", "Setting exponential number notation as html" );
+ assert.equal( div.html( valueObj( 5 ) ).html(), "5", "Setting a number as html" );
+ assert.equal( div.html( valueObj( 0 ) ).html(), "0", "Setting a zero as html" );
+ assert.equal( div.html( valueObj( Infinity ) ).html(), "Infinity", "Setting Infinity as html" );
+ assert.equal( div.html( valueObj( NaN ) ).html(), "", "Setting NaN as html" );
+ assert.equal( div.html( valueObj( 1e2 ) ).html(), "100", "Setting exponential number notation as html" );
- div.html( valueObj("&#160;&amp;") );
+ div.html( valueObj( "&#160;&amp;" ) );
assert.equal(
div[ 0 ].innerHTML.replace( /\xA0/, "&nbsp;" ),
"&nbsp;&amp;",
@@ -1644,46 +1642,46 @@ function testHtml( valueObj, assert ) {
);
tmp = "&lt;div&gt;hello1&lt;/div&gt;";
- assert.equal( div.html(valueObj(tmp) ).html().replace( />/g, "&gt;" ), tmp, "Escaped html" );
+ assert.equal( div.html( valueObj( tmp ) ).html().replace( />/g, "&gt;" ), tmp, "Escaped html" );
tmp = "x" + tmp;
- assert.equal( div.html(valueObj( tmp )).html().replace( />/g, "&gt;" ), tmp, "Escaped html, leading x" );
+ assert.equal( div.html( valueObj( tmp ) ).html().replace( />/g, "&gt;" ), tmp, "Escaped html, leading x" );
tmp = " " + tmp.slice( 1 );
- assert.equal( div.html(valueObj( tmp )).html().replace( />/g, "&gt;" ), tmp, "Escaped html, leading space" );
+ assert.equal( div.html( valueObj( tmp ) ).html().replace( />/g, "&gt;" ), tmp, "Escaped html, leading space" );
actual = []; expected = []; tmp = {};
- jQuery("#nonnodes").contents().html( valueObj("<b>bold</b>") ).each(function() {
+ jQuery( "#nonnodes" ).contents().html( valueObj( "<b>bold</b>" ) ).each( function() {
var html = jQuery( this ).html();
tmp[ this.nodeType ] = true;
expected.push( this.nodeType === 1 ? "<b>bold</b>" : undefined );
actual.push( html ? html.toLowerCase() : html );
- });
+ } );
assert.deepEqual( actual, expected, "Set containing element, text node, comment" );
assert.ok( tmp[ 1 ], "element" );
assert.ok( tmp[ 3 ], "text node" );
assert.ok( tmp[ 8 ], "comment" );
actual = []; expected = [];
- fixture.children("div").html( valueObj("<b>test</b>") ).each(function() {
- expected.push("B");
+ fixture.children( "div" ).html( valueObj( "<b>test</b>" ) ).each( function() {
+ expected.push( "B" );
actual.push( childNodeNames( this ) );
- });
+ } );
assert.equal( expected.length, 7, "Expecting many parents" );
assert.deepEqual( actual, expected, "Correct childNodes after setting HTML" );
actual = []; expected = [];
- fixture.html( valueObj("<style>.foobar{color:green;}</style>") ).each(function() {
- expected.push("STYLE");
+ fixture.html( valueObj( "<style>.foobar{color:green;}</style>" ) ).each( function() {
+ expected.push( "STYLE" );
actual.push( childNodeNames( this ) );
- });
+ } );
assert.equal( expected.length, 1, "Expecting one parent" );
assert.deepEqual( actual, expected, "Found the inserted style element" );
- fixture.html( valueObj("<select/>") );
- jQuery("#qunit-fixture select").html( valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>") );
- assert.equal( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" );
+ fixture.html( valueObj( "<select/>" ) );
+ jQuery( "#qunit-fixture select" ).html( valueObj( "<option>O1</option><option selected='selected'>O2</option><option>O3</option>" ) );
+ assert.equal( jQuery( "#qunit-fixture select" ).val(), "O2", "Selected option correct" );
tmp = fixture.html(
- valueObj([
+ valueObj( [
"<script type='something/else'>ok( false, 'evaluated: non-script' );</script>",
"<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>",
"<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>",
@@ -1694,38 +1692,38 @@ function testHtml( valueObj, assert ) {
"<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>",
"<script>ok( true, 'evaluated: inner no type' );</script>",
"</div>"
- ].join(""))
- ).find("script");
+ ].join( "" ) )
+ ).find( "script" );
assert.equal( tmp.length, 8, "All script tags remain." );
assert.equal( tmp[ 0 ].type, "something/else", "Non-evaluated type." );
assert.equal( tmp[ 1 ].type, "text/javascript", "Evaluated type." );
- fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") );
- fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") );
- fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") );
- fixture.html( valueObj("foo <form><script type='text/javascript'>ok( true, 'Injection of identical script (#975)' );</script></form>") );
+ fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) );
+ fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) );
+ fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) );
+ fixture.html( valueObj( "foo <form><script type='text/javascript'>ok( true, 'Injection of identical script (#975)' );</script></form>" ) );
jQuery.scriptorder = 0;
- fixture.html( valueObj([
+ fixture.html( valueObj( [
"<script>",
"equal( jQuery('#scriptorder').length, 1,'Execute after html' );",
"equal( jQuery.scriptorder++, 0, 'Script is executed in order' );",
"</script>",
"<span id='scriptorder'><script>equal( jQuery.scriptorder++, 1, 'Script (nested) is executed in order');</script></span>",
"<script>equal( jQuery.scriptorder++, 2, 'Script (unnested) is executed in order' );</script>"
- ].join("")) );
+ ].join( "" ) ) );
fixture.html( valueObj( fixture.text() ) );
assert.ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" );
}
QUnit.test( "html(String|Number)", function( assert ) {
- testHtml(manipulationBareObj, assert );
-});
+ testHtml( manipulationBareObj, assert );
+} );
QUnit.test( "html(Function)", function( assert ) {
- testHtml(manipulationFunctionReturningObj, assert );
-});
+ testHtml( manipulationFunctionReturningObj, assert );
+} );
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {
@@ -1733,24 +1731,24 @@ QUnit.test( "html(Function) with incoming value -- direct selection", function(
var els, actualhtml, pass;
- els = jQuery("#foo > p");
- actualhtml = els.map(function() {
+ els = jQuery( "#foo > p" );
+ actualhtml = els.map( function() {
return jQuery( this ).html();
- });
+ } );
- els.html(function( i, val ) {
+ els.html( function( i, val ) {
assert.equal( val, actualhtml[ i ], "Make sure the incoming value is correct." );
return "<b>test</b>";
- });
+ } );
pass = true;
- els.each(function() {
+ els.each( function() {
if ( this.childNodes.length !== 1 ) {
pass = false;
}
- });
+ } );
assert.ok( pass, "Set HTML" );
-});
+} );
QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function( assert ) {
@@ -1758,15 +1756,15 @@ QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function(
var actualhtml, j, $div, $div2, insert;
- j = jQuery("#nonnodes").contents();
- actualhtml = j.map(function() {
+ j = jQuery( "#nonnodes" ).contents();
+ actualhtml = j.map( function() {
return jQuery( this ).html();
- });
+ } );
- j.html(function( i, val ) {
+ j.html( function( i, val ) {
assert.equal( val, actualhtml[ i ], "Make sure the incoming value is correct." );
return "<b>bold</b>";
- });
+ } );
// Handle the case where no comment is in the document
if ( j.length === 2 ) {
@@ -1775,99 +1773,99 @@ QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function(
assert.equal( j.html().replace( / xmlns="[^"]+"/g, "" ).toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
- $div = jQuery("<div />");
+ $div = jQuery( "<div />" );
- assert.equal( $div.html(function( i, val ) {
+ assert.equal( $div.html( function( i, val ) {
assert.equal( val, "", "Make sure the incoming value is correct." );
return 5;
- }).html(), "5", "Setting a number as html" );
+ } ).html(), "5", "Setting a number as html" );
- assert.equal( $div.html(function( i, val ) {
+ assert.equal( $div.html( function( i, val ) {
assert.equal( val, "5", "Make sure the incoming value is correct." );
return 0;
- }).html(), "0", "Setting a zero as html" );
+ } ).html(), "0", "Setting a zero as html" );
- $div2 = jQuery("<div/>");
+ $div2 = jQuery( "<div/>" );
insert = "&lt;div&gt;hello1&lt;/div&gt;";
- assert.equal( $div2.html(function( i, val ) {
+ assert.equal( $div2.html( function( i, val ) {
assert.equal( val, "", "Make sure the incoming value is correct." );
return insert;
- }).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." );
+ } ).html().replace( />/g, "&gt;" ), insert, "Verify escaped insertion." );
- assert.equal( $div2.html(function( i, val ) {
- assert.equal( val.replace(/>/g, "&gt;"), insert, "Make sure the incoming value is correct." );
+ assert.equal( $div2.html( function( i, val ) {
+ assert.equal( val.replace( />/g, "&gt;" ), insert, "Make sure the incoming value is correct." );
return "x" + insert;
- }).html().replace( />/g, "&gt;" ), "x" + insert, "Verify escaped insertion." );
+ } ).html().replace( />/g, "&gt;" ), "x" + insert, "Verify escaped insertion." );
- assert.equal( $div2.html(function( i, val ) {
+ assert.equal( $div2.html( function( i, val ) {
assert.equal( val.replace( />/g, "&gt;" ), "x" + insert, "Make sure the incoming value is correct." );
return " " + insert;
- }).html().replace( />/g, "&gt;" ), " " + insert, "Verify escaped insertion." );
-});
+ } ).html().replace( />/g, "&gt;" ), " " + insert, "Verify escaped insertion." );
+} );
QUnit.test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function( assert ) {
assert.expect( 2 );
- var $content = jQuery("<div><b><i>text</i></b></div>").appendTo("#qunit-fixture"),
+ var $content = jQuery( "<div><b><i>text</i></b></div>" ).appendTo( "#qunit-fixture" ),
expected = /^<b><i>text<\/i><\/b>$/i;
// Attach jQuery and Sizzle data (the latter with a non-qSA nth-child)
try {
- $content.find(":nth-child(1):lt(4)").data( "test", true );
+ $content.find( ":nth-child(1):lt(4)" ).data( "test", true );
// But don't break on a non-Sizzle build
- } catch( e ) {
- $content.find("*").data( "test", true );
+ } catch ( e ) {
+ $content.find( "*" ).data( "test", true );
}
assert.ok( expected.test( $content.clone( false )[ 0 ].innerHTML ), "clone()" );
assert.ok( expected.test( $content.html() ), "html()" );
-});
+} );
QUnit.test( "remove() no filters", function( assert ) {
assert.expect( 2 );
- var first = jQuery("#ap").children().first();
+ var first = jQuery( "#ap" ).children().first();
- first.data("foo", "bar");
+ first.data( "foo", "bar" );
- jQuery("#ap").children().remove();
- assert.ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
- assert.equal( jQuery("#ap").children().length, 0, "Check remove" );
-});
+ jQuery( "#ap" ).children().remove();
+ assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" );
+ assert.equal( jQuery( "#ap" ).children().length, 0, "Check remove" );
+} );
QUnit.test( "remove() with filters", function( assert ) {
assert.expect( 8 );
var markup, div;
- jQuery("#ap").children().remove("a");
- assert.ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
- assert.equal( jQuery("#ap").children().length, 1, "Check filtered remove" );
+ jQuery( "#ap" ).children().remove( "a" );
+ assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" );
+ assert.equal( jQuery( "#ap" ).children().length, 1, "Check filtered remove" );
- jQuery("#ap").children().remove("a, code");
- assert.equal( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
+ jQuery( "#ap" ).children().remove( "a, code" );
+ assert.equal( jQuery( "#ap" ).children().length, 0, "Check multi-filtered remove" );
// Positional and relative selectors
markup = "<div><span>1</span><span>2</span><span>3</span><span>4</span></div>";
div = jQuery( markup );
- div.children().remove("span:nth-child(2n)");
+ div.children().remove( "span:nth-child(2n)" );
assert.equal( div.text(), "13", "relative selector in remove" );
div = jQuery( markup );
- div.children().remove("span:first");
+ div.children().remove( "span:first" );
assert.equal( div.text(), "234", "positional selector in remove" );
div = jQuery( markup );
- div.children().remove("span:last");
+ div.children().remove( "span:last" );
assert.equal( div.text(), "123", "positional selector in remove" );
// using contents will get comments regular, text, and comment nodes
// Handle the case where no comment is in the document
- assert.ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" );
- jQuery("#nonnodes").contents().remove();
- assert.equal( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
-});
+ assert.ok( jQuery( "#nonnodes" ).contents().length >= 2, "Check node,textnode,comment remove works" );
+ jQuery( "#nonnodes" ).contents().remove();
+ assert.equal( jQuery( "#nonnodes" ).contents().length, 0, "Check node,textnode,comment remove works" );
+} );
QUnit.test( "remove() event cleaning ", function( assert ) {
assert.expect( 1 );
@@ -1875,16 +1873,16 @@ QUnit.test( "remove() event cleaning ", function( assert ) {
var count, first, cleanUp;
count = 0;
- first = jQuery("#ap").children().first();
+ first = jQuery( "#ap" ).children().first();
cleanUp = first.on( "click", function() {
count++;
- }).remove().appendTo("#qunit-fixture").trigger("click");
+ } ).remove().appendTo( "#qunit-fixture" ).trigger( "click" );
assert.strictEqual( 0, count, "Event handler has been removed" );
// Clean up detached data
cleanUp.remove();
-});
+} );
QUnit.test( "remove() in document order #13779", function( assert ) {
assert.expect( 1 );
@@ -1893,11 +1891,11 @@ QUnit.test( "remove() in document order #13779", function( assert ) {
cleanData = jQuery.cleanData;
jQuery.cleanData = function( nodes ) {
- last = jQuery.text( nodes[0] );
+ last = jQuery.text( nodes[ 0 ] );
cleanData.call( this, nodes );
};
- jQuery("#qunit-fixture").append(
+ jQuery( "#qunit-fixture" ).append(
jQuery.parseHTML(
"<div class='removal-fixture'>1</div>" +
"<div class='removal-fixture'>2</div>" +
@@ -1905,60 +1903,60 @@ QUnit.test( "remove() in document order #13779", function( assert ) {
)
);
- jQuery(".removal-fixture").remove();
+ jQuery( ".removal-fixture" ).remove();
assert.equal( last, 3, "The removal fixtures were removed in document order" );
jQuery.cleanData = cleanData;
-});
+} );
-QUnit.test("detach() no filters", function( assert ) {
+QUnit.test( "detach() no filters", function( assert ) {
- assert.expect(3);
+ assert.expect( 3 );
- var first = jQuery("#ap").children().first();
+ var first = jQuery( "#ap" ).children().first();
- first.data("foo", "bar");
+ first.data( "foo", "bar" );
- jQuery("#ap").children().detach();
- assert.ok(jQuery("#ap").text().length > 10, "Check text is not removed");
- assert.equal(jQuery("#ap").children().length, 0, "Check remove");
+ jQuery( "#ap" ).children().detach();
+ assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" );
+ assert.equal( jQuery( "#ap" ).children().length, 0, "Check remove" );
- assert.equal(first.data("foo"), "bar");
+ assert.equal( first.data( "foo" ), "bar" );
first.remove();
-});
+} );
-QUnit.test("detach() with filters", function( assert ) {
+QUnit.test( "detach() with filters", function( assert ) {
- assert.expect(8);
+ assert.expect( 8 );
var markup, div;
- jQuery("#ap").children().detach("a");
- assert.ok(jQuery("#ap").text().length > 10, "Check text is not removed");
- assert.equal(jQuery("#ap").children().length, 1, "Check filtered remove");
+ jQuery( "#ap" ).children().detach( "a" );
+ assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" );
+ assert.equal( jQuery( "#ap" ).children().length, 1, "Check filtered remove" );
- jQuery("#ap").children().detach("a, code");
- assert.equal(jQuery("#ap").children().length, 0, "Check multi-filtered remove");
+ jQuery( "#ap" ).children().detach( "a, code" );
+ assert.equal( jQuery( "#ap" ).children().length, 0, "Check multi-filtered remove" );
// Positional and relative selectors
markup = "<div><span>1</span><span>2</span><span>3</span><span>4</span></div>";
- div = jQuery(markup);
- div.children().detach("span:nth-child(2n)");
- assert.equal(div.text(), "13", "relative selector in detach");
- div = jQuery(markup);
- div.children().detach("span:first");
- assert.equal(div.text(), "234", "positional selector in detach");
- div = jQuery(markup);
- div.children().detach("span:last");
- assert.equal(div.text(), "123", "positional selector in detach");
+ div = jQuery( markup );
+ div.children().detach( "span:nth-child(2n)" );
+ assert.equal( div.text(), "13", "relative selector in detach" );
+ div = jQuery( markup );
+ div.children().detach( "span:first" );
+ assert.equal( div.text(), "234", "positional selector in detach" );
+ div = jQuery( markup );
+ div.children().detach( "span:last" );
+ assert.equal( div.text(), "123", "positional selector in detach" );
// using contents will get comments regular, text, and comment nodes
// Handle the case where no comment is in the document
- assert.ok(jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works");
- jQuery("#nonnodes").contents().detach();
- assert.equal(jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works");
-});
+ assert.ok( jQuery( "#nonnodes" ).contents().length >= 2, "Check node,textnode,comment remove works" );
+ jQuery( "#nonnodes" ).contents().detach();
+ assert.equal( jQuery( "#nonnodes" ).contents().length, 0, "Check node,textnode,comment remove works" );
+} );
QUnit.test( "detach() event cleaning ", function( assert ) {
assert.expect( 1 );
@@ -1966,29 +1964,29 @@ QUnit.test( "detach() event cleaning ", function( assert ) {
var count, first, cleanUp;
count = 0;
- first = jQuery("#ap").children().first();
+ first = jQuery( "#ap" ).children().first();
cleanUp = first.on( "click", function() {
count++;
- }).detach().appendTo("#qunit-fixture").trigger("click");
+ } ).detach().appendTo( "#qunit-fixture" ).trigger( "click" );
assert.strictEqual( 1, count, "Event handler has not been removed" );
// Clean up detached data
cleanUp.remove();
-});
+} );
-QUnit.test("empty()", function( assert ) {
+QUnit.test( "empty()", function( assert ) {
assert.expect( 3 );
- assert.equal( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
- assert.equal( jQuery("#ap").children().length, 4, "Check elements are not removed" );
+ assert.equal( jQuery( "#ap" ).children().empty().text().length, 0, "Check text is removed" );
+ assert.equal( jQuery( "#ap" ).children().length, 4, "Check elements are not removed" );
// using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
+ var j = jQuery( "#nonnodes" ).contents();
j.empty();
assert.equal( j.html(), "", "Check node,textnode,comment empty works" );
-});
+} );
QUnit.test( "jQuery.cleanData", function( assert ) {
@@ -2003,10 +2001,10 @@ QUnit.test( "jQuery.cleanData", function( assert ) {
// Should both do nothing
pos = "Outer";
- div.trigger("click");
+ div.trigger( "click" );
pos = "Inner";
- div.children().trigger("click");
+ div.children().trigger( "click" );
type = "empty";
div = getDiv();
@@ -2017,11 +2015,11 @@ QUnit.test( "jQuery.cleanData", function( assert ) {
// Should trigger 1
pos = "Outer";
- div.trigger("click");
+ div.trigger( "click" );
// Should do nothing
pos = "Inner";
- child.trigger("click");
+ child.trigger( "click" );
// Should trigger 2
div.remove();
@@ -2032,29 +2030,29 @@ QUnit.test( "jQuery.cleanData", function( assert ) {
child = div.children();
// Should trigger 2 remove event
- div.html("<div></div>");
+ div.html( "<div></div>" );
// Should trigger 1
pos = "Outer";
- div.trigger("click");
+ div.trigger( "click" );
// Should do nothing
pos = "Inner";
- child.trigger("click");
+ child.trigger( "click" );
// Should trigger 2
div.remove();
function getDiv() {
- var div = jQuery("<div class='outer'><div class='inner'></div></div>").on( "click", function() {
+ var div = jQuery( "<div class='outer'><div class='inner'></div></div>" ).on( "click", function() {
assert.ok( true, type + " " + pos + " Click event fired." );
- }).on( "focus", function() {
+ } ).on( "focus", function() {
assert.ok( true, type + " " + pos + " Focus event fired." );
- }).find("div").on( "click", function() {
+ } ).find( "div" ).on( "click", function() {
assert.ok( false, type + " " + pos + " Click event fired." );
- }).on( "focus", function() {
+ } ).on( "focus", function() {
assert.ok( false, type + " " + pos + " Focus event fired." );
- }).end().appendTo("body");
+ } ).end().appendTo( "body" );
div[ 0 ].detachEvent = div[ 0 ].removeEventListener = function( t ) {
assert.ok( true, type + " Outer " + t + " event unbound" );
@@ -2066,7 +2064,7 @@ QUnit.test( "jQuery.cleanData", function( assert ) {
return div;
}
-});
+} );
QUnit.test( "jQuery.cleanData eliminates all private data (gh-2127)", function( assert ) {
assert.expect( 3 );
@@ -2085,7 +2083,7 @@ QUnit.test( "jQuery.cleanData eliminates all private data (gh-2127)", function(
"Private data is empty after node is removed" );
div.remove();
-});
+} );
QUnit.test( "jQuery.cleanData eliminates all public data", function( assert ) {
assert.expect( 2 );
@@ -2105,7 +2103,7 @@ QUnit.test( "jQuery.cleanData eliminates all public data", function( assert ) {
assert.ok( false, "Expando was not removed when there was no more data" );
}
}
-});
+} );
QUnit.test( "domManip plain-text caching (trac-6779)", function( assert ) {
@@ -2120,11 +2118,11 @@ QUnit.test( "domManip plain-text caching (trac-6779)", function( assert ) {
try {
$f.append( bad[ i ] );
}
- catch( e ) {}
+ catch ( e ) {}
}
- assert.equal( $f.text(), bad.join(""), "Cached strings that match Object properties" );
+ assert.equal( $f.text(), bad.join( "" ), "Cached strings that match Object properties" );
$f.remove();
-});
+} );
QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9221)", function( assert ) {
@@ -2153,7 +2151,7 @@ QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9
"//--><!]]>",
"</script>"
].join( "\n" ) ).appendTo( "#qunit-fixture" );
-});
+} );
testIframeWithCallback(
"domManip tolerates window-valued document[0] in IE9/10 (trac-12266)",
@@ -2169,12 +2167,12 @@ QUnit.test( "jQuery.clone - no exceptions for object elements #9587", function(
assert.expect( 1 );
try {
- jQuery("#no-clone-exception").clone();
+ jQuery( "#no-clone-exception" ).clone();
assert.ok( true, "cloned with no exceptions" );
- } catch( e ) {
+ } catch ( e ) {
assert.ok( false, e.message );
}
-});
+} );
QUnit.test( "Cloned, detached HTML5 elems (#10667,10670)", function( assert ) {
@@ -2193,38 +2191,38 @@ QUnit.test( "Cloned, detached HTML5 elems (#10667,10670)", function( assert ) {
// Bind an event
$section.on( "click", function() {
assert.ok( true, "clone fired event" );
- });
+ } );
// Second clone (will have an event bound)
$clone = $section.clone( true );
// Trigger an event from the first clone
- $clone.trigger("click");
- $clone.off("click");
+ $clone.trigger( "click" );
+ $clone.off( "click" );
// Add a child node with text to the original
- $section.append("<p>Hello</p>");
+ $section.append( "<p>Hello</p>" );
// Third clone (will have child node and text)
$clone = $section.clone( true );
- assert.equal( $clone.find("p").text(), "Hello", "Assert text in child of clone" );
+ assert.equal( $clone.find( "p" ).text(), "Hello", "Assert text in child of clone" );
// Trigger an event from the third clone
- $clone.trigger("click");
- $clone.off("click");
+ $clone.trigger( "click" );
+ $clone.off( "click" );
// Add attributes to copy
- $section.attr({
+ $section.attr( {
"class": "foo bar baz",
"title": "This is a title"
- });
+ } );
// Fourth clone (will have newly added attributes)
$clone = $section.clone( true );
- assert.equal( $clone.attr("class"), $section.attr("class"), "clone and element have same class attribute" );
- assert.equal( $clone.attr("title"), $section.attr("title"), "clone and element have same title attribute" );
+ assert.equal( $clone.attr( "class" ), $section.attr( "class" ), "clone and element have same class attribute" );
+ assert.equal( $clone.attr( "title" ), $section.attr( "title" ), "clone and element have same title attribute" );
// Remove the original
$section.remove();
@@ -2236,12 +2234,12 @@ QUnit.test( "Cloned, detached HTML5 elems (#10667,10670)", function( assert ) {
$clone.remove();
// Trigger an event from the clone of the clone
- $section.trigger("click");
+ $section.trigger( "click" );
// Unbind any remaining events
- $section.off("click");
- $clone.off("click");
-});
+ $section.off( "click" );
+ $clone.off( "click" );
+} );
QUnit.test( "Guard against exceptions when clearing safeChildNodes", function( assert ) {
@@ -2250,24 +2248,25 @@ QUnit.test( "Guard against exceptions when clearing safeChildNodes", function( a
var div;
try {
- div = jQuery("<div/><hr/><code/><b/>");
- } catch(e) {}
+ div = jQuery( "<div/><hr/><code/><b/>" );
+ } catch ( e ) {}
assert.ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" );
-});
+} );
QUnit.test( "Ensure oldIE creates a new set on appendTo (#8894)", function( assert ) {
assert.expect( 5 );
- assert.strictEqual( jQuery("<div/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" );
- assert.strictEqual( jQuery("<div/>").find("p").end().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" );
- assert.strictEqual( jQuery("<div/>").text("test").addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" );
- assert.strictEqual( jQuery("<bdi/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" );
- assert.strictEqual( jQuery("<p/>").appendTo("<div/>").end().length, jQuery("<p>test</p>").appendTo("<div/>").end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
-});
+ assert.strictEqual( jQuery( "<div/>" ).clone().addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after jQuery.clone" );
+ assert.strictEqual( jQuery( "<div/>" ).find( "p" ).end().addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after jQuery.fn.find" );
+ assert.strictEqual( jQuery( "<div/>" ).text( "test" ).addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after jQuery.fn.text" );
+ assert.strictEqual( jQuery( "<bdi/>" ).clone().addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after clone html5 element" );
+ assert.strictEqual( jQuery( "<p/>" ).appendTo( "<div/>" ).end().length, jQuery( "<p>test</p>" ).appendTo( "<div/>" ).end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
+} );
QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( assert ) {
+
// Support: Android 2.3 only
// Android 2.3 doesn't fire the window.onerror handler, just accept the reality there.
if ( /android 2\.3/i.test( navigator.userAgent ) ) {
@@ -2281,7 +2280,7 @@ QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( asse
var onerror = window.onerror;
- setTimeout(function() {
+ setTimeout( function() {
window.onerror = onerror;
QUnit.start();
@@ -2304,46 +2303,46 @@ QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( asse
};
jQuery( "#qunit-fixture" ).html( "<script>undefined();</script>" );
-});
+} );
QUnit.test( "checked state is cloned with clone()", function( assert ) {
assert.expect( 2 );
- var elem = jQuery.parseHTML("<input type='checkbox' checked='checked'/>")[ 0 ];
+ var elem = jQuery.parseHTML( "<input type='checkbox' checked='checked'/>" )[ 0 ];
elem.checked = false;
- assert.equal( jQuery(elem).clone().attr("id","clone")[ 0 ].checked, false, "Checked false state correctly cloned" );
+ assert.equal( jQuery( elem ).clone().attr( "id", "clone" )[ 0 ].checked, false, "Checked false state correctly cloned" );
- elem = jQuery.parseHTML("<input type='checkbox'/>")[ 0 ];
+ elem = jQuery.parseHTML( "<input type='checkbox'/>" )[ 0 ];
elem.checked = true;
- assert.equal( jQuery(elem).clone().attr("id","clone")[ 0 ].checked, true, "Checked true state correctly cloned" );
-});
+ assert.equal( jQuery( elem ).clone().attr( "id", "clone" )[ 0 ].checked, true, "Checked true state correctly cloned" );
+} );
QUnit.test( "manipulate mixed jQuery and text (#12384, #12346)", function( assert ) {
assert.expect( 2 );
- var div = jQuery("<div>a</div>").append( "&nbsp;", jQuery("<span>b</span>"), "&nbsp;", jQuery("<span>c</span>") ),
+ var div = jQuery( "<div>a</div>" ).append( "&nbsp;", jQuery( "<span>b</span>" ), "&nbsp;", jQuery( "<span>c</span>" ) ),
nbsp = String.fromCharCode( 160 );
- assert.equal( div.text(), "a" + nbsp + "b" + nbsp+ "c", "Appending mixed jQuery with text nodes" );
+ assert.equal( div.text(), "a" + nbsp + "b" + nbsp + "c", "Appending mixed jQuery with text nodes" );
- div = jQuery("<div><div></div></div>")
- .find("div")
+ div = jQuery( "<div><div></div></div>" )
+ .find( "div" )
.after( "<p>a</p>", "<p>b</p>" )
.parent();
- assert.equal( div.find("*").length, 3, "added 2 paragraphs after inner div" );
-});
+ assert.equal( div.find( "*" ).length, 3, "added 2 paragraphs after inner div" );
+} );
QUnit.test( "script evaluation (#11795)", function( assert ) {
assert.expect( 13 );
var scriptsIn, scriptsOut,
- fixture = jQuery("#qunit-fixture").empty(),
- objGlobal = (function() {
+ fixture = jQuery( "#qunit-fixture" ).empty(),
+ objGlobal = ( function() {
return this;
- })(),
+ } )(),
isOk = objGlobal.ok,
notOk = function() {
var args = arguments;
@@ -2352,7 +2351,7 @@ QUnit.test( "script evaluation (#11795)", function( assert ) {
};
objGlobal.ok = notOk;
- scriptsIn = jQuery([
+ scriptsIn = jQuery( [
"<script type='something/else'>ok( false, 'evaluated: non-script' );</script>",
"<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>",
"<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>",
@@ -2363,31 +2362,31 @@ QUnit.test( "script evaluation (#11795)", function( assert ) {
"<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>",
"<script>ok( true, 'evaluated: inner no type' );</script>",
"</div>"
- ].join(""));
- scriptsIn.appendTo( jQuery("<div class='detached'/>") );
+ ].join( "" ) );
+ scriptsIn.appendTo( jQuery( "<div class='detached'/>" ) );
objGlobal.ok = isOk;
- scriptsOut = fixture.append( scriptsIn ).find("script");
+ scriptsOut = fixture.append( scriptsIn ).find( "script" );
assert.equal( scriptsOut[ 0 ].type, "something/else", "Non-evaluated type." );
assert.equal( scriptsOut[ 1 ].type, "text/javascript", "Evaluated type." );
- assert.deepEqual( scriptsOut.get(), fixture.find("script").get(), "All script tags remain." );
+ assert.deepEqual( scriptsOut.get(), fixture.find( "script" ).get(), "All script tags remain." );
objGlobal.ok = notOk;
- scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find("div") );
- assert.deepEqual( fixture.find("div script").get(), scriptsOut.get(), "Scripts cloned without reevaluation" );
+ scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find( "div" ) );
+ assert.deepEqual( fixture.find( "div script" ).get(), scriptsOut.get(), "Scripts cloned without reevaluation" );
fixture.append( scriptsOut.detach() );
- assert.deepEqual( fixture.children("script").get(), scriptsOut.get(), "Scripts detached without reevaluation" );
+ assert.deepEqual( fixture.children( "script" ).get(), scriptsOut.get(), "Scripts detached without reevaluation" );
objGlobal.ok = isOk;
if ( jQuery.ajax ) {
- Globals.register("testBar");
- jQuery("#qunit-fixture").append( "<script src='" + url("data/testbar.php") + "'/>" );
- assert.strictEqual( window["testBar"], "bar", "Global script evaluation" );
+ Globals.register( "testBar" );
+ jQuery( "#qunit-fixture" ).append( "<script src='" + url( "data/testbar.php" ) + "'/>" );
+ assert.strictEqual( window[ "testBar" ], "bar", "Global script evaluation" );
} else {
assert.ok( true, "No jQuery.ajax" );
assert.ok( true, "No jQuery.ajax" );
}
-});
+} );
QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) {
@@ -2403,7 +2402,7 @@ QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) {
assert.equal( ( input.url || input ).slice( -1 ), expectedArgument, message );
expectedArgument++;
};
- jQuery("#qunit-fixture").append("<script src='1'/><script src='2'/>");
+ jQuery( "#qunit-fixture" ).append( "<script src='1'/><script src='2'/>" );
assert.equal( expectedArgument, 3, "synchronous execution" );
message = "custom implementation";
@@ -2412,11 +2411,11 @@ QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) {
jQuery.ajax = function( options ) {
assert.strictEqual( options, {}, "Unexpected call to jQuery.ajax" );
};
- jQuery("#qunit-fixture").append("<script src='3'/><script src='4'/>");
+ jQuery( "#qunit-fixture" ).append( "<script src='3'/><script src='4'/>" );
jQuery.ajax = ajax;
jQuery._evalUrl = evalUrl;
-});
+} );
QUnit.test( "jQuery.htmlPrefilter (gh-1747)", function( assert ) {
@@ -2456,7 +2455,7 @@ QUnit.test( "jQuery.htmlPrefilter (gh-1747)", function( assert ) {
jQuery.htmlPrefilter = htmlPrefilter;
done();
}, 100 );
-});
+} );
QUnit.test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function( assert ) {
@@ -2464,7 +2463,7 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig
var elems;
- jQuery.each([
+ jQuery.each( [
"appendTo",
"prependTo",
"insertBefore",
@@ -2475,44 +2474,44 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig
"<ul id='test4087-complex'><li class='test4087'><div>c1</div>h1</li><li><div>c2</div>h2</li></ul>",
"<div id='test4087-simple'><div class='test4087-1'>1<div class='test4087-2'>2</div><div class='test4087-3'>3</div></div></div>",
"<div id='test4087-multiple'><div class='test4087-multiple'>1</div><div class='test4087-multiple'>2</div></div>"
- ].join("") ).appendTo( "#qunit-fixture" );
+ ].join( "" ) ).appendTo( "#qunit-fixture" );
// complex case based on http://jsfiddle.net/pbramos/gZ7vB/
- jQuery("#test4087-complex div")[ name ]("#test4087-complex li:last-child div:last-child");
- assert.equal( jQuery("#test4087-complex li:last-child div").length, name === "replaceAll" ? 1 : 2, name +" a node to itself, complex case." );
+ jQuery( "#test4087-complex div" )[ name ]( "#test4087-complex li:last-child div:last-child" );
+ assert.equal( jQuery( "#test4087-complex li:last-child div" ).length, name === "replaceAll" ? 1 : 2, name + " a node to itself, complex case." );
// simple case
- jQuery( ".test4087-1" )[ name ](".test4087-1");
- assert.equal( jQuery(".test4087-1").length, 1, name +" a node to itself, simple case." );
+ jQuery( ".test4087-1" )[ name ]( ".test4087-1" );
+ assert.equal( jQuery( ".test4087-1" ).length, 1, name + " a node to itself, simple case." );
// clean for next test
- jQuery("#test4087-complex").remove();
- jQuery("#test4087-simple").remove();
- jQuery("#test4087-multiple").remove();
- });
-});
+ jQuery( "#test4087-complex" ).remove();
+ jQuery( "#test4087-simple" ).remove();
+ jQuery( "#test4087-multiple" ).remove();
+ } );
+} );
QUnit.test( "Index for function argument should be received (#13094)", function( assert ) {
assert.expect( 2 );
var i = 0;
- jQuery("<div/><div/>").before(function( index ) {
+ jQuery( "<div/><div/>" ).before( function( index ) {
assert.equal( index, i++, "Index should be correct" );
- });
+ } );
-});
+} );
QUnit.test( "Make sure jQuery.fn.remove can work on elements in documentFragment", function( assert ) {
assert.expect( 1 );
var fragment = document.createDocumentFragment(),
- div = fragment.appendChild( document.createElement("div") );
+ div = fragment.appendChild( document.createElement( "div" ) );
jQuery( div ).remove();
assert.equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" );
-});
+} );
QUnit.test( "Make sure specific elements with content created correctly (#13232)", function( assert ) {
assert.expect( 20 );
@@ -2538,12 +2537,12 @@ QUnit.test( "Make sure specific elements with content created correctly (#13232)
results.push( name );
args.push( html );
- });
+ } );
- jQuery.fn.append.apply( jQuery("<div/>"), args ).children().each(function( i ) {
+ jQuery.fn.append.apply( jQuery( "<div/>" ), args ).children().each( function( i ) {
assert.ok( jQuery.nodeName( this, results[ i ] ) );
- });
-});
+ } );
+} );
QUnit.test( "Validate creation of multiple quantities of certain elements (#13818)", function( assert ) {
assert.expect( 44 );
@@ -2551,15 +2550,15 @@ QUnit.test( "Validate creation of multiple quantities of certain elements (#1381
var tags = [ "thead", "tbody", "tfoot", "colgroup", "col", "caption", "tr", "th", "td", "optgroup", "option" ];
jQuery.each( tags, function( index, tag ) {
- jQuery( "<" + tag + "/><" + tag + "/>" ).each(function() {
+ jQuery( "<" + tag + "/><" + tag + "/>" ).each( function() {
assert.ok( jQuery.nodeName( this, tag ), tag + " empty elements created correctly" );
- });
+ } );
- jQuery( "<" + this + "></" + tag + "><" + tag + "></" + tag + ">" ).each(function() {
+ jQuery( "<" + this + "></" + tag + "><" + tag + "></" + tag + ">" ).each( function() {
assert.ok( jQuery.nodeName( this, tag ), tag + " elements with closing tag created correctly" );
- });
- });
-});
+ } );
+ } );
+} );
QUnit.test( "Make sure tr element will be appended to tbody element of table when present", function( assert ) {
assert.expect( 1 );
@@ -2576,7 +2575,7 @@ QUnit.test( "Make sure tr element will be appended to tbody element of table whe
html = table.innerHTML.toLowerCase().replace( /\s/g, "" );
assert.strictEqual( html, "<tbody><tr><td>test</td></tr></tbody>" );
-});
+} );
QUnit.test( "Make sure tr elements will be appended to tbody element of table when present", function( assert ) {
assert.expect( 1 );
@@ -2593,7 +2592,7 @@ QUnit.test( "Make sure tr elements will be appended to tbody element of table wh
html = table.innerHTML.toLowerCase().replace( /\s/g, "" );
assert.strictEqual( html, "<tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody>" );
-});
+} );
QUnit.test( "Make sure tfoot element will not be appended to tbody element of table when present", function( assert ) {
assert.expect( 1 );
@@ -2610,7 +2609,7 @@ QUnit.test( "Make sure tfoot element will not be appended to tbody element of ta
html = table.innerHTML.toLowerCase().replace( /\s/g, "" );
assert.strictEqual( html, "<tbody></tbody><tfoot></tfoot>" );
-});
+} );
QUnit.test( "Make sure document fragment will be appended to tbody element of table when present", function( assert ) {
assert.expect( 1 );
@@ -2634,7 +2633,7 @@ QUnit.test( "Make sure document fragment will be appended to tbody element of ta
html = table.innerHTML.toLowerCase().replace( /\s/g, "" );
assert.strictEqual( html, "<tbody><tr><td>test</td></tr></tbody>" );
-});
+} );
QUnit.test( "Make sure col element is appended correctly", function( assert ) {
assert.expect( 1 );
@@ -2646,7 +2645,7 @@ QUnit.test( "Make sure col element is appended correctly", function( assert ) {
jQuery( "<col width='150'/>" ).prependTo( table );
assert.strictEqual( table.find( "td" ).width(), 150 );
-});
+} );
QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) {
Globals.register( "testFoo" );
@@ -2662,7 +2661,7 @@ QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) {
jQuery( fixture ).append( "<script src=\"data:text/javascript,testFoo = 'foo';\"></script>" );
- setTimeout(function() {
+ setTimeout( function() {
if ( window[ "testSrcFoo" ] === "foo" ) {
assert.strictEqual( window[ "testFoo" ], window[ "testSrcFoo" ], "data-URI script executed" );
@@ -2672,4 +2671,4 @@ QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) {
done();
}, 100 );
-});
+} );
diff --git a/test/unit/offset.js b/test/unit/offset.js
index 039b8c781..457034662 100644
--- a/test/unit/offset.js
+++ b/test/unit/offset.js
@@ -1,38 +1,39 @@
-(function() {
+( function() {
if ( !jQuery.fn.offset ) {
return;
}
var supportsScroll, supportsFixedPosition,
- forceScroll = jQuery("<div/>").css({ width: 2000, height: 2000 }),
+ forceScroll = jQuery( "<div/>" ).css( { width: 2000, height: 2000 } ),
checkSupport = function() {
+
// Only run once
checkSupport = false;
- var checkFixed = jQuery("<div/>").css({ position: "fixed", top: "20px" }).appendTo("#qunit-fixture");
+ var checkFixed = jQuery( "<div/>" ).css( { position: "fixed", top: "20px" } ).appendTo( "#qunit-fixture" );
// Must append to body because #qunit-fixture is hidden and elements inside it don't have a scrollTop
- forceScroll.appendTo("body");
+ forceScroll.appendTo( "body" );
window.scrollTo( 200, 200 );
supportsScroll = document.documentElement.scrollTop || document.body.scrollTop;
forceScroll.detach();
- supportsFixedPosition = checkFixed[0].offsetTop === 20;
+ supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20;
checkFixed.remove();
};
-QUnit.module("offset", { setup: function(){
+QUnit.module( "offset", { setup: function() {
if ( typeof checkSupport === "function" ) {
checkSupport();
}
// Force a scroll value on the main window to ensure incorrect results
// if offset is using the scroll offset of the parent window
- forceScroll.appendTo("body");
+ forceScroll.appendTo( "body" );
window.scrollTo( 1, 1 );
forceScroll.detach();
-}, teardown: moduleTeardown });
+}, teardown: moduleTeardown } );
/*
Closure-compiler will roll static methods off of the jQuery object and so they will
@@ -41,13 +42,13 @@ QUnit.module("offset", { setup: function(){
the iframe window and the "jQuery" symbol is used to access any static methods.
*/
-QUnit.test("empty set", function( assert ) {
+QUnit.test( "empty set", function( assert ) {
assert.expect( 2 );
assert.strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
assert.strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
-});
+} );
-QUnit.test("disconnected element", function( assert ) {
+QUnit.test( "disconnected element", function( assert ) {
assert.expect( 2 );
var result = jQuery( document.createElement( "div" ) ).offset();
@@ -57,12 +58,12 @@ QUnit.test("disconnected element", function( assert ) {
// valid input, but will return zeros for back-compat
assert.equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
assert.equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
-});
+} );
-QUnit.test("hidden (display: none) element", function( assert ) {
+QUnit.test( "hidden (display: none) element", function( assert ) {
assert.expect( 2 );
- var node = jQuery("<div style='display: none' />").appendTo("#qunit-fixture"),
+ var node = jQuery( "<div style='display: none' />" ).appendTo( "#qunit-fixture" ),
result = node.offset();
node.remove();
@@ -72,10 +73,10 @@ QUnit.test("hidden (display: none) element", function( assert ) {
// valid input, but will return zeros for back-compat
assert.equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
assert.equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
-});
+} );
-testIframe("offset/absolute", "absolute", function( $, iframe, document, assert ) {
- assert.expect(4);
+testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert ) {
+ assert.expect( 4 );
var doc = iframe.document,
tests;
@@ -85,23 +86,22 @@ testIframe("offset/absolute", "absolute", function( $, iframe, document, assert
{ "id": "#absolute-1", "top": 1, "left": 1 }
];
jQuery.each( tests, function() {
- assert.equal( jQuery( this["id"], doc ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
- assert.equal( jQuery( this["id"], doc ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
- });
-
+ assert.equal( jQuery( this[ "id" ], doc ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
+ assert.equal( jQuery( this[ "id" ], doc ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
+ } );
// get position
tests = [
{ "id": "#absolute-1", "top": 0, "left": 0 }
];
jQuery.each( tests, function() {
- assert.equal( jQuery( this["id"], doc ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
- assert.equal( jQuery( this["id"], doc ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
- });
-});
+ assert.equal( jQuery( this[ "id" ], doc ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
+ assert.equal( jQuery( this[ "id" ], doc ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
+ } );
+} );
-testIframe("offset/absolute", "absolute", function( $, window, document, assert ) {
- assert.expect(178);
+testIframe( "offset/absolute", "absolute", function( $, window, document, assert ) {
+ assert.expect( 178 );
var tests, offset;
@@ -113,10 +113,9 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert
{ "id": "#absolute-2", "top": 20, "left": 20 }
];
jQuery.each( tests, function() {
- assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
- assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
- });
-
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
+ } );
// get position
tests = [
@@ -126,16 +125,15 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert
{ "id": "#absolute-2", "top": 19, "left": 19 }
];
jQuery.each( tests, function() {
- assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
- assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
- });
+ assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
+ assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
+ } );
// test #5781
- offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
+ offset = $( "#positionTest" ).offset( { "top": 10, "left": 10 } ).offset();
assert.equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
assert.equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
-
// set offset
tests = [
{ "id": "#absolute-2", "top": 30, "left": 30 },
@@ -156,39 +154,39 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert
{ "id": "#absolute-1", "top": 1, "left": 1 }
];
jQuery.each( tests, function() {
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
- assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
- assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" );
- var top = this["top"], left = this["left"];
+ var top = this[ "top" ], left = this[ "left" ];
- $( this["id"] ).offset(function(i, val){
+ $( this[ "id" ] ).offset( function( i, val ) {
assert.equal( val.top, top, "Verify incoming top position." );
assert.equal( val.left, left, "Verify incoming top position." );
return { "top": top + 1, "left": left + 1 };
- });
- assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + " })" );
- assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + " })" );
-
- $( this["id"] )
- .offset({ "left": this["left"] + 2 })
- .offset({ "top": this["top"] + 2 });
- assert.equal( $( this["id"] ).offset().top, this["top"] + 2, "Setting one property at a time." );
- assert.equal( $( this["id"] ).offset().left, this["left"] + 2, "Setting one property at a time." );
-
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
- $( this ).css({
+ } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + " })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + " })" );
+
+ $( this[ "id" ] )
+ .offset( { "left": this[ "left" ] + 2 } )
+ .offset( { "top": this[ "top" ] + 2 } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 2, "Setting one property at a time." );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 2, "Setting one property at a time." );
+
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) {
+ $( this ).css( {
"top": props.top + 1,
"left": props.left + 1
- });
- }});
- assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
- assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
- });
-});
+ } );
+ } } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
+ } );
+} );
-testIframe("offset/relative", "relative", function( $, window, document, assert ) {
- assert.expect(60);
+testIframe( "offset/relative", "relative", function( $, window, document, assert ) {
+ assert.expect( 60 );
// get offset
var tests = [
@@ -197,10 +195,9 @@ testIframe("offset/relative", "relative", function( $, window, document, assert
{ "id": "#relative-2", "top": 142, "left": 27 }
];
jQuery.each( tests, function() {
- assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
- assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
- });
-
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
+ } );
// get position
tests = [
@@ -209,10 +206,9 @@ testIframe("offset/relative", "relative", function( $, window, document, assert
{ "id": "#relative-2", "top": 141, "left": 26 }
];
jQuery.each( tests, function() {
- assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
- assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
- });
-
+ assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
+ assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
+ } );
// set offset
tests = [
@@ -230,22 +226,22 @@ testIframe("offset/relative", "relative", function( $, window, document, assert
{ "id": "#relative-1", "top": 7, "left": 7 }
];
jQuery.each( tests, function() {
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
- assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
- assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" );
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
- $( this ).css({
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) {
+ $( this ).css( {
"top": props.top + 1,
"left": props.left + 1
- });
- }});
- assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
- assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
- });
-});
-
-testIframe("offset/static", "static", function( $, window, document, assert ) {
+ } );
+ } } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
+ } );
+} );
+
+testIframe( "offset/static", "static", function( $, window, document, assert ) {
assert.expect( 80 );
// get offset
@@ -256,10 +252,9 @@ testIframe("offset/static", "static", function( $, window, document, assert ) {
{ "id": "#static-2", "top": 122, left: 7 }
];
jQuery.each( tests, function() {
- assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
- assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
- });
-
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
+ } );
// get position
tests = [
@@ -269,10 +264,9 @@ testIframe("offset/static", "static", function( $, window, document, assert ) {
{ "id": "#static-2", "top": 121, "left": 6 }
];
jQuery.each( tests, function() {
- assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["top"] + "').position().top" );
- assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["left"] +"').position().left" );
- });
-
+ assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "top" ] + "').position().top" );
+ assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "left" ] + "').position().left" );
+ } );
// set offset
tests = [
@@ -294,23 +288,23 @@ testIframe("offset/static", "static", function( $, window, document, assert ) {
{ "id": "#static-1", "top": 7, "left": 7 }
];
jQuery.each( tests, function() {
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
- assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
- assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" );
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
- $( this ).css({
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) {
+ $( this ).css( {
"top": props.top + 1,
"left": props.left + 1
- });
- }});
- assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
- assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
- });
-});
+ } );
+ } } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
+ } );
+} );
-testIframe("offset/fixed", "fixed", function( $, window, document, assert ) {
- assert.expect(34);
+testIframe( "offset/fixed", "fixed", function( $, window, document, assert ) {
+ assert.expect( 34 );
var tests, $noTopLeft;
@@ -339,18 +333,19 @@ testIframe("offset/fixed", "fixed", function( $, window, document, assert ) {
assert.ok( true, "Browser doesn't support scroll position." );
} else if ( window.supportsFixedPosition ) {
- assert.equal( $( this["id"] ).offset().top, this["offsetTop"], "jQuery('" + this["id"] + "').offset().top" );
- assert.equal( $( this["id"] ).position().top, this["positionTop"], "jQuery('" + this["id"] + "').position().top" );
- assert.equal( $( this["id"] ).offset().left, this["offsetLeft"], "jQuery('" + this["id"] + "').offset().left" );
- assert.equal( $( this["id"] ).position().left, this["positionLeft"], "jQuery('" + this["id"] + "').position().left" );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "offsetTop" ], "jQuery('" + this[ "id" ] + "').offset().top" );
+ assert.equal( $( this[ "id" ] ).position().top, this[ "positionTop" ], "jQuery('" + this[ "id" ] + "').position().top" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "offsetLeft" ], "jQuery('" + this[ "id" ] + "').offset().left" );
+ assert.equal( $( this[ "id" ] ).position().left, this[ "positionLeft" ], "jQuery('" + this[ "id" ] + "').position().left" );
} else {
+
// need to have same number of assertions
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
}
- });
+ } );
tests = [
{ "id": "#fixed-1", "top": 100, "left": 100 },
@@ -363,74 +358,76 @@ testIframe("offset/fixed", "fixed", function( $, window, document, assert ) {
jQuery.each( tests, function() {
if ( window.supportsFixedPosition ) {
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
- assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
- assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" );
- $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
- $( this ).css({
+ $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) {
+ $( this ).css( {
"top": props.top + 1,
"left": props.left + 1
- });
- }});
- assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
- assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
+ } );
+ } } );
+ assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
+ assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
} else {
+
// need to have same number of assertions
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
}
- });
+ } );
// Bug 8316
- $noTopLeft = $("#fixed-no-top-left");
+ $noTopLeft = $( "#fixed-no-top-left" );
if ( window.supportsFixedPosition ) {
assert.equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
assert.equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
} else {
+
// need to have same number of assertions
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
}
-});
+} );
-testIframe("offset/table", "table", function( $, window, document, assert ) {
- assert.expect(4);
+testIframe( "offset/table", "table", function( $, window, document, assert ) {
+ assert.expect( 4 );
- assert.equal( $("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" );
- assert.equal( $("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" );
+ assert.equal( $( "#table-1" ).offset().top, 6, "jQuery('#table-1').offset().top" );
+ assert.equal( $( "#table-1" ).offset().left, 6, "jQuery('#table-1').offset().left" );
- assert.equal( $("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" );
- assert.equal( $("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" );
-});
+ assert.equal( $( "#th-1" ).offset().top, 10, "jQuery('#th-1').offset().top" );
+ assert.equal( $( "#th-1" ).offset().left, 10, "jQuery('#th-1').offset().left" );
+} );
-testIframe("offset/scroll", "scroll", function( $, win, doc, assert ) {
+testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
assert.expect( 30 );
- assert.equal( $("#scroll-1").offset().top, 7, "jQuery('#scroll-1').offset().top" );
- assert.equal( $("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" );
+ assert.equal( $( "#scroll-1" ).offset().top, 7, "jQuery('#scroll-1').offset().top" );
+ assert.equal( $( "#scroll-1" ).offset().left, 7, "jQuery('#scroll-1').offset().left" );
- assert.equal( $("#scroll-1-1").offset().top, 11, "jQuery('#scroll-1-1').offset().top" );
- assert.equal( $("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
+ assert.equal( $( "#scroll-1-1" ).offset().top, 11, "jQuery('#scroll-1-1').offset().top" );
+ assert.equal( $( "#scroll-1-1" ).offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
// These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
- assert.equal( $("#hidden").offset().top, 0, "Hidden elements do not subtract scroll" );
- assert.equal( $("#hidden").offset().left, 0, "Hidden elements do not subtract scroll" );
+ assert.equal( $( "#hidden" ).offset().top, 0, "Hidden elements do not subtract scroll" );
+ assert.equal( $( "#hidden" ).offset().left, 0, "Hidden elements do not subtract scroll" );
// scroll offset tests .scrollTop/Left
- assert.equal( $("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
- assert.equal( $("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
+ assert.equal( $( "#scroll-1" ).scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
+ assert.equal( $( "#scroll-1" ).scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
- assert.equal( $("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
- assert.equal( $("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
+ assert.equal( $( "#scroll-1-1" ).scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
+ assert.equal( $( "#scroll-1-1" ).scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
// scroll method chaining
- assert.equal( $("#scroll-1").scrollTop(undefined).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" );
- assert.equal( $("#scroll-1").scrollLeft(undefined).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" );
+ assert.equal( $( "#scroll-1" ).scrollTop( undefined ).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" );
+ assert.equal( $( "#scroll-1" ).scrollLeft( undefined ).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" );
win.name = "test";
@@ -441,113 +438,113 @@ testIframe("offset/scroll", "scroll", function( $, win, doc, assert ) {
assert.ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
} else {
- assert.equal( $(win).scrollTop(), 1000, "jQuery(window).scrollTop()" );
- assert.equal( $(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
+ assert.equal( $( win ).scrollTop(), 1000, "jQuery(window).scrollTop()" );
+ assert.equal( $( win ).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
- assert.equal( $(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" );
- assert.equal( $(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
+ assert.equal( $( win.document ).scrollTop(), 1000, "jQuery(document).scrollTop()" );
+ assert.equal( $( win.document ).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
}
// test jQuery using parent window/document
// jQuery reference here is in the iframe
- window.scrollTo(0,0);
- assert.equal( $(window).scrollTop(), 0, "jQuery(window).scrollTop() other window" );
- assert.equal( $(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
- assert.equal( $(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
- assert.equal( $(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
+ window.scrollTo( 0, 0 );
+ assert.equal( $( window ).scrollTop(), 0, "jQuery(window).scrollTop() other window" );
+ assert.equal( $( window ).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
+ assert.equal( $( document ).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
+ assert.equal( $( document ).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
// Tests scrollTop/Left with empty jquery objects
- assert.notEqual( $().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
- assert.notEqual( $().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
- assert.notEqual( $().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
- assert.notEqual( $().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
+ assert.notEqual( $().scrollTop( 100 ), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
+ assert.notEqual( $().scrollLeft( 100 ), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
+ assert.notEqual( $().scrollTop( null ), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
+ assert.notEqual( $().scrollLeft( null ), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
assert.strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
assert.strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
// Tests position after parent scrolling (#15239)
- $("#scroll-1").scrollTop(0);
- $("#scroll-1").scrollLeft(0);
- assert.equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
- assert.equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
-
- $("#scroll-1").scrollTop(5);
- $("#scroll-1").scrollLeft(5);
- assert.equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
- assert.equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
-});
-
-testIframe("offset/body", "body", function( $, window, document, assert ) {
- assert.expect(4);
-
- assert.equal( $("body").offset().top, 1, "jQuery('#body').offset().top" );
- assert.equal( $("body").offset().left, 1, "jQuery('#body').offset().left" );
- assert.equal( $("#firstElement").position().left, 5, "$('#firstElement').position().left" );
- assert.equal( $("#firstElement").position().top, 5, "$('#firstElement').position().top" );
-});
-
-QUnit.test("chaining", function( assert ) {
- assert.expect(3);
+ $( "#scroll-1" ).scrollTop( 0 );
+ $( "#scroll-1" ).scrollLeft( 0 );
+ assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
+ assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
+
+ $( "#scroll-1" ).scrollTop( 5 );
+ $( "#scroll-1" ).scrollLeft( 5 );
+ assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
+ assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
+} );
+
+testIframe( "offset/body", "body", function( $, window, document, assert ) {
+ assert.expect( 4 );
+
+ assert.equal( $( "body" ).offset().top, 1, "jQuery('#body').offset().top" );
+ assert.equal( $( "body" ).offset().left, 1, "jQuery('#body').offset().left" );
+ assert.equal( $( "#firstElement" ).position().left, 5, "$('#firstElement').position().left" );
+ assert.equal( $( "#firstElement" ).position().top, 5, "$('#firstElement').position().top" );
+} );
+
+QUnit.test( "chaining", function( assert ) {
+ assert.expect( 3 );
var coords = { "top": 1, "left": 1 };
- assert.equal( jQuery("#absolute-1").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
- assert.equal( jQuery("#non-existent").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );
- assert.equal( jQuery("#absolute-1").offset(undefined).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" );
-});
+ assert.equal( jQuery( "#absolute-1" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
+ assert.equal( jQuery( "#non-existent" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );
+ assert.equal( jQuery( "#absolute-1" ).offset( undefined ).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" );
+} );
-QUnit.test("offsetParent", function( assert ){
- assert.expect(13);
+QUnit.test( "offsetParent", function( assert ) {
+ assert.expect( 13 );
var body, header, div, area;
- body = jQuery("body").offsetParent();
+ body = jQuery( "body" ).offsetParent();
assert.equal( body.length, 1, "Only one offsetParent found." );
- assert.equal( body[0], document.documentElement, "The html element is the offsetParent of the body." );
+ assert.equal( body[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
- header = jQuery("#qunit").offsetParent();
+ header = jQuery( "#qunit" ).offsetParent();
assert.equal( header.length, 1, "Only one offsetParent found." );
- assert.equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." );
+ assert.equal( header[ 0 ], document.documentElement, "The html element is the offsetParent of #qunit." );
- div = jQuery("#nothiddendivchild").offsetParent();
+ div = jQuery( "#nothiddendivchild" ).offsetParent();
assert.equal( div.length, 1, "Only one offsetParent found." );
- assert.equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
+ assert.equal( div[ 0 ], document.getElementById( "qunit-fixture" ), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
- jQuery("#nothiddendiv").css("position", "relative");
+ jQuery( "#nothiddendiv" ).css( "position", "relative" );
- div = jQuery("#nothiddendivchild").offsetParent();
+ div = jQuery( "#nothiddendivchild" ).offsetParent();
assert.equal( div.length, 1, "Only one offsetParent found." );
- assert.equal( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
+ assert.equal( div[ 0 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." );
- div = jQuery("body, #nothiddendivchild").offsetParent();
+ div = jQuery( "body, #nothiddendivchild" ).offsetParent();
assert.equal( div.length, 2, "Two offsetParent found." );
- assert.equal( div[0], document.documentElement, "The html element is the offsetParent of the body." );
- assert.equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
+ assert.equal( div[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
+ assert.equal( div[ 1 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." );
- area = jQuery("#imgmap area").offsetParent();
- assert.equal( area[0], document.documentElement, "The html element is the offsetParent of the body." );
+ area = jQuery( "#imgmap area" ).offsetParent();
+ assert.equal( area[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
- div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body");
- assert.equal( div.offsetParent()[0], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" );
+ div = jQuery( "<div>" ).css( { "position": "absolute" } ).appendTo( "body" );
+ assert.equal( div.offsetParent()[ 0 ], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" );
div.remove();
-});
+} );
-QUnit.test("fractions (see #7730 and #7885)", function( assert ) {
- assert.expect(2);
+QUnit.test( "fractions (see #7730 and #7885)", function( assert ) {
+ assert.expect( 2 );
- jQuery("body").append("<div id='fractions'/>");
+ jQuery( "body" ).append( "<div id='fractions'/>" );
var result,
expected = { "top": 1000, "left": 1000 },
- div = jQuery("#fractions");
+ div = jQuery( "#fractions" );
- div.css({
+ div.css( {
"position": "absolute",
"left": "1000.7432222px",
"top": "1000.532325px",
"width": 100,
"height": 100
- });
+ } );
- div.offset(expected);
+ div.offset( expected );
result = div.offset();
@@ -555,9 +552,9 @@ QUnit.test("fractions (see #7730 and #7885)", function( assert ) {
assert.equal( result.left, expected.left, "Check left" );
div.remove();
-});
+} );
-QUnit.test("iframe scrollTop/Left (see gh-1945)", function( assert ) {
+QUnit.test( "iframe scrollTop/Left (see gh-1945)", function( assert ) {
assert.expect( 2 );
var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument;
@@ -572,6 +569,7 @@ QUnit.test("iframe scrollTop/Left (see gh-1945)", function( assert ) {
assert.equal( true, true, "Can't scroll iframes in this environment" );
} else {
+
// Tests scrollTop/Left with iframes
jQuery( "#iframe" ).css( "width", "50px" ).css( "height", "50px" );
ifDoc.write( "<div style='width: 1000px; height: 1000px;'></div>" );
@@ -582,6 +580,6 @@ QUnit.test("iframe scrollTop/Left (see gh-1945)", function( assert ) {
assert.equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" );
assert.equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" );
}
-});
+} );
-})();
+} )();
diff --git a/test/unit/queue.js b/test/unit/queue.js
index 42192f3d3..780e20058 100644
--- a/test/unit/queue.js
+++ b/test/unit/queue.js
@@ -1,240 +1,241 @@
-QUnit.module( "queue", { teardown: moduleTeardown });
+QUnit.module( "queue", { teardown: moduleTeardown } );
QUnit.test( "queue() with other types", function( assert ) {
assert.expect( 14 );
QUnit.stop();
- var $div = jQuery({}),
+ var $div = jQuery( {} ),
counter = 0;
- $div.promise( "foo" ).done(function() {
+ $div.promise( "foo" ).done( function() {
assert.equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
- });
+ } );
$div
- .queue("foo",function(){
+ .queue( "foo", function() {
assert.equal( ++counter, 1, "Dequeuing" );
- jQuery.dequeue(this,"foo");
- })
- .queue("foo",function(){
+ jQuery.dequeue( this, "foo" );
+ } )
+ .queue( "foo", function() {
assert.equal( ++counter, 2, "Dequeuing" );
- jQuery(this).dequeue("foo");
- })
- .queue("foo",function(){
+ jQuery( this ).dequeue( "foo" );
+ } )
+ .queue( "foo", function() {
assert.equal( ++counter, 3, "Dequeuing" );
- })
- .queue("foo",function(){
+ } )
+ .queue( "foo", function() {
assert.equal( ++counter, 4, "Dequeuing" );
- });
+ } );
- $div.promise("foo").done(function() {
+ $div.promise( "foo" ).done( function() {
assert.equal( counter, 4, "Testing previous call to dequeue in deferred" );
QUnit.start();
- });
+ } );
- assert.equal( $div.queue("foo").length, 4, "Testing queue length" );
+ assert.equal( $div.queue( "foo" ).length, 4, "Testing queue length" );
- assert.equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)");
+ assert.equal( $div.queue( "foo", undefined ).queue( "foo" ).length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)" );
- $div.dequeue("foo");
+ $div.dequeue( "foo" );
assert.equal( counter, 3, "Testing previous call to dequeue" );
- assert.equal( $div.queue("foo").length, 1, "Testing queue length" );
+ assert.equal( $div.queue( "foo" ).length, 1, "Testing queue length" );
- $div.dequeue("foo");
+ $div.dequeue( "foo" );
assert.equal( counter, 4, "Testing previous call to dequeue" );
- assert.equal( $div.queue("foo").length, 0, "Testing queue length" );
+ assert.equal( $div.queue( "foo" ).length, 0, "Testing queue length" );
- $div.dequeue("foo");
+ $div.dequeue( "foo" );
assert.equal( counter, 4, "Testing previous call to dequeue" );
- assert.equal( $div.queue("foo").length, 0, "Testing queue length" );
+ assert.equal( $div.queue( "foo" ).length, 0, "Testing queue length" );
-});
+} );
-QUnit.test("queue(name) passes in the next item in the queue as a parameter", function( assert ) {
- assert.expect(2);
+QUnit.test( "queue(name) passes in the next item in the queue as a parameter", function( assert ) {
+ assert.expect( 2 );
- var div = jQuery({}),
+ var div = jQuery( {} ),
counter = 0;
- div.queue("foo", function(next) {
- assert.equal(++counter, 1, "Dequeueing");
+ div.queue( "foo", function( next ) {
+ assert.equal( ++counter, 1, "Dequeueing" );
next();
- }).queue("foo", function(next) {
- assert.equal(++counter, 2, "Next was called");
+ } ).queue( "foo", function( next ) {
+ assert.equal( ++counter, 2, "Next was called" );
next();
- }).queue("bar", function() {
- assert.equal(++counter, 3, "Other queues are not triggered by next()");
- });
+ } ).queue( "bar", function() {
+ assert.equal( ++counter, 3, "Other queues are not triggered by next()" );
+ } );
- div.dequeue("foo");
-});
+ div.dequeue( "foo" );
+} );
-QUnit.test("queue() passes in the next item in the queue as a parameter to fx queues", function( assert ) {
- assert.expect(3);
+QUnit.test( "queue() passes in the next item in the queue as a parameter to fx queues", function( assert ) {
+ assert.expect( 3 );
QUnit.stop();
- var div = jQuery({}),
+ var div = jQuery( {} ),
counter = 0;
- div.queue(function(next) {
- assert.equal(++counter, 1, "Dequeueing");
- setTimeout(function() { next(); }, 500);
- }).queue(function(next) {
- assert.equal(++counter, 2, "Next was called");
+ div.queue( function( next ) {
+ assert.equal( ++counter, 1, "Dequeueing" );
+ setTimeout( function() { next(); }, 500 );
+ } ).queue( function( next ) {
+ assert.equal( ++counter, 2, "Next was called" );
next();
- }).queue("bar", function() {
- assert.equal(++counter, 3, "Other queues are not triggered by next()");
- });
+ } ).queue( "bar", function() {
+ assert.equal( ++counter, 3, "Other queues are not triggered by next()" );
+ } );
- jQuery.when( div.promise("fx"), div ).done(function() {
- assert.equal(counter, 2, "Deferreds resolved");
+ jQuery.when( div.promise( "fx" ), div ).done( function() {
+ assert.equal( counter, 2, "Deferreds resolved" );
QUnit.start();
- });
-});
+ } );
+} );
-QUnit.test("callbacks keep their place in the queue", function( assert ) {
- assert.expect(5);
+QUnit.test( "callbacks keep their place in the queue", function( assert ) {
+ assert.expect( 5 );
QUnit.stop();
- var div = jQuery("<div>"),
+ var div = jQuery( "<div>" ),
counter = 0;
- div.queue(function( next ) {
+ div.queue( function( next ) {
assert.equal( ++counter, 1, "Queue/callback order: first called" );
setTimeout( next, 200 );
- }).delay( 100 ).queue(function( next ) {
+ } ).delay( 100 ).queue( function( next ) {
assert.equal( ++counter, 2, "Queue/callback order: second called" );
- jQuery( this ).delay( 100 ).queue(function( next ) {
+ jQuery( this ).delay( 100 ).queue( function( next ) {
assert.equal( ++counter, 4, "Queue/callback order: fourth called" );
next();
- });
+ } );
next();
- }).queue(function( next ) {
+ } ).queue( function( next ) {
assert.equal( ++counter, 3, "Queue/callback order: third called" );
next();
- });
+ } );
- div.promise("fx").done(function() {
- assert.equal(counter, 4, "Deferreds resolved");
+ div.promise( "fx" ).done( function() {
+ assert.equal( counter, 4, "Deferreds resolved" );
QUnit.start();
- });
-});
+ } );
+} );
QUnit.test( "jQuery.queue should return array while manipulating the queue", function( assert ) {
assert.expect( 1 );
- var div = document.createElement("div");
+ var div = document.createElement( "div" );
assert.ok( jQuery.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" );
-});
+} );
-QUnit.test("delay()", function( assert ) {
- assert.expect(2);
+QUnit.test( "delay()", function( assert ) {
+ assert.expect( 2 );
QUnit.stop();
- var foo = jQuery({}), run = 0;
+ var foo = jQuery( {} ), run = 0;
- foo.delay(100).queue(function(){
+ foo.delay( 100 ).queue( function() {
run = 1;
assert.ok( true, "The function was dequeued." );
QUnit.start();
- });
+ } );
assert.equal( run, 0, "The delay delayed the next function from running." );
-});
+} );
-QUnit.test("clearQueue(name) clears the queue", function( assert ) {
- assert.expect(2);
+QUnit.test( "clearQueue(name) clears the queue", function( assert ) {
+ assert.expect( 2 );
QUnit.stop();
- var div = jQuery({}),
+ var div = jQuery( {} ),
counter = 0;
- div.queue("foo", function( next ) {
+ div.queue( "foo", function( next ) {
counter++;
- jQuery(this).clearQueue("foo");
+ jQuery( this ).clearQueue( "foo" );
next();
- }).queue("foo", function() {
+ } ).queue( "foo", function() {
counter++;
- });
+ } );
- div.promise("foo").done(function() {
+ div.promise( "foo" ).done( function() {
assert.ok( true, "dequeue resolves the deferred" );
QUnit.start();
- });
+ } );
- div.dequeue("foo");
+ div.dequeue( "foo" );
- assert.equal(counter, 1, "the queue was cleared");
-});
+ assert.equal( counter, 1, "the queue was cleared" );
+} );
-QUnit.test("clearQueue() clears the fx queue", function( assert ) {
- assert.expect(1);
+QUnit.test( "clearQueue() clears the fx queue", function( assert ) {
+ assert.expect( 1 );
- var div = jQuery({}),
+ 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() {
+ setTimeout( function() { jQuery( self ).clearQueue(); next(); }, 50 );
+ } ).queue( function() {
counter++;
- });
+ } );
- assert.equal(counter, 1, "the queue was cleared");
+ assert.equal( counter, 1, "the queue was cleared" );
div.removeData();
-});
+} );
QUnit.asyncTest( "fn.promise() - called when fx queue is empty", 3, function( assert ) {
var foo = jQuery( "#foo" ).clone().addBack(),
promised = false;
foo.queue( function( next ) {
+
// called twice!
assert.ok( !promised, "Promised hasn't been called" );
setTimeout( next, 10 );
- });
+ } );
foo.promise().done( function() {
assert.ok( promised = true, "Promised" );
QUnit.start();
- });
-});
+ } );
+} );
QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function( assert ) {
var foo = jQuery( "#foo" ),
test;
foo.promise( "queue" ).done( function() {
assert.strictEqual( test, undefined, "called immediately when queue was already empty" );
- });
+ } );
test = 1;
foo.queue( "queue", function( next ) {
assert.strictEqual( test++, 1, "step one" );
setTimeout( next, 0 );
- }).queue( "queue", function( next ) {
+ } ).queue( "queue", function( next ) {
assert.strictEqual( test++, 2, "step two" );
setTimeout( function() {
next();
assert.strictEqual( test++, 4, "step four" );
QUnit.start();
}, 10 );
- }).promise( "queue" ).done( function() {
+ } ).promise( "queue" ).done( function() {
assert.strictEqual( test++, 3, "step three" );
- });
+ } );
foo.dequeue( "queue" );
-});
+} );
QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function( assert ) {
var foo = jQuery( "#foo" ),
test = 1;
- foo.animate({
+ foo.animate( {
top: 100
}, {
duration: 1,
@@ -242,43 +243,42 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete befo
complete: function() {
assert.strictEqual( test++, 1, "step one" );
}
- }).dequeue( "queue" );
+ } ).dequeue( "queue" );
foo.promise( "queue" ).done( function() {
assert.strictEqual( test++, 2, "step two" );
QUnit.start();
- });
+ } );
-});
+} );
QUnit.test( ".promise(obj)", function( assert ) {
- assert.expect(2);
+ assert.expect( 2 );
var obj = {},
promise = jQuery( "#foo" ).promise( "promise", obj );
assert.ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" );
-});
-
+} );
if ( jQuery.fn.stop ) {
- QUnit.test("delay() can be stopped", function( assert ) {
+ QUnit.test( "delay() can be stopped", function( assert ) {
assert.expect( 3 );
QUnit.stop();
var done = {};
- jQuery({})
+ jQuery( {} )
.queue( "alternate", function( next ) {
done.alt1 = true;
assert.ok( true, "This first function was dequeued" );
next();
- })
+ } )
.delay( 1000, "alternate" )
.queue( "alternate", function() {
done.alt2 = true;
assert.ok( true, "The function was dequeued immediately, the delay was stopped" );
- })
+ } )
.dequeue( "alternate" )
// stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
@@ -286,20 +286,20 @@ if ( jQuery.fn.stop ) {
// this test
.delay( 1 )
- .queue(function() {
+ .queue( function() {
done.default1 = true;
assert.ok( false, "This queue should never run" );
- })
+ } )
// stop( clearQueue ) should clear the queue
.stop( true, false );
assert.deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" );
- setTimeout(function() {
+ setTimeout( function() {
QUnit.start();
}, 1500 );
- });
+ } );
QUnit.asyncTest( "queue stop hooks", 2, function( assert ) {
var foo = jQuery( "#foo" );
@@ -308,7 +308,7 @@ if ( jQuery.fn.stop ) {
hooks.stop = function( gotoEnd ) {
assert.equal( !!gotoEnd, false, "Stopped without gotoEnd" );
};
- });
+ } );
foo.stop();
foo.queue( function( next, hooks ) {
@@ -316,9 +316,9 @@ if ( jQuery.fn.stop ) {
assert.equal( gotoEnd, true, "Stopped with gotoEnd" );
QUnit.start();
};
- });
+ } );
foo.stop( false, true );
- });
+ } );
} // if ( jQuery.fn.stop )
diff --git a/test/unit/ready.js b/test/unit/ready.js
index d058466b2..6272dbdd4 100644
--- a/test/unit/ready.js
+++ b/test/unit/ready.js
@@ -1,6 +1,6 @@
QUnit.module( "ready" );
-(function() {
+( function() {
var notYetReady, noEarlyExecution,
order = [],
args = {};
@@ -12,7 +12,7 @@ QUnit.module( "ready" );
assert.equal( notYetReady, true, "jQuery.isReady should not be true before DOM ready" );
assert.equal( jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready" );
- });
+ } );
// Create an event handler.
function makeHandler( testId ) {
@@ -22,7 +22,7 @@ QUnit.module( "ready" );
// the correct arg is being passed into the event handler.
return function( arg ) {
order.push( testId );
- args[testId] = arg;
+ args[ testId ] = arg;
};
}
@@ -65,6 +65,6 @@ QUnit.module( "ready" );
assert.equal( order.pop(), "h", "Event handler should execute immediately" );
assert.equal( args.h, jQuery,
"Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" );
- });
+ } );
-})();
+} )();
diff --git a/test/unit/selector.js b/test/unit/selector.js
index e7f3d85ae..8d18506fe 100644
--- a/test/unit/selector.js
+++ b/test/unit/selector.js
@@ -1,93 +1,93 @@
-QUnit.module("selector", { teardown: moduleTeardown });
+QUnit.module( "selector", { teardown: moduleTeardown } );
/**
* This test page is for selector tests that require jQuery in order to do the selection
*/
-QUnit.test("element - jQuery only", function( assert ) {
+QUnit.test( "element - jQuery only", function( assert ) {
assert.expect( 7 );
- var fixture = document.getElementById("qunit-fixture");
+ var fixture = document.getElementById( "qunit-fixture" );
- assert.deepEqual( jQuery("p", fixture).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a Node context." );
- assert.deepEqual( jQuery("p", "#qunit-fixture").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a selector context." );
- assert.deepEqual( jQuery("p", jQuery("#qunit-fixture")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a jQuery object context." );
- assert.deepEqual( jQuery("#qunit-fixture").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context via .find()." );
+ assert.deepEqual( jQuery( "p", fixture ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a Node context." );
+ assert.deepEqual( jQuery( "p", "#qunit-fixture" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a selector context." );
+ assert.deepEqual( jQuery( "p", jQuery( "#qunit-fixture" ) ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a jQuery object context." );
+ assert.deepEqual( jQuery( "#qunit-fixture" ).find( "p" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a context via .find()." );
- assert.ok( jQuery("#length").length, "<input name=\"length\"> cannot be found under IE, see #945" );
- assert.ok( jQuery("#lengthtest input").length, "<input name=\"length\"> cannot be found under IE, see #945" );
+ assert.ok( jQuery( "#length" ).length, "<input name=\"length\"> cannot be found under IE, see #945" );
+ assert.ok( jQuery( "#lengthtest input" ).length, "<input name=\"length\"> cannot be found under IE, see #945" );
// #7533
- assert.equal( jQuery("<div id=\"A'B~C.D[E]\"><p>foo</p></div>").find("p").length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" );
-});
+ assert.equal( jQuery( "<div id=\"A'B~C.D[E]\"><p>foo</p></div>" ).find( "p" ).length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" );
+} );
-QUnit.test("id", function( assert ) {
+QUnit.test( "id", function( assert ) {
assert.expect( 26 );
var a;
- t( "ID Selector", "#body", ["body"] );
- t( "ID Selector w/ Element", "body#body", ["body"] );
+ t( "ID Selector", "#body", [ "body" ] );
+ t( "ID Selector w/ Element", "body#body", [ "body" ] );
t( "ID Selector w/ Element", "ul#first", [] );
- t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] );
+ t( "ID selector with existing ID descendant", "#firstp #simon1", [ "simon1" ] );
t( "ID selector with non-existent descendant", "#firstp #foobar", [] );
- t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] );
- t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] );
- t( "Descendant ID selector using UTF8", "div #台北", ["台北"] );
- t( "Child ID selector using UTF8", "form > #台北", ["台北"] );
-
- t( "Escaped ID", "#foo\\:bar", ["foo:bar"] );
- t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
- t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] );
- t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
- t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] );
- t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
-
- t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
+ t( "ID selector using UTF8", "#台北Táiběi", [ "台北Táiběi" ] );
+ t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", [ "台北Táiběi","台北" ] );
+ t( "Descendant ID selector using UTF8", "div #台北", [ "台北" ] );
+ t( "Child ID selector using UTF8", "form > #台北", [ "台北" ] );
+
+ t( "Escaped ID", "#foo\\:bar", [ "foo:bar" ] );
+ t( "Escaped ID", "#test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
+ t( "Descendant escaped ID", "div #foo\\:bar", [ "foo:bar" ] );
+ t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
+ t( "Child escaped ID", "form > #foo\\:bar", [ "foo:bar" ] );
+ t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
+
+ t( "ID Selector, child ID present", "#form > #radio1", [ "radio1" ] ); // bug #267
t( "ID Selector, not an ancestor ID", "#form #first", [] );
t( "ID Selector, not a child ID", "#form > #option1a", [] );
- t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] );
+ t( "All Children of ID", "#foo > *", [ "sndp", "en", "sap" ] );
t( "All Children of ID with no children", "#firstUL > *", [] );
- a = jQuery("<a id='backslash\\foo'></a>").appendTo("#qunit-fixture");
- t( "ID Selector contains backslash", "#backslash\\\\foo", ["backslash\\foo"] );
+ a = jQuery( "<a id='backslash\\foo'></a>" ).appendTo( "#qunit-fixture" );
+ t( "ID Selector contains backslash", "#backslash\\\\foo", [ "backslash\\foo" ] );
- t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] );
+ t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", [ "lengthtest" ] );
t( "ID selector with non-existent ancestor", "#asdfasdf #foobar", [] ); // bug #986
- t( "Underscore ID", "#types_all", ["types_all"] );
- t( "Dash ID", "#qunit-fixture", ["qunit-fixture"] );
+ t( "Underscore ID", "#types_all", [ "types_all" ] );
+ t( "Dash ID", "#qunit-fixture", [ "qunit-fixture" ] );
- t( "ID with weird characters in it", "#name\\+value", ["name+value"] );
-});
+ t( "ID with weird characters in it", "#name\\+value", [ "name+value" ] );
+} );
-QUnit.test("class - jQuery only", function( assert ) {
+QUnit.test( "class - jQuery only", function( assert ) {
assert.expect( 4 );
- assert.deepEqual( jQuery(".blog", document.getElementsByTagName("p")).get(), q("mark", "simon"), "Finding elements with a context." );
- assert.deepEqual( jQuery(".blog", "p").get(), q("mark", "simon"), "Finding elements with a context." );
- assert.deepEqual( jQuery(".blog", jQuery("p")).get(), q("mark", "simon"), "Finding elements with a context." );
- assert.deepEqual( jQuery("p").find(".blog").get(), q("mark", "simon"), "Finding elements with a context." );
-});
+ assert.deepEqual( jQuery( ".blog", document.getElementsByTagName( "p" ) ).get(), q( "mark", "simon" ), "Finding elements with a context." );
+ assert.deepEqual( jQuery( ".blog", "p" ).get(), q( "mark", "simon" ), "Finding elements with a context." );
+ assert.deepEqual( jQuery( ".blog", jQuery( "p" ) ).get(), q( "mark", "simon" ), "Finding elements with a context." );
+ assert.deepEqual( jQuery( "p" ).find( ".blog" ).get(), q( "mark", "simon" ), "Finding elements with a context." );
+} );
-QUnit.test("name", function( assert ) {
+QUnit.test( "name", function( assert ) {
assert.expect( 5 );
var form;
- t( "Name selector", "input[name=action]", ["text1"] );
- t( "Name selector with single quotes", "input[name='action']", ["text1"] );
- t( "Name selector with double quotes", "input[name=\"action\"]", ["text1"] );
+ t( "Name selector", "input[name=action]", [ "text1" ] );
+ t( "Name selector with single quotes", "input[name='action']", [ "text1" ] );
+ t( "Name selector with double quotes", "input[name=\"action\"]", [ "text1" ] );
- t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] );
+ t( "Name selector for grouped input", "input[name='types[]']", [ "types_all", "types_anime", "types_movie" ] );
- form = jQuery("<form><input name='id'/></form>").appendTo("body");
- assert.equal( jQuery("input", form[0]).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
+ form = jQuery( "<form><input name='id'/></form>" ).appendTo( "body" );
+ assert.equal( jQuery( "input", form[ 0 ] ).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
form.remove();
-});
+} );
QUnit.test( "selectors with comma", function( assert ) {
assert.expect( 4 );
@@ -98,108 +98,108 @@ QUnit.test( "selectors with comma", function( assert ) {
assert.equal( fixture.find( "h2, div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
assert.equal( fixture.find( "h2 , div p" ).filter( "p" ).length, 2, "has to find two <p>" );
assert.equal( fixture.find( "h2 , div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
-});
+} );
QUnit.test( "child and adjacent", function( assert ) {
assert.expect( 27 );
var nothiddendiv;
- t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
- t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
- t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
- t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
- t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
- t( "All Children", "code > *", ["anchor1","anchor2"] );
- t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
- t( "Adjacent", "p + p", ["ap","en","sap"] );
- t( "Adjacent", "p#firstp + p", ["ap"] );
- t( "Adjacent", "p[lang=en] + p", ["sap"] );
- t( "Adjacent", "a.GROUPS + code + a", ["mark"] );
- t( "Element Preceded By", "#groups ~ a", ["mark"] );
- t( "Element Preceded By", "#length ~ input", ["idTest"] );
- t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext", "siblingthird"] );
- t( "Element Preceded By (multiple)", "#siblingTest em ~ em ~ em ~ span", ["siblingspan"] );
- t( "Element Preceded By, Containing", "#liveHandlerOrder ~ div em:contains('1')", ["siblingfirst"] );
-
- t( "Multiple combinators selects all levels", "#siblingTest em *", ["siblingchild", "siblinggrandchild", "siblinggreatgrandchild"] );
- t( "Multiple combinators selects all levels", "#siblingTest > em *", ["siblingchild", "siblinggrandchild", "siblinggreatgrandchild"] );
- t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", ["siblingspan"] );
+ t( "Child", "p > a", [ "simon1","google","groups","mark","yahoo","simon" ] );
+ t( "Child", "p> a", [ "simon1","google","groups","mark","yahoo","simon" ] );
+ t( "Child", "p >a", [ "simon1","google","groups","mark","yahoo","simon" ] );
+ t( "Child", "p>a", [ "simon1","google","groups","mark","yahoo","simon" ] );
+ t( "Child w/ Class", "p > a.blog", [ "mark","simon" ] );
+ t( "All Children", "code > *", [ "anchor1","anchor2" ] );
+ t( "All Grandchildren", "p > * > *", [ "anchor1","anchor2" ] );
+ t( "Adjacent", "p + p", [ "ap","en","sap" ] );
+ t( "Adjacent", "p#firstp + p", [ "ap" ] );
+ t( "Adjacent", "p[lang=en] + p", [ "sap" ] );
+ t( "Adjacent", "a.GROUPS + code + a", [ "mark" ] );
+ t( "Element Preceded By", "#groups ~ a", [ "mark" ] );
+ t( "Element Preceded By", "#length ~ input", [ "idTest" ] );
+ t( "Element Preceded By", "#siblingfirst ~ em", [ "siblingnext", "siblingthird" ] );
+ t( "Element Preceded By (multiple)", "#siblingTest em ~ em ~ em ~ span", [ "siblingspan" ] );
+ t( "Element Preceded By, Containing", "#liveHandlerOrder ~ div em:contains('1')", [ "siblingfirst" ] );
+
+ t( "Multiple combinators selects all levels", "#siblingTest em *", [ "siblingchild", "siblinggrandchild", "siblinggreatgrandchild" ] );
+ t( "Multiple combinators selects all levels", "#siblingTest > em *", [ "siblingchild", "siblinggrandchild", "siblinggreatgrandchild" ] );
+ t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", [ "siblingspan" ] );
t( "Combinators are not skipped when mixing general and specific", "#siblingTest > em:contains('x') + em ~ span", [] );
- assert.equal( jQuery("#listWithTabIndex").length, 1, "Parent div for next test is found via ID (#8310)" );
- assert.equal( jQuery("#listWithTabIndex li:eq(2) ~ li").length, 1, "Find by general sibling combinator (#8310)" );
- assert.equal( jQuery("#__sizzle__").length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" );
- assert.equal( jQuery("#listWithTabIndex").length, 1, "Parent div for previous test is still found via ID (#8310)" );
+ assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for next test is found via ID (#8310)" );
+ assert.equal( jQuery( "#listWithTabIndex li:eq(2) ~ li" ).length, 1, "Find by general sibling combinator (#8310)" );
+ assert.equal( jQuery( "#__sizzle__" ).length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" );
+ assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for previous test is still found via ID (#8310)" );
t( "Verify deep class selector", "div.blah > p > a", [] );
t( "No element deep selector", "div.foo > span > a", [] );
- nothiddendiv = document.getElementById("nothiddendiv");
+ nothiddendiv = document.getElementById( "nothiddendiv" );
t( "Non-existent ancestors", ".fototab > .thumbnails > a", [] );
-});
+} );
-QUnit.test("attributes", function( assert ) {
+QUnit.test( "attributes", function( assert ) {
assert.expect( 54 );
var attrbad, div, withScript;
- t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] );
+ t( "Find elements with a tabindex attribute", "[tabindex]", [ "listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex" ] );
- t( "Attribute Exists", "#qunit-fixture a[title]", ["google"] );
- t( "Attribute Exists (case-insensitive)", "#qunit-fixture a[TITLE]", ["google"] );
- t( "Attribute Exists", "#qunit-fixture *[title]", ["google"] );
- t( "Attribute Exists", "#qunit-fixture [title]", ["google"] );
- t( "Attribute Exists", "#qunit-fixture a[ title ]", ["google"] );
+ t( "Attribute Exists", "#qunit-fixture a[title]", [ "google" ] );
+ t( "Attribute Exists (case-insensitive)", "#qunit-fixture a[TITLE]", [ "google" ] );
+ t( "Attribute Exists", "#qunit-fixture *[title]", [ "google" ] );
+ t( "Attribute Exists", "#qunit-fixture [title]", [ "google" ] );
+ t( "Attribute Exists", "#qunit-fixture a[ title ]", [ "google" ] );
- t( "Boolean attribute exists", "#select2 option[selected]", ["option2d"]);
- t( "Boolean attribute equals", "#select2 option[selected='selected']", ["option2d"]);
+ t( "Boolean attribute exists", "#select2 option[selected]", [ "option2d" ] );
+ t( "Boolean attribute equals", "#select2 option[selected='selected']", [ "option2d" ] );
- t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] );
- t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] );
- t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", ["simon1"] );
- t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", ["google"] );
- t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", ["simon1"] );
- t( "Attribute Equals Number", "#qunit-fixture option[value=1]", ["option1b","option2b","option3b","option4b","option5c"] );
- t( "Attribute Equals Number", "#qunit-fixture li[tabIndex=-1]", ["foodWithNegativeTabIndex"] );
+ t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", [ "simon1" ] );
+ t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", [ "simon1" ] );
+ t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", [ "simon1" ] );
+ t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", [ "google" ] );
+ t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", [ "simon1" ] );
+ t( "Attribute Equals Number", "#qunit-fixture option[value=1]", [ "option1b","option2b","option3b","option4b","option5c" ] );
+ t( "Attribute Equals Number", "#qunit-fixture li[tabIndex=-1]", [ "foodWithNegativeTabIndex" ] );
- document.getElementById("anchor2").href = "#2";
- t( "href Attribute", "p a[href^='#']", ["anchor2"] );
- t( "href Attribute", "p a[href*='#']", ["simon1", "anchor2"] );
+ document.getElementById( "anchor2" ).href = "#2";
+ t( "href Attribute", "p a[href^='#']", [ "anchor2" ] );
+ t( "href Attribute", "p a[href*='#']", [ "simon1", "anchor2" ] );
- t( "for Attribute", "form label[for]", ["label-for"] );
- t( "for Attribute in form", "#form [for=action]", ["label-for"] );
+ t( "for Attribute", "form label[for]", [ "label-for" ] );
+ t( "for Attribute in form", "#form [for=action]", [ "label-for" ] );
- t( "Attribute containing []", "input[name^='foo[']", ["hidden2"] );
- t( "Attribute containing []", "input[name^='foo[bar]']", ["hidden2"] );
- t( "Attribute containing []", "input[name*='[bar]']", ["hidden2"] );
- t( "Attribute containing []", "input[name$='bar]']", ["hidden2"] );
- t( "Attribute containing []", "input[name$='[bar]']", ["hidden2"] );
- t( "Attribute containing []", "input[name$='foo[bar]']", ["hidden2"] );
- t( "Attribute containing []", "input[name*='foo[bar]']", ["hidden2"] );
+ t( "Attribute containing []", "input[name^='foo[']", [ "hidden2" ] );
+ t( "Attribute containing []", "input[name^='foo[bar]']", [ "hidden2" ] );
+ t( "Attribute containing []", "input[name*='[bar]']", [ "hidden2" ] );
+ t( "Attribute containing []", "input[name$='bar]']", [ "hidden2" ] );
+ t( "Attribute containing []", "input[name$='[bar]']", [ "hidden2" ] );
+ t( "Attribute containing []", "input[name$='foo[bar]']", [ "hidden2" ] );
+ t( "Attribute containing []", "input[name*='foo[bar]']", [ "hidden2" ] );
- t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type='hidden']", ["radio1", "radio2", "hidden1"] );
- t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=\"hidden\"]", ["radio1", "radio2", "hidden1"] );
- t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=hidden]", ["radio1", "radio2", "hidden1"] );
+ t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type='hidden']", [ "radio1", "radio2", "hidden1" ] );
+ t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=\"hidden\"]", [ "radio1", "radio2", "hidden1" ] );
+ t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=hidden]", [ "radio1", "radio2", "hidden1" ] );
- t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] );
+ t( "Attribute selector using UTF8", "span[lang=中文]", [ "台北" ] );
- t( "Attribute Begins With", "a[href ^= 'http://www']", ["google","yahoo"] );
- t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] );
- t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] );
- t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", ["google","groups","anchor1"] );
+ t( "Attribute Begins With", "a[href ^= 'http://www']", [ "google","yahoo" ] );
+ t( "Attribute Ends With", "a[href $= 'org/']", [ "mark" ] );
+ t( "Attribute Contains", "a[href *= 'google']", [ "google","groups" ] );
+ t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", [ "google","groups","anchor1" ] );
- t( "Empty values", "#select1 option[value='']", ["option1a"] );
- t( "Empty values", "#select1 option[value!='']", ["option1b","option1c","option1d"] );
+ t( "Empty values", "#select1 option[value='']", [ "option1a" ] );
+ t( "Empty values", "#select1 option[value!='']", [ "option1b","option1c","option1d" ] );
- t( "Select options via :selected", "#select1 option:selected", ["option1a"] );
- t( "Select options via :selected", "#select2 option:selected", ["option2d"] );
- t( "Select options via :selected", "#select3 option:selected", ["option3b", "option3c"] );
- t( "Select options via :selected", "select[name='select2'] option:selected", ["option2d"] );
+ t( "Select options via :selected", "#select1 option:selected", [ "option1a" ] );
+ t( "Select options via :selected", "#select2 option:selected", [ "option2d" ] );
+ t( "Select options via :selected", "#select3 option:selected", [ "option3b", "option3c" ] );
+ t( "Select options via :selected", "select[name='select2'] option:selected", [ "option2d" ] );
- t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] );
+ t( "Grouped Form Elements", "input[name='foo[bar]']", [ "hidden2" ] );
// Make sure attribute value quoting works correctly. See jQuery #6093; #6428; #13894
// Use seeded results to bypass querySelectorAll optimizations
@@ -213,63 +213,63 @@ QUnit.test("attributes", function( assert ) {
"<input type='hidden' id='attrbad_backslash_quote' data-attr='&#92;&#39;'/>" +
"<input type='hidden' id='attrbad_backslash_backslash' data-attr='&#92;&#92;'/>" +
"<input type='hidden' id='attrbad_unicode' data-attr='&#x4e00;'/>"
- ).appendTo("#qunit-fixture").get();
+ ).appendTo( "#qunit-fixture" ).get();
- t( "Underscores don't need escaping", "input[id=types_all]", ["types_all"] );
+ t( "Underscores don't need escaping", "input[id=types_all]", [ "types_all" ] );
- t( "input[type=text]", "#form input[type=text]", ["text1", "text2", "hidden2", "name"] );
- t( "input[type=search]", "#form input[type=search]", ["search"] );
+ t( "input[type=text]", "#form input[type=text]", [ "text1", "text2", "hidden2", "name" ] );
+ t( "input[type=search]", "#form input[type=search]", [ "search" ] );
withScript = supportjQuery( "<div><span><script src=''/></span></div>" );
assert.ok( withScript.find( "#moretests script[src]" ).has( "script" ), "script[src] (jQuery #13777)" );
- div = document.getElementById("foo");
+ div = document.getElementById( "foo" );
t( "Object.prototype property \"constructor\" (negative)", "[constructor]", [] );
t( "Gecko Object.prototype property \"watch\" (negative)", "[watch]", [] );
div.setAttribute( "constructor", "foo" );
div.setAttribute( "watch", "bar" );
- t( "Object.prototype property \"constructor\"", "[constructor='foo']", ["foo"] );
- t( "Gecko Object.prototype property \"watch\"", "[watch='bar']", ["foo"] );
+ t( "Object.prototype property \"constructor\"", "[constructor='foo']", [ "foo" ] );
+ t( "Gecko Object.prototype property \"watch\"", "[watch='bar']", [ "foo" ] );
- t( "Value attribute is retrieved correctly", "input[value=Test]", ["text1", "text2"] );
+ t( "Value attribute is retrieved correctly", "input[value=Test]", [ "text1", "text2" ] );
// #12600
assert.ok(
- jQuery("<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>")
+ jQuery( "<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>" )
.prop( "value", "option" )
- .is(":input[value='12600']"),
+ .is( ":input[value='12600']" ),
":input[value=foo] selects select by attribute"
);
- assert.ok( jQuery("<input type='text' value='12600'/>").prop( "value", "option" ).is(":input[value='12600']"),
+ assert.ok( jQuery( "<input type='text' value='12600'/>" ).prop( "value", "option" ).is( ":input[value='12600']" ),
":input[value=foo] selects text input by attribute"
);
// #11115
- assert.ok( jQuery("<input type='checkbox' checked='checked'/>").prop( "checked", false ).is("[checked]"),
+ assert.ok( jQuery( "<input type='checkbox' checked='checked'/>" ).prop( "checked", false ).is( "[checked]" ),
"[checked] selects by attribute (positive)"
);
- assert.ok( !jQuery("<input type='checkbox'/>").prop( "checked", true ).is("[checked]"),
+ assert.ok( !jQuery( "<input type='checkbox'/>" ).prop( "checked", true ).is( "[checked]" ),
"[checked] selects by attribute (negative)"
);
-});
+} );
-QUnit.test("disconnected nodes", function( assert ) {
+QUnit.test( "disconnected nodes", function( assert ) {
assert.expect( 1 );
- var $div = jQuery("<div/>");
- assert.equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." );
-});
+ var $div = jQuery( "<div/>" );
+ assert.equal( $div.is( "div" ), true, "Make sure .is('nodeName') works on disconnected nodes." );
+} );
-QUnit.test("disconnected nodes - jQuery only", function( assert ) {
+QUnit.test( "disconnected nodes - jQuery only", function( assert ) {
assert.expect( 3 );
- var $opt = jQuery("<option></option>").attr("value", "whipit").appendTo("#qunit-fixture").detach();
+ var $opt = jQuery( "<option></option>" ).attr( "value", "whipit" ).appendTo( "#qunit-fixture" ).detach();
assert.equal( $opt.val(), "whipit", "option value" );
- assert.equal( $opt.is(":selected"), false, "unselected option" );
- $opt.prop("selected", true);
- assert.equal( $opt.is(":selected"), true, "selected option" );
-});
+ assert.equal( $opt.is( ":selected" ), false, "unselected option" );
+ $opt.prop( "selected", true );
+ assert.equal( $opt.is( ":selected" ), true, "selected option" );
+} );
testIframe(
"selector/html5_selector",
@@ -286,7 +286,7 @@ testIframe(
i = 0;
for ( ; i < arguments.length; i++ ) {
- r.push( document.getElementById( arguments[i] ) );
+ r.push( document.getElementById( arguments[ i ] ) );
}
return r;
}
@@ -299,15 +299,15 @@ testIframe(
* @param {Array} c - Array of ids to construct what is expected
*/
function t( a, b, c ) {
- var f = jQuery(b).get(),
+ var f = jQuery( b ).get(),
s = "",
i = 0;
for ( ; i < f.length; i++ ) {
- s += (s && ",") + "'" + f[i].id + "'";
+ s += ( s && "," ) + "'" + f[ i ].id + "'";
}
- assert.deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
+ assert.deepEqual( f, q.apply( q, c ), a + " (" + b + ")" );
}
// ====== All known boolean attributes, including html5 booleans ======
@@ -318,79 +318,79 @@ testIframe(
// noshade, nowrap, novalidate, open, pubdate, readonly, required,
// reversed, scoped, seamless, selected, truespeed, visible (skipping visible attribute, which is on a barprop object)
- t( "Attribute Exists", "[autobuffer]", ["video1"]);
- t( "Attribute Exists", "[autofocus]", ["text1"]);
- t( "Attribute Exists", "[autoplay]", ["video1"]);
- t( "Attribute Exists", "[async]", ["script1"]);
- t( "Attribute Exists", "[checked]", ["check1"]);
- t( "Attribute Exists", "[compact]", ["dl"]);
- t( "Attribute Exists", "[controls]", ["video1"]);
- t( "Attribute Exists", "[declare]", ["object1"]);
- t( "Attribute Exists", "[defer]", ["script1"]);
- t( "Attribute Exists", "[disabled]", ["check1"]);
- t( "Attribute Exists", "[formnovalidate]", ["form1"]);
- t( "Attribute Exists", "[hidden]", ["div1"]);
- t( "Attribute Exists", "[indeterminate]", []);
- t( "Attribute Exists", "[ismap]", ["img1"]);
- t( "Attribute Exists", "[itemscope]", ["div1"]);
- t( "Attribute Exists", "[loop]", ["video1"]);
- t( "Attribute Exists", "[multiple]", ["select1"]);
- t( "Attribute Exists", "[muted]", ["audio1"]);
- t( "Attribute Exists", "[nohref]", ["area1"]);
- t( "Attribute Exists", "[noresize]", ["textarea1"]);
- t( "Attribute Exists", "[noshade]", ["hr1"]);
- t( "Attribute Exists", "[nowrap]", ["td1", "div1"]);
- t( "Attribute Exists", "[novalidate]", ["form1"]);
- t( "Attribute Exists", "[open]", ["details1"]);
- t( "Attribute Exists", "[pubdate]", ["article1"]);
- t( "Attribute Exists", "[readonly]", ["text1"]);
- t( "Attribute Exists", "[required]", ["text1"]);
- t( "Attribute Exists", "[reversed]", ["ol1"]);
- t( "Attribute Exists", "[scoped]", ["style1"]);
- t( "Attribute Exists", "[seamless]", ["iframe1"]);
- t( "Attribute Exists", "[selected]", ["option1"]);
- t( "Attribute Exists", "[truespeed]", ["marquee1"]);
+ t( "Attribute Exists", "[autobuffer]", [ "video1" ] );
+ t( "Attribute Exists", "[autofocus]", [ "text1" ] );
+ t( "Attribute Exists", "[autoplay]", [ "video1" ] );
+ t( "Attribute Exists", "[async]", [ "script1" ] );
+ t( "Attribute Exists", "[checked]", [ "check1" ] );
+ t( "Attribute Exists", "[compact]", [ "dl" ] );
+ t( "Attribute Exists", "[controls]", [ "video1" ] );
+ t( "Attribute Exists", "[declare]", [ "object1" ] );
+ t( "Attribute Exists", "[defer]", [ "script1" ] );
+ t( "Attribute Exists", "[disabled]", [ "check1" ] );
+ t( "Attribute Exists", "[formnovalidate]", [ "form1" ] );
+ t( "Attribute Exists", "[hidden]", [ "div1" ] );
+ t( "Attribute Exists", "[indeterminate]", [] );
+ t( "Attribute Exists", "[ismap]", [ "img1" ] );
+ t( "Attribute Exists", "[itemscope]", [ "div1" ] );
+ t( "Attribute Exists", "[loop]", [ "video1" ] );
+ t( "Attribute Exists", "[multiple]", [ "select1" ] );
+ t( "Attribute Exists", "[muted]", [ "audio1" ] );
+ t( "Attribute Exists", "[nohref]", [ "area1" ] );
+ t( "Attribute Exists", "[noresize]", [ "textarea1" ] );
+ t( "Attribute Exists", "[noshade]", [ "hr1" ] );
+ t( "Attribute Exists", "[nowrap]", [ "td1", "div1" ] );
+ t( "Attribute Exists", "[novalidate]", [ "form1" ] );
+ t( "Attribute Exists", "[open]", [ "details1" ] );
+ t( "Attribute Exists", "[pubdate]", [ "article1" ] );
+ t( "Attribute Exists", "[readonly]", [ "text1" ] );
+ t( "Attribute Exists", "[required]", [ "text1" ] );
+ t( "Attribute Exists", "[reversed]", [ "ol1" ] );
+ t( "Attribute Exists", "[scoped]", [ "style1" ] );
+ t( "Attribute Exists", "[seamless]", [ "iframe1" ] );
+ t( "Attribute Exists", "[selected]", [ "option1" ] );
+ t( "Attribute Exists", "[truespeed]", [ "marquee1" ] );
// Enumerated attributes (these are not boolean content attributes)
jQuery.expandedEach = jQuery.each;
- jQuery.expandedEach([ "draggable", "contenteditable", "aria-disabled" ], function( i, val ) {
- t( "Enumerated attribute", "[" + val + "]", ["div1"]);
- });
- t( "Enumerated attribute", "[spellcheck]", ["span1"]);
+ jQuery.expandedEach( [ "draggable", "contenteditable", "aria-disabled" ], function( i, val ) {
+ t( "Enumerated attribute", "[" + val + "]", [ "div1" ] );
+ } );
+ t( "Enumerated attribute", "[spellcheck]", [ "span1" ] );
t( "tabindex selector does not retrieve all elements in IE6/7 (#8473)",
"form, [tabindex]", [ "form1", "text1" ] );
- t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", ["form1"] );
+ t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", [ "form1" ] );
}
);
QUnit.test( "jQuery.contains", function( assert ) {
assert.expect( 16 );
- var container = document.getElementById("nonnodes"),
+ var container = document.getElementById( "nonnodes" ),
element = container.firstChild,
text = element.nextSibling,
nonContained = container.nextSibling,
- detached = document.createElement("a");
+ detached = document.createElement( "a" );
assert.ok( element && element.nodeType === 1, "preliminary: found element" );
assert.ok( text && text.nodeType === 3, "preliminary: found text" );
assert.ok( nonContained, "preliminary: found non-descendant" );
- assert.ok( jQuery.contains(container, element), "child" );
- assert.ok( jQuery.contains(container.parentNode, element), "grandchild" );
- assert.ok( jQuery.contains(container, text), "text child" );
- assert.ok( jQuery.contains(container.parentNode, text), "text grandchild" );
- assert.ok( !jQuery.contains(container, container), "self" );
- assert.ok( !jQuery.contains(element, container), "parent" );
- assert.ok( !jQuery.contains(container, nonContained), "non-descendant" );
- assert.ok( !jQuery.contains(container, document), "document" );
- assert.ok( !jQuery.contains(container, document.documentElement), "documentElement (negative)" );
- assert.ok( !jQuery.contains(container, null), "Passing null does not throw an error" );
- assert.ok( jQuery.contains(document, document.documentElement), "documentElement (positive)" );
- assert.ok( jQuery.contains(document, element), "document container (positive)" );
- assert.ok( !jQuery.contains(document, detached), "document container (negative)" );
-});
-
-QUnit.test("jQuery.uniqueSort", function( assert ) {
+ assert.ok( jQuery.contains( container, element ), "child" );
+ assert.ok( jQuery.contains( container.parentNode, element ), "grandchild" );
+ assert.ok( jQuery.contains( container, text ), "text child" );
+ assert.ok( jQuery.contains( container.parentNode, text ), "text grandchild" );
+ assert.ok( !jQuery.contains( container, container ), "self" );
+ assert.ok( !jQuery.contains( element, container ), "parent" );
+ assert.ok( !jQuery.contains( container, nonContained ), "non-descendant" );
+ assert.ok( !jQuery.contains( container, document ), "document" );
+ assert.ok( !jQuery.contains( container, document.documentElement ), "documentElement (negative)" );
+ assert.ok( !jQuery.contains( container, null ), "Passing null does not throw an error" );
+ assert.ok( jQuery.contains( document, document.documentElement ), "documentElement (positive)" );
+ assert.ok( jQuery.contains( document, element ), "document container (positive)" );
+ assert.ok( !jQuery.contains( document, detached ), "document container (negative)" );
+} );
+
+QUnit.test( "jQuery.uniqueSort", function( assert ) {
assert.expect( 15 );
function Arrayish( arr ) {
@@ -408,16 +408,16 @@ QUnit.test("jQuery.uniqueSort", function( assert ) {
var i, tests,
detached = [],
body = document.body,
- fixture = document.getElementById("qunit-fixture"),
- detached1 = document.createElement("p"),
- detached2 = document.createElement("ul"),
- detachedChild = detached1.appendChild( document.createElement("a") ),
- detachedGrandchild = detachedChild.appendChild( document.createElement("b") );
+ fixture = document.getElementById( "qunit-fixture" ),
+ detached1 = document.createElement( "p" ),
+ detached2 = document.createElement( "ul" ),
+ detachedChild = detached1.appendChild( document.createElement( "a" ) ),
+ detachedGrandchild = detachedChild.appendChild( document.createElement( "b" ) );
for ( i = 0; i < 12; i++ ) {
- detached.push( document.createElement("li") );
- detached[i].id = "detached" + i;
- detached2.appendChild( document.createElement("li") ).id = "detachedChild" + i;
+ detached.push( document.createElement( "li" ) );
+ detached[ i ].id = "detached" + i;
+ detached2.appendChild( document.createElement( "li" ) ).id = "detachedChild" + i;
}
tests = {
@@ -443,16 +443,16 @@ QUnit.test("jQuery.uniqueSort", function( assert ) {
},
"Detached children": {
input: [
- detached2.childNodes[0],
- detached2.childNodes[1],
- detached2.childNodes[2],
- detached2.childNodes[3]
+ detached2.childNodes[ 0 ],
+ detached2.childNodes[ 1 ],
+ detached2.childNodes[ 2 ],
+ detached2.childNodes[ 3 ]
],
expected: [
- detached2.childNodes[0],
- detached2.childNodes[1],
- detached2.childNodes[2],
- detached2.childNodes[3]
+ detached2.childNodes[ 0 ],
+ detached2.childNodes[ 1 ],
+ detached2.childNodes[ 2 ],
+ detached2.childNodes[ 3 ]
]
},
"Attached/detached mixture": {
@@ -465,23 +465,23 @@ QUnit.test("jQuery.uniqueSort", function( assert ) {
jQuery.each( tests, function( label, test ) {
var length = test.length || test.input.length;
assert.deepEqual( jQuery.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" );
- assert.deepEqual( jQuery.uniqueSort( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" );
- });
+ assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).slice( 0, length ), test.expected, label + " (quasi-array)" );
+ } );
assert.strictEqual( jQuery.unique, jQuery.uniqueSort, "jQuery.unique() is an alias for jQuery.uniqueSort()" );
-});
+} );
testIframe(
"selector/sizzle_cache",
"Sizzle cache collides with multiple Sizzles on a page",
function( jQuery, window, document, assert ) {
- var $cached = window["$cached"];
+ var $cached = window[ "$cached" ];
- assert.expect(4);
+ assert.expect( 4 );
assert.notStrictEqual( jQuery, $cached, "Loaded two engines" );
- assert.deepEqual( $cached(".test a").get(), [ document.getElementById("collision") ], "Select collision anchor with first sizzle" );
- assert.equal( jQuery(".evil a").length, 0, "Select nothing with second sizzle" );
- assert.equal( jQuery(".evil a").length, 0, "Select nothing again with second sizzle" );
+ assert.deepEqual( $cached( ".test a" ).get(), [ document.getElementById( "collision" ) ], "Select collision anchor with first sizzle" );
+ assert.equal( jQuery( ".evil a" ).length, 0, "Select nothing with second sizzle" );
+ assert.equal( jQuery( ".evil a" ).length, 0, "Select nothing again with second sizzle" );
}
);
@@ -512,9 +512,9 @@ QUnit.asyncTest( "Iframe dispatch should not affect jQuery (#13936)", 1, functio
loaded = true;
form.submit();
}
- });
+ } );
iframeDoc.open();
iframeDoc.write( "<body><form id='navigate' action='?'></form></body>" );
iframeDoc.close();
-});
+} );
diff --git a/test/unit/serialize.js b/test/unit/serialize.js
index a650f5456..047861530 100644
--- a/test/unit/serialize.js
+++ b/test/unit/serialize.js
@@ -1,43 +1,43 @@
-QUnit.module("serialize", { teardown: moduleTeardown });
+QUnit.module( "serialize", { teardown: moduleTeardown } );
-QUnit.test("jQuery.param()", function( assert ) {
- assert.expect(22);
+QUnit.test( "jQuery.param()", function( assert ) {
+ assert.expect( 22 );
var params, settings;
assert.equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" );
- params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
- assert.equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
+ params = { "foo":"bar", "baz":42, "quux":"All your base are belong to us" };
+ assert.equal( jQuery.param( params ), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
- params = {"string":"foo","null":null,"undefined":undefined};
- assert.equal( jQuery.param(params), "string=foo&null=&undefined=", "handle nulls and undefineds properly" );
+ params = { "string":"foo","null":null,"undefined":undefined };
+ assert.equal( jQuery.param( params ), "string=foo&null=&undefined=", "handle nulls and undefineds properly" );
- params = {"someName": [1, 2, 3], "regularThing": "blah" };
- assert.equal( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
+ params = { "someName": [ 1, 2, 3 ], "regularThing": "blah" };
+ assert.equal( jQuery.param( params ), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
- params = {"foo": ["a", "b", "c"]};
- assert.equal( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
+ params = { "foo": [ "a", "b", "c" ] };
+ assert.equal( jQuery.param( params ), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
- params = {"foo": ["baz", 42, "All your base are belong to us"] };
- assert.equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
+ params = { "foo": [ "baz", 42, "All your base are belong to us" ] };
+ assert.equal( jQuery.param( params ), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
- params = {"foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } };
- assert.equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
+ params = { "foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } };
+ assert.equal( jQuery.param( params ), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
- params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
- assert.equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" );
+ params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" };
+ assert.equal( decodeURIComponent( jQuery.param( params ) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, "d": 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
- assert.equal( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
+ assert.equal( decodeURIComponent( jQuery.param( params ) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
- params = { "a":[1,2], "b":{ "c":3, "d":[4,5], "e":{ "x":[6], "y":7, "z":[8,9] }, "f":true, "g":false, "h":undefined }, "i":[10,11], "j":true, "k":false, "l":[undefined,0], "m":"cowboy hat?" };
- assert.equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
+ params = { "a":[ 1,2 ], "b":{ "c":3, "d":[ 4,5 ], "e":{ "x":[ 6 ], "y":7, "z":[ 8,9 ] }, "f":true, "g":false, "h":undefined }, "i":[ 10,11 ], "j":true, "k":false, "l":[ undefined,0 ], "m":"cowboy hat?" };
+ assert.equal( jQuery.param( params, true ), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
- assert.equal( decodeURIComponent( jQuery.param({ "a": [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], "e": { "f": [10], "g": [11,12], "h": 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
+ assert.equal( decodeURIComponent( jQuery.param( { "a": [ 1,2,3 ], "b[]": [ 4,5,6 ], "c[d]": [ 7,8,9 ], "e": { "f": [ 10 ], "g": [ 11,12 ], "h": 13 } } ) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
// #7945
- assert.equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
+ assert.equal( jQuery.param( { "jquery": "1.4.2" } ), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
settings = { traditional: true };
@@ -47,58 +47,58 @@ QUnit.test("jQuery.param()", function( assert ) {
jQuery.ajaxSettings = settings;
}
- params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
- assert.equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
+ params = { "foo":"bar", "baz":42, "quux":"All your base are belong to us" };
+ assert.equal( jQuery.param( params ), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
- params = {"someName": [1, 2, 3], "regularThing": "blah" };
- assert.equal( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
+ params = { "someName": [ 1, 2, 3 ], "regularThing": "blah" };
+ assert.equal( jQuery.param( params ), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
- params = {"foo": ["a", "b", "c"]};
- assert.equal( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
+ params = { "foo": [ "a", "b", "c" ] };
+ assert.equal( jQuery.param( params ), "foo=a&foo=b&foo=c", "with array of strings" );
- params = {"foo[]":["baz", 42, "All your base are belong to us"]};
- assert.equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
+ params = { "foo[]":[ "baz", 42, "All your base are belong to us" ] };
+ assert.equal( jQuery.param( params ), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
- params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
- assert.equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
+ params = { "foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us" };
+ assert.equal( jQuery.param( params ), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
- params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
- assert.equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" );
+ params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" };
+ assert.equal( jQuery.param( params ), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
- assert.equal( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
+ assert.equal( jQuery.param( params ), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
- params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
- assert.equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
+ params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" };
+ assert.equal( decodeURIComponent( jQuery.param( params, false ) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
params = { "param1": null };
- assert.equal( jQuery.param(params,false), "param1=", "Make sure that null params aren't traversed." );
+ assert.equal( jQuery.param( params, false ), "param1=", "Make sure that null params aren't traversed." );
- params = {"test": {"length": 3, "foo": "bar"} };
+ params = { "test": { "length": 3, "foo": "bar" } };
assert.equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
if ( jQuery.ajaxSettings === settings ) {
delete jQuery.ajaxSettings;
} else {
- jQuery.ajaxSetup({ traditional: false });
+ jQuery.ajaxSetup( { traditional: false } );
}
-});
+} );
-QUnit.test("jQuery.param() Constructed prop values", function( assert ) {
+QUnit.test( "jQuery.param() Constructed prop values", function( assert ) {
assert.expect( 4 );
/** @constructor */
function Record() {
- this["prop"] = "val";
+ this[ "prop" ] = "val";
}
var MyString = String,
MyNumber = Number,
- params = { "test": new MyString("foo") };
+ params = { "test": new MyString( "foo" ) };
assert.equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" );
- params = { "test": new MyNumber(5) };
+ params = { "test": new MyNumber( 5 ) };
assert.equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
params = { "test": new Date() };
@@ -106,41 +106,41 @@ QUnit.test("jQuery.param() Constructed prop values", function( assert ) {
// should allow non-native constructed objects
params = { "test": new Record() };
- assert.equal( jQuery.param( params, false ), jQuery.param({ "test": { "prop": "val" } }), "Allow non-native constructed objects" );
-});
+ assert.equal( jQuery.param( params, false ), jQuery.param( { "test": { "prop": "val" } } ), "Allow non-native constructed objects" );
+} );
-QUnit.test("serialize()", function( assert ) {
- assert.expect(6);
+QUnit.test( "serialize()", function( assert ) {
+ assert.expect( 6 );
// Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
- jQuery("#search").after(
+ jQuery( "#search" ).after(
"<input type='email' id='html5email' name='email' value='dave@jquery.com' />" +
"<input type='number' id='html5number' name='number' value='43' />" +
"<input type='file' name='fileupload' />"
);
- assert.equal( jQuery("#form").serialize(),
+ assert.equal( jQuery( "#form" ).serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
- "Check form serialization as query string");
+ "Check form serialization as query string" );
- assert.equal( jQuery("input,select,textarea,button", "#form").serialize(),
+ assert.equal( jQuery( "input,select,textarea,button", "#form" ).serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
- "Check input serialization as query string");
+ "Check input serialization as query string" );
- assert.equal( jQuery("#testForm").serialize(),
+ assert.equal( jQuery( "#testForm" ).serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
- "Check form serialization as query string");
+ "Check form serialization as query string" );
- assert.equal( jQuery("input,select,textarea,button", "#testForm").serialize(),
+ assert.equal( jQuery( "input,select,textarea,button", "#testForm" ).serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
- "Check input serialization as query string");
+ "Check input serialization as query string" );
- assert.equal( jQuery("#form, #testForm").serialize(),
+ assert.equal( jQuery( "#form, #testForm" ).serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
- "Multiple form serialization as query string");
+ "Multiple form serialization as query string" );
- assert.equal( jQuery("#form, #testForm :input").serialize(),
+ assert.equal( jQuery( "#form, #testForm :input" ).serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
- "Mixed form/input serialization as query string");
- jQuery("#html5email, #html5number").remove();
-});
+ "Mixed form/input serialization as query string" );
+ jQuery( "#html5email, #html5number" ).remove();
+} );
diff --git a/test/unit/support.js b/test/unit/support.js
index d1e3a4661..ec1ada480 100644
--- a/test/unit/support.js
+++ b/test/unit/support.js
@@ -1,4 +1,4 @@
-QUnit.module("support", { teardown: moduleTeardown });
+QUnit.module( "support", { teardown: moduleTeardown } );
var computedSupport = getComputedSupport( jQuery.support );
@@ -45,14 +45,14 @@ testIframeWithCallback(
QUnit.stop();
- supportjQuery.get( "data/support/csp.log" ).done(function( data ) {
+ supportjQuery.get( "data/support/csp.log" ).done( function( data ) {
assert.equal( data, "", "No log request should be sent" );
supportjQuery.get( "data/support/csp-clean.php" ).done( start );
- });
+ } );
}
);
-(function() {
+( function() {
var expected,
userAgent = window.navigator.userAgent;
@@ -111,6 +111,7 @@ testIframeWithCallback(
"reliableMarginRight": true
};
} else if ( /chrome/i.test( userAgent ) ) {
+
// Catches Chrome on Android as well (i.e. the default
// Android browser on Android >= 4.4).
expected = {
@@ -270,16 +271,17 @@ testIframeWithCallback(
assert.expect( j );
for ( i in expected ) {
+
// TODO check for all modules containing support properties
if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {
assert.equal( computedSupport[ i ], expected[ i ],
"jQuery.support['" + i + "']: " + computedSupport[ i ] +
- ", expected['" + i + "']: " + expected[ i ]);
+ ", expected['" + i + "']: " + expected[ i ] );
} else {
assert.ok( true, "no ajax; skipping jQuery.support[' " + i + " ']" );
}
}
- });
+ } );
}
-})();
+} )();
diff --git a/test/unit/traversing.js b/test/unit/traversing.js
index 7b5a393d9..39558fa68 100644
--- a/test/unit/traversing.js
+++ b/test/unit/traversing.js
@@ -1,46 +1,46 @@
-QUnit.module("traversing", { teardown: moduleTeardown });
+QUnit.module( "traversing", { teardown: moduleTeardown } );
QUnit.test( "find(String)", function( assert ) {
assert.expect( 1 );
- assert.equal( jQuery("#foo").find(".blogTest").text(), "Yahoo", "Basic selector" );
-});
+ assert.equal( jQuery( "#foo" ).find( ".blogTest" ).text(), "Yahoo", "Basic selector" );
+} );
QUnit.test( "find(String) under non-elements", function( assert ) {
assert.expect( 2 );
- var j = jQuery("#nonnodes").contents();
- assert.equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
- assert.equal( j.find("div").addBack().length, 3, "Check node,textnode,comment to find zero divs, but preserves pushStack" );
-});
+ var j = jQuery( "#nonnodes" ).contents();
+ assert.equal( j.find( "div" ).length, 0, "Check node,textnode,comment to find zero divs" );
+ assert.equal( j.find( "div" ).addBack().length, 3, "Check node,textnode,comment to find zero divs, but preserves pushStack" );
+} );
QUnit.test( "find(leading combinator)", function( assert ) {
assert.expect( 4 );
- assert.deepEqual( jQuery("#qunit-fixture").find("> div").get(), q( "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ), "find child elements" );
- assert.deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q( "foo", "moretests" ), "find child elements" );
- assert.deepEqual( jQuery("#qunit-fixture").find("> #foo > p").get(), q( "sndp", "en", "sap" ), "find child elements" );
+ assert.deepEqual( jQuery( "#qunit-fixture" ).find( "> div" ).get(), q( "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ), "find child elements" );
+ assert.deepEqual( jQuery( "#qunit-fixture" ).find( "> #foo, > #moretests" ).get(), q( "foo", "moretests" ), "find child elements" );
+ assert.deepEqual( jQuery( "#qunit-fixture" ).find( "> #foo > p" ).get(), q( "sndp", "en", "sap" ), "find child elements" );
- assert.deepEqual( jQuery("#siblingTest, #siblingfirst").find("+ *").get(), q( "siblingnext", "fx-test-group" ), "ensure document order" );
-});
+ assert.deepEqual( jQuery( "#siblingTest, #siblingfirst" ).find( "+ *" ).get(), q( "siblingnext", "fx-test-group" ), "ensure document order" );
+} );
QUnit.test( "find(node|jQuery object)", function( assert ) {
assert.expect( 13 );
- var $foo = jQuery("#foo"),
- $blog = jQuery(".blogTest"),
- $first = jQuery("#first"),
+ var $foo = jQuery( "#foo" ),
+ $blog = jQuery( ".blogTest" ),
+ $first = jQuery( "#first" ),
$two = $blog.add( $first ),
- $twoMore = jQuery("#ap").add( $blog ),
+ $twoMore = jQuery( "#ap" ).add( $blog ),
$fooTwo = $foo.add( $blog );
assert.equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" );
assert.equal( $foo.find( $blog[ 0 ] ).text(), "Yahoo", "Find with blog node" );
assert.equal( $foo.find( $first ).length, 0, "#first is not in #foo" );
- assert.equal( $foo.find( $first[ 0 ]).length, 0, "#first not in #foo (node)" );
+ assert.equal( $foo.find( $first[ 0 ] ).length, 0, "#first not in #foo (node)" );
assert.deepEqual( $foo.find( $two ).get(), $blog.get(), "Find returns only nodes within #foo" );
assert.deepEqual( $foo.find( $twoMore ).get(), $blog.get(), "...regardless of order" );
- assert.ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" );
- assert.ok( $fooTwo.find( $blog[ 0 ] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" );
+ assert.ok( $fooTwo.find( $blog ).is( ".blogTest" ), "Blog is part of the collection, but also within foo" );
+ assert.ok( $fooTwo.find( $blog[ 0 ] ).is( ".blogTest" ), "Blog is part of the collection, but also within foo(node)" );
assert.equal( $two.find( $foo ).length, 0, "Foo is not in two elements" );
assert.equal( $two.find( $foo[ 0 ] ).length, 0, "Foo is not in two elements(node)" );
@@ -48,47 +48,47 @@ QUnit.test( "find(node|jQuery object)", function( assert ) {
assert.equal( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" );
assert.equal( $two.find( $foo[ 0 ] ).addBack().length, 2, "find preserves the pushStack, see #12009" );
-});
-
-QUnit.test("is(String|undefined)", function( assert ) {
- assert.expect(23);
- assert.ok( jQuery("#form").is("form"), "Check for element: A form must be a form" );
- assert.ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" );
- assert.ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" );
- assert.ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" );
- assert.ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" );
- assert.ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
- assert.ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" );
- assert.ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
- assert.ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" );
- assert.ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
- assert.ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" );
- assert.ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" );
- assert.ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" );
- assert.ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" );
-
- assert.ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" );
- assert.ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" );
- assert.ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" );
- assert.ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" );
- assert.ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" );
+} );
+
+QUnit.test( "is(String|undefined)", function( assert ) {
+ assert.expect( 23 );
+ assert.ok( jQuery( "#form" ).is( "form" ), "Check for element: A form must be a form" );
+ assert.ok( !jQuery( "#form" ).is( "div" ), "Check for element: A form is not a div" );
+ assert.ok( jQuery( "#mark" ).is( ".blog" ), "Check for class: Expected class 'blog'" );
+ assert.ok( !jQuery( "#mark" ).is( ".link" ), "Check for class: Did not expect class 'link'" );
+ assert.ok( jQuery( "#simon" ).is( ".blog.link" ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
+ assert.ok( !jQuery( "#simon" ).is( ".blogTest" ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
+ assert.ok( jQuery( "#en" ).is( "[lang=\"en\"]" ), "Check for attribute: Expected attribute lang to be 'en'" );
+ assert.ok( !jQuery( "#en" ).is( "[lang=\"de\"]" ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
+ assert.ok( jQuery( "#text1" ).is( "[type=\"text\"]" ), "Check for attribute: Expected attribute type to be 'text'" );
+ assert.ok( !jQuery( "#text1" ).is( "[type=\"radio\"]" ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
+ assert.ok( jQuery( "#text2" ).is( ":disabled" ), "Check for pseudoclass: Expected to be disabled" );
+ assert.ok( !jQuery( "#text1" ).is( ":disabled" ), "Check for pseudoclass: Expected not disabled" );
+ assert.ok( jQuery( "#radio2" ).is( ":checked" ), "Check for pseudoclass: Expected to be checked" );
+ assert.ok( !jQuery( "#radio1" ).is( ":checked" ), "Check for pseudoclass: Expected not checked" );
+
+ assert.ok( !jQuery( "#foo" ).is( 0 ), "Expected false for an invalid expression - 0" );
+ assert.ok( !jQuery( "#foo" ).is( null ), "Expected false for an invalid expression - null" );
+ assert.ok( !jQuery( "#foo" ).is( "" ), "Expected false for an invalid expression - \"\"" );
+ assert.ok( !jQuery( "#foo" ).is( undefined ), "Expected false for an invalid expression - undefined" );
+ assert.ok( !jQuery( "#foo" ).is( { plain: "object" } ), "Check passing invalid object" );
// test is() with comma-separated expressions
- assert.ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
- assert.ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
- assert.ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
- assert.ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
-});
+ assert.ok( jQuery( "#en" ).is( "[lang=\"en\"],[lang=\"de\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" );
+ assert.ok( jQuery( "#en" ).is( "[lang=\"de\"],[lang=\"en\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" );
+ assert.ok( jQuery( "#en" ).is( "[lang=\"en\"] , [lang=\"de\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" );
+ assert.ok( jQuery( "#en" ).is( "[lang=\"de\"] , [lang=\"en\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" );
+} );
-QUnit.test("is() against non-elements (#10178)", function( assert ) {
- assert.expect(14);
+QUnit.test( "is() against non-elements (#10178)", function( assert ) {
+ assert.expect( 14 );
var label, i, test,
collection = jQuery( document ),
tests = [ "a", "*" ],
nonelements = {
- text: document.createTextNode(""),
- comment: document.createComment(""),
+ text: document.createTextNode( "" ),
+ comment: document.createComment( "" ),
document: document,
window: window,
array: [],
@@ -103,47 +103,47 @@ QUnit.test("is() against non-elements (#10178)", function( assert ) {
assert.ok( !collection.is( test ), label + " does not match \"" + test + "\"" );
}
}
-});
-
-QUnit.test("is(jQuery)", function( assert ) {
- assert.expect(19);
- assert.ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" );
- assert.ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" );
- assert.ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" );
- assert.ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" );
- assert.ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
- assert.ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
- assert.ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" );
- assert.ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
- assert.ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" );
- assert.ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
- assert.ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" );
- assert.ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" );
- assert.ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" );
+} );
+
+QUnit.test( "is(jQuery)", function( assert ) {
+ assert.expect( 19 );
+ assert.ok( jQuery( "#form" ).is( jQuery( "form" ) ), "Check for element: A form is a form" );
+ assert.ok( !jQuery( "#form" ).is( jQuery( "div" ) ), "Check for element: A form is not a div" );
+ assert.ok( jQuery( "#mark" ).is( jQuery( ".blog" ) ), "Check for class: Expected class 'blog'" );
+ assert.ok( !jQuery( "#mark" ).is( jQuery( ".link" ) ), "Check for class: Did not expect class 'link'" );
+ assert.ok( jQuery( "#simon" ).is( jQuery( ".blog.link" ) ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
+ assert.ok( !jQuery( "#simon" ).is( jQuery( ".blogTest" ) ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
+ assert.ok( jQuery( "#en" ).is( jQuery( "[lang=\"en\"]" ) ), "Check for attribute: Expected attribute lang to be 'en'" );
+ assert.ok( !jQuery( "#en" ).is( jQuery( "[lang=\"de\"]" ) ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
+ assert.ok( jQuery( "#text1" ).is( jQuery( "[type=\"text\"]" ) ), "Check for attribute: Expected attribute type to be 'text'" );
+ assert.ok( !jQuery( "#text1" ).is( jQuery( "[type=\"radio\"]" ) ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
+ assert.ok( !jQuery( "#text1" ).is( jQuery( "input:disabled" ) ), "Check for pseudoclass: Expected not disabled" );
+ assert.ok( jQuery( "#radio2" ).is( jQuery( "input:checked" ) ), "Check for pseudoclass: Expected to be checked" );
+ assert.ok( !jQuery( "#radio1" ).is( jQuery( "input:checked" ) ), "Check for pseudoclass: Expected not checked" );
// Some raw elements
- assert.ok( jQuery("#form").is( jQuery("#qunit-fixture form")[0] ), "Check for element: A form is a form" );
- assert.ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" );
- assert.ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" );
- assert.ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" );
- assert.ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
- assert.ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
-});
+ assert.ok( jQuery( "#form" ).is( jQuery( "#qunit-fixture form" )[ 0 ] ), "Check for element: A form is a form" );
+ assert.ok( !jQuery( "#form" ).is( jQuery( "div" )[ 0 ] ), "Check for element: A form is not a div" );
+ assert.ok( jQuery( "#mark" ).is( jQuery( ".blog" )[ 0 ] ), "Check for class: Expected class 'blog'" );
+ assert.ok( !jQuery( "#mark" ).is( jQuery( ".link" )[ 0 ] ), "Check for class: Did not expect class 'link'" );
+ assert.ok( jQuery( "#simon" ).is( jQuery( ".blog.link" )[ 0 ] ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
+ assert.ok( !jQuery( "#simon" ).is( jQuery( ".blogTest" )[ 0 ] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
+} );
-QUnit.test("is() with :has() selectors", function( assert ) {
- assert.expect(6);
+QUnit.test( "is() with :has() selectors", function( assert ) {
+ assert.expect( 6 );
- assert.ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" );
- assert.ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" );
- assert.ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" );
- assert.ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" );
+ assert.ok( jQuery( "#foo" ).is( ":has(p)" ), "Check for child: Expected a child 'p' element" );
+ assert.ok( !jQuery( "#foo" ).is( ":has(ul)" ), "Check for child: Did not expect 'ul' element" );
+ assert.ok( jQuery( "#foo" ).is( ":has(p):has(a):has(code)" ), "Check for childs: Expected 'p', 'a' and 'code' child elements" );
+ assert.ok( !jQuery( "#foo" ).is( ":has(p):has(a):has(code):has(ol)" ), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" );
- assert.ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" );
- assert.ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" );
-});
+ assert.ok( jQuery( "#foo" ).is( jQuery( "div:has(p)" ) ), "Check for child: Expected a child 'p' element" );
+ assert.ok( !jQuery( "#foo" ).is( jQuery( "div:has(ul)" ) ), "Check for child: Did not expect 'ul' element" );
+} );
-QUnit.test("is() with positional selectors", function( assert ) {
- assert.expect(27);
+QUnit.test( "is() with positional selectors", function( assert ) {
+ assert.expect( 27 );
var
posp = jQuery(
@@ -186,104 +186,103 @@ QUnit.test("is() with positional selectors", function( assert ) {
isit( "#posp em", "#posp a em:last", true );
isit( "#posp em", "#posp a em:eq(2)", false );
- assert.ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" );
+ assert.ok( jQuery( "#option1b" ).is( "#select1 option:not(:first)" ), "POS inside of :not() (#10970)" );
- assert.ok( jQuery( posp[0] ).is("p:last"), "context constructed from a single node (#13797)" );
- assert.ok( !jQuery( posp[0] ).find("#firsta").is("a:first"), "context derived from a single node (#13797)" );
-});
+ assert.ok( jQuery( posp[ 0 ] ).is( "p:last" ), "context constructed from a single node (#13797)" );
+ assert.ok( !jQuery( posp[ 0 ] ).find( "#firsta" ).is( "a:first" ), "context derived from a single node (#13797)" );
+} );
-QUnit.test("index()", function( assert ) {
+QUnit.test( "index()", function( assert ) {
assert.expect( 2 );
- assert.equal( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" );
+ assert.equal( jQuery( "#text2" ).index(), 2, "Returns the index of a child amongst its siblings" );
- assert.equal( jQuery("<div/>").index(), -1, "Node without parent returns -1" );
-});
+ assert.equal( jQuery( "<div/>" ).index(), -1, "Node without parent returns -1" );
+} );
-QUnit.test("index(Object|String|undefined)", function( assert ) {
- assert.expect(16);
+QUnit.test( "index(Object|String|undefined)", function( assert ) {
+ assert.expect( 16 );
- var elements = jQuery([window, document]),
- inputElements = jQuery("#radio1,#radio2,#check1,#check2");
+ var elements = jQuery( [ window, document ] ),
+ inputElements = jQuery( "#radio1,#radio2,#check1,#check2" );
// Passing a node
- assert.equal( elements.index(window), 0, "Check for index of elements" );
- assert.equal( elements.index(document), 1, "Check for index of elements" );
- assert.equal( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" );
- assert.equal( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" );
- assert.equal( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" );
- assert.equal( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" );
- assert.equal( inputElements.index(window), -1, "Check for not found index" );
- assert.equal( inputElements.index(document), -1, "Check for not found index" );
+ assert.equal( elements.index( window ), 0, "Check for index of elements" );
+ assert.equal( elements.index( document ), 1, "Check for index of elements" );
+ assert.equal( inputElements.index( document.getElementById( "radio1" ) ), 0, "Check for index of elements" );
+ assert.equal( inputElements.index( document.getElementById( "radio2" ) ), 1, "Check for index of elements" );
+ assert.equal( inputElements.index( document.getElementById( "check1" ) ), 2, "Check for index of elements" );
+ assert.equal( inputElements.index( document.getElementById( "check2" ) ), 3, "Check for index of elements" );
+ assert.equal( inputElements.index( window ), -1, "Check for not found index" );
+ assert.equal( inputElements.index( document ), -1, "Check for not found index" );
// Passing a jQuery object
// enabled since [5500]
assert.equal( elements.index( elements ), 0, "Pass in a jQuery object" );
- assert.equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
- assert.equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" );
+ assert.equal( elements.index( elements.eq( 1 ) ), 1, "Pass in a jQuery object" );
+ assert.equal( jQuery( "#form input[type='radio']" ).index( jQuery( "#radio2" ) ), 1, "Pass in a jQuery object" );
// Passing a selector or nothing
// enabled since [6330]
- assert.equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" );
- assert.equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" );
- assert.equal( jQuery("#radio2").index("#form input[type='radio']") , 1, "Check for index within a selector" );
- assert.equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Check for index within a selector" );
- assert.equal( jQuery("#radio2").index("#form input[type='text']") , -1, "Check for index not found within a selector" );
-});
-
-QUnit.test("filter(Selector|undefined)", function( assert ) {
- assert.expect(9);
- assert.deepEqual( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
- assert.deepEqual( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
- assert.deepEqual( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
-
- assert.deepEqual( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object");
- assert.deepEqual( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object");
- assert.deepEqual( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object");
- assert.deepEqual( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object");
+ assert.equal( jQuery( "#text2" ).index(), 2, "Check for index amongst siblings" );
+ assert.equal( jQuery( "#form" ).children().eq( 4 ).index(), 4, "Check for index amongst siblings" );
+ assert.equal( jQuery( "#radio2" ).index( "#form input[type='radio']" ), 1, "Check for index within a selector" );
+ assert.equal( jQuery( "#form input[type='radio']" ).index( jQuery( "#radio2" ) ), 1, "Check for index within a selector" );
+ assert.equal( jQuery( "#radio2" ).index( "#form input[type='text']" ), -1, "Check for index not found within a selector" );
+} );
+
+QUnit.test( "filter(Selector|undefined)", function( assert ) {
+ assert.expect( 9 );
+ assert.deepEqual( jQuery( "#form input" ).filter( ":checked" ).get(), q( "radio2", "check1" ), "filter(String)" );
+ assert.deepEqual( jQuery( "p" ).filter( "#ap, #sndp" ).get(), q( "ap", "sndp" ), "filter('String, String')" );
+ assert.deepEqual( jQuery( "p" ).filter( "#ap,#sndp" ).get(), q( "ap", "sndp" ), "filter('String,String')" );
+
+ assert.deepEqual( jQuery( "p" ).filter( null ).get(), [], "filter(null) should return an empty jQuery object" );
+ assert.deepEqual( jQuery( "p" ).filter( undefined ).get(), [], "filter(undefined) should return an empty jQuery object" );
+ assert.deepEqual( jQuery( "p" ).filter( 0 ).get(), [], "filter(0) should return an empty jQuery object" );
+ assert.deepEqual( jQuery( "p" ).filter( "" ).get(), [], "filter('') should return an empty jQuery object" );
// using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- assert.equal( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
- assert.equal( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
-});
+ var j = jQuery( "#nonnodes" ).contents();
+ assert.equal( j.filter( "span" ).length, 1, "Check node,textnode,comment to filter the one span" );
+ assert.equal( j.filter( "[name]" ).length, 0, "Check node,textnode,comment to filter the one span" );
+} );
-QUnit.test("filter(Function)", function( assert ) {
- assert.expect(2);
-
- assert.deepEqual( jQuery("#qunit-fixture p").filter(function() {
- return !jQuery("a", this).length;
- }).get(), q("sndp", "first"), "filter(Function)" );
+QUnit.test( "filter(Function)", function( assert ) {
+ assert.expect( 2 );
- assert.deepEqual( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length; }).get(), q("sndp", "first"), "filter(Function) using arg" );
-});
+ assert.deepEqual( jQuery( "#qunit-fixture p" ).filter( function() {
+ return !jQuery( "a", this ).length;
+ } ).get(), q( "sndp", "first" ), "filter(Function)" );
-QUnit.test("filter(Element)", function( assert ) {
- assert.expect(1);
+ assert.deepEqual( jQuery( "#qunit-fixture p" ).filter( function( i, elem ) { return !jQuery( "a", elem ).length; } ).get(), q( "sndp", "first" ), "filter(Function) using arg" );
+} );
- var element = document.getElementById("text1");
- assert.deepEqual( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" );
-});
+QUnit.test( "filter(Element)", function( assert ) {
+ assert.expect( 1 );
-QUnit.test("filter(Array)", function( assert ) {
- assert.expect(1);
+ var element = document.getElementById( "text1" );
+ assert.deepEqual( jQuery( "#form input" ).filter( element ).get(), q( "text1" ), "filter(Element)" );
+} );
- var elements = [ document.getElementById("text1") ];
- assert.deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
-});
+QUnit.test( "filter(Array)", function( assert ) {
+ assert.expect( 1 );
-QUnit.test("filter(jQuery)", function( assert ) {
- assert.expect(1);
+ var elements = [ document.getElementById( "text1" ) ];
+ assert.deepEqual( jQuery( "#form input" ).filter( elements ).get(), q( "text1" ), "filter(Element)" );
+} );
- var elements = jQuery("#text1");
- assert.deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
-});
+QUnit.test( "filter(jQuery)", function( assert ) {
+ assert.expect( 1 );
+ var elements = jQuery( "#text1" );
+ assert.deepEqual( jQuery( "#form input" ).filter( elements ).get(), q( "text1" ), "filter(Element)" );
+} );
-QUnit.test("filter() with positional selectors", function( assert ) {
- assert.expect(19);
+QUnit.test( "filter() with positional selectors", function( assert ) {
+ assert.expect( 19 );
- var filterit = function(sel, filter, length) {
+ var filterit = function( sel, filter, length ) {
assert.equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" );
};
@@ -298,7 +297,7 @@ QUnit.test("filter() with positional selectors", function( assert ) {
"<em></em>" +
"</p>" ).appendTo( "#qunit-fixture" );
- filterit( "#posp", "#posp:first", 1);
+ filterit( "#posp", "#posp:first", 1 );
filterit( "#posp", "#posp:eq(2)", 0 );
filterit( "#posp", "#posp a:first", 0 );
@@ -321,364 +320,364 @@ QUnit.test("filter() with positional selectors", function( assert ) {
filterit( "#posp .seconda", "#posp a:gt(0)", 0 );
filterit( "#posp .seconda", "#posp a:lt(5)", 1 );
filterit( "#posp .seconda", "#posp a:lt(1)", 1 );
-});
+} );
-QUnit.test("closest()", function( assert ) {
+QUnit.test( "closest()", function( assert ) {
assert.expect( 13 );
var jq;
- assert.deepEqual( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
- assert.deepEqual( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
- assert.deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" );
- assert.deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" );
+ assert.deepEqual( jQuery( "body" ).closest( "body" ).get(), q( "body" ), "closest(body)" );
+ assert.deepEqual( jQuery( "body" ).closest( "html" ).get(), q( "html" ), "closest(html)" );
+ assert.deepEqual( jQuery( "body" ).closest( "div" ).get(), [], "closest(div)" );
+ assert.deepEqual( jQuery( "#qunit-fixture" ).closest( "span,#html" ).get(), q( "html" ), "closest(span,#html)" );
// Test .closest() limited by the context
- jq = jQuery("#nothiddendivchild");
- assert.deepEqual( jq.closest("html", document.body).get(), [], "Context limited." );
- assert.deepEqual( jq.closest("body", document.body).get(), [], "Context limited." );
- assert.deepEqual( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
+ jq = jQuery( "#nothiddendivchild" );
+ assert.deepEqual( jq.closest( "html", document.body ).get(), [], "Context limited." );
+ assert.deepEqual( jq.closest( "body", document.body ).get(), [], "Context limited." );
+ assert.deepEqual( jq.closest( "#nothiddendiv", document.body ).get(), q( "nothiddendiv" ), "Context not reached." );
//Test that .closest() returns unique'd set
- assert.equal( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" );
+ assert.equal( jQuery( "#qunit-fixture p" ).closest( "#qunit-fixture" ).length, 1, "Closest should return a unique set" );
// Test on disconnected node
- assert.equal( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
+ assert.equal( jQuery( "<div><p></p></div>" ).find( "p" ).closest( "table" ).length, 0, "Make sure disconnected closest work." );
// Bug #7369
- assert.equal( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" );
- assert.equal( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" );
+ assert.equal( jQuery( "<div foo='bar'></div>" ).closest( "[foo]" ).length, 1, "Disconnected nodes with attribute selector" );
+ assert.equal( jQuery( "<div>text</div>" ).closest( "[lang]" ).length, 0, "Disconnected nodes with text and non-existent attribute selector" );
- assert.ok( !jQuery(document).closest("#foo").length, "Calling closest on a document fails silently" );
+ assert.ok( !jQuery( document ).closest( "#foo" ).length, "Calling closest on a document fails silently" );
- jq = jQuery("<div>text</div>");
- assert.deepEqual( jq.contents().closest("*").get(), jq.get(), "Text node input (#13332)" );
-});
+ jq = jQuery( "<div>text</div>" );
+ assert.deepEqual( jq.contents().closest( "*" ).get(), jq.get(), "Text node input (#13332)" );
+} );
-QUnit.test("closest() with positional selectors", function( assert ) {
+QUnit.test( "closest() with positional selectors", function( assert ) {
assert.expect( 2 );
- assert.deepEqual( jQuery("#qunit-fixture").closest("div:first").get(), [], "closest(div:first)" );
- assert.deepEqual( jQuery("#qunit-fixture div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
-});
-
-QUnit.test("closest(jQuery)", function( assert ) {
- assert.expect(8);
- var $child = jQuery("#nothiddendivchild"),
- $parent = jQuery("#nothiddendiv"),
- $sibling = jQuery("#foo"),
- $body = jQuery("body");
- assert.ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" );
- assert.ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" );
- assert.ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" );
- assert.ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" );
- assert.equal( $child.closest( document.createElement("div") ).length, 0, "created element is not related" );
+ assert.deepEqual( jQuery( "#qunit-fixture" ).closest( "div:first" ).get(), [], "closest(div:first)" );
+ assert.deepEqual( jQuery( "#qunit-fixture div" ).closest( "body:first div:last" ).get(), q( "fx-tests" ), "closest(body:first div:last)" );
+} );
+
+QUnit.test( "closest(jQuery)", function( assert ) {
+ assert.expect( 8 );
+ var $child = jQuery( "#nothiddendivchild" ),
+ $parent = jQuery( "#nothiddendiv" ),
+ $sibling = jQuery( "#foo" ),
+ $body = jQuery( "body" );
+ assert.ok( $child.closest( $parent ).is( "#nothiddendiv" ), "closest( jQuery('#nothiddendiv') )" );
+ assert.ok( $child.closest( $parent[ 0 ] ).is( "#nothiddendiv" ), "closest( jQuery('#nothiddendiv') ) :: node" );
+ assert.ok( $child.closest( $child ).is( "#nothiddendivchild" ), "child is included" );
+ assert.ok( $child.closest( $child[ 0 ] ).is( "#nothiddendivchild" ), "child is included :: node" );
+ assert.equal( $child.closest( document.createElement( "div" ) ).length, 0, "created element is not related" );
assert.equal( $child.closest( $sibling ).length, 0, "Sibling not a parent of child" );
- assert.equal( $child.closest( $sibling[0] ).length, 0, "Sibling not a parent of child :: node" );
- assert.ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." );
-});
-
-QUnit.test("not(Selector|undefined)", function( assert ) {
- assert.expect(11);
- assert.equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" );
- assert.deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
- assert.deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
-
- assert.deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
- assert.deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
- assert.deepEqual( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
-
- var all = jQuery("p").get();
- assert.deepEqual( jQuery("p").not(null).get(), all, "not(null) should have no effect");
- assert.deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect");
- assert.deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect");
- assert.deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect");
+ assert.equal( $child.closest( $sibling[ 0 ] ).length, 0, "Sibling not a parent of child :: node" );
+ assert.ok( $child.closest( $body.add( $parent ) ).is( "#nothiddendiv" ), "Closest ancestor retrieved." );
+} );
+
+QUnit.test( "not(Selector|undefined)", function( assert ) {
+ assert.expect( 11 );
+ assert.equal( jQuery( "#qunit-fixture > p#ap > a" ).not( "#google" ).length, 2, "not('selector')" );
+ assert.deepEqual( jQuery( "p" ).not( ".result" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "not('.class')" );
+ assert.deepEqual( jQuery( "p" ).not( "#ap, #sndp, .result" ).get(), q( "firstp", "en", "sap", "first" ), "not('selector, selector')" );
+
+ assert.deepEqual( jQuery( "#ap *" ).not( "code" ).get(), q( "google", "groups", "anchor1", "mark" ), "not('tag selector')" );
+ assert.deepEqual( jQuery( "#ap *" ).not( "code, #mark" ).get(), q( "google", "groups", "anchor1" ), "not('tag, ID selector')" );
+ assert.deepEqual( jQuery( "#ap *" ).not( "#mark, code" ).get(), q( "google", "groups", "anchor1" ), "not('ID, tag selector')" );
+
+ var all = jQuery( "p" ).get();
+ assert.deepEqual( jQuery( "p" ).not( null ).get(), all, "not(null) should have no effect" );
+ assert.deepEqual( jQuery( "p" ).not( undefined ).get(), all, "not(undefined) should have no effect" );
+ assert.deepEqual( jQuery( "p" ).not( 0 ).get(), all, "not(0) should have no effect" );
+ assert.deepEqual( jQuery( "p" ).not( "" ).get(), all, "not('') should have no effect" );
assert.deepEqual(
- jQuery("#form option").not("option.emptyopt:contains('Nothing'),optgroup *,[value='1']").get(),
- q("option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b"),
+ jQuery( "#form option" ).not( "option.emptyopt:contains('Nothing'),optgroup *,[value='1']" ).get(),
+ q( "option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b" ),
"not('complex selector')"
);
-});
+} );
-QUnit.test("not(Element)", function( assert ) {
- assert.expect(1);
+QUnit.test( "not(Element)", function( assert ) {
+ assert.expect( 1 );
- var selects = jQuery("#form select");
- assert.deepEqual( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element");
-});
+ var selects = jQuery( "#form select" );
+ assert.deepEqual( selects.not( selects[ 1 ] ).get(), q( "select1", "select3", "select4", "select5" ), "filter out DOM element" );
+} );
-QUnit.test("not(Function)", function( assert ) {
- assert.expect(1);
+QUnit.test( "not(Function)", function( assert ) {
+ assert.expect( 1 );
- assert.deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length; }).get(), q("sndp", "first"), "not(Function)" );
-});
+ assert.deepEqual( jQuery( "#qunit-fixture p" ).not( function() { return jQuery( "a", this ).length; } ).get(), q( "sndp", "first" ), "not(Function)" );
+} );
-QUnit.test("not(Array)", function( assert ) {
- assert.expect(2);
+QUnit.test( "not(Array)", function( assert ) {
+ assert.expect( 2 );
- assert.equal( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
- assert.equal( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
-});
+ assert.equal( jQuery( "#qunit-fixture > p#ap > a" ).not( document.getElementById( "google" ) ).length, 2, "not(DOMElement)" );
+ assert.equal( jQuery( "p" ).not( document.getElementsByTagName( "p" ) ).length, 0, "not(Array-like DOM collection)" );
+} );
-QUnit.test("not(jQuery)", function( assert ) {
+QUnit.test( "not(jQuery)", function( assert ) {
assert.expect( 1 );
- assert.deepEqual( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
-});
+ assert.deepEqual( jQuery( "p" ).not( jQuery( "#ap, #sndp, .result" ) ).get(), q( "firstp", "en", "sap", "first" ), "not(jQuery)" );
+} );
-QUnit.test("has(Element)", function( assert ) {
- assert.expect(3);
+QUnit.test( "has(Element)", function( assert ) {
+ assert.expect( 3 );
var obj, detached, multipleParent;
- obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
- assert.deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
+ obj = jQuery( "#qunit-fixture" ).has( jQuery( "#sndp" )[ 0 ] );
+ assert.deepEqual( obj.get(), q( "qunit-fixture" ), "Keeps elements that have the element as a descendant" );
- detached = jQuery("<a><b><i/></b></a>");
- assert.deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
+ detached = jQuery( "<a><b><i/></b></a>" );
+ assert.deepEqual( detached.has( detached.find( "i" )[ 0 ] ).get(), detached.get(), "...Even when detached" );
- multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
- assert.deepEqual( multipleParent.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 ] );
+ assert.deepEqual( multipleParent.get(), q( "qunit-fixture" ), "Does not include elements that do not have the element as a descendant" );
+} );
-QUnit.test("has(Selector)", function( assert ) {
+QUnit.test( "has(Selector)", function( assert ) {
assert.expect( 5 );
var obj, detached, multipleParent, multipleHas;
- obj = jQuery("#qunit-fixture").has("#sndp");
- assert.deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
+ obj = jQuery( "#qunit-fixture" ).has( "#sndp" );
+ assert.deepEqual( obj.get(), q( "qunit-fixture" ), "Keeps elements that have any element matching the selector as a descendant" );
- detached = jQuery("<a><b><i/></b></a>");
- assert.deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
+ detached = jQuery( "<a><b><i/></b></a>" );
+ assert.deepEqual( detached.has( "i" ).get(), detached.get(), "...Even when detached" );
- multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
- assert.deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
+ multipleParent = jQuery( "#qunit-fixture, #header" ).has( "#sndp" );
+ assert.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");
- assert.deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" );
+ multipleParent = jQuery( "#select1, #select2, #select3" ).has( "#option1a, #option3a" );
+ assert.deepEqual( multipleParent.get(), q( "select1", "select3" ), "Multiple contexts are checks correctly" );
- multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
- assert.deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
-});
+ multipleHas = jQuery( "#qunit-fixture" ).has( "#sndp, #first" );
+ assert.deepEqual( multipleHas.get(), q( "qunit-fixture" ), "Only adds elements once" );
+} );
-QUnit.test("has(Arrayish)", function( assert ) {
- assert.expect(4);
+QUnit.test( "has(Arrayish)", function( assert ) {
+ assert.expect( 4 );
var simple, detached, multipleParent, multipleHas;
- simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
- assert.deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
-
- detached = jQuery("<a><b><i/></b></a>");
- assert.deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
-
- multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
- assert.deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
-
- multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
- assert.deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
-});
-
-QUnit.test("addBack()", function( assert ) {
- assert.expect(5);
- assert.deepEqual( jQuery("#en").siblings().addBack().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
- assert.deepEqual( jQuery("#foo").children().addBack().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
- assert.deepEqual( jQuery("#sndp, #en").parent().addBack().get(), q("foo","sndp","en"), "Check for parent and self" );
- assert.deepEqual( jQuery("#groups").parents("p, div").addBack().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" );
- assert.deepEqual( jQuery("#select1 > option").filter(":first-child").addBack(":last-child").get(), q("option1a", "option1d"), "Should contain the last elems plus the *filtered* prior set elements" );
-});
-
-QUnit.test("siblings([String])", function( assert ) {
- assert.expect(6);
- assert.deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
- assert.deepEqual( jQuery("#nonnodes").contents().eq(1).siblings().get(), q("nonnodesElement"), "Check for text node siblings" );
- assert.deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
-
- var set = q("sndp", "en", "sap");
- assert.deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
- assert.deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
- assert.equal( jQuery("<a/>").siblings().length, 0, "Detached elements have no siblings (#11370)" );
-});
-
-QUnit.test("siblings([String]) - jQuery only", function( assert ) {
- assert.expect(2);
- assert.deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
- assert.deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
-});
-
-QUnit.test("children([String])", function( assert ) {
- assert.expect(2);
- assert.deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
- assert.deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
-});
-
-QUnit.test("children([String]) - jQuery only", function( assert ) {
- assert.expect(1);
- assert.deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
-});
-
-QUnit.test("parent([String])", function( assert ) {
- assert.expect(6);
+ simple = jQuery( "#qunit-fixture" ).has( jQuery( "#sndp" ) );
+ assert.deepEqual( simple.get(), q( "qunit-fixture" ), "Keeps elements that have any element in the jQuery list as a descendant" );
+
+ detached = jQuery( "<a><b><i/></b></a>" );
+ assert.deepEqual( detached.has( detached.find( "i" ) ).get(), detached.get(), "...Even when detached" );
+
+ multipleParent = jQuery( "#qunit-fixture, #header" ).has( jQuery( "#sndp" ) );
+ assert.deepEqual( multipleParent.get(), q( "qunit-fixture" ), "Does not include elements that do not have an element in the jQuery list as a descendant" );
+
+ multipleHas = jQuery( "#qunit-fixture" ).has( jQuery( "#sndp, #first" ) );
+ assert.deepEqual( multipleHas.get(), q( "qunit-fixture" ), "Only adds elements once" );
+} );
+
+QUnit.test( "addBack()", function( assert ) {
+ assert.expect( 5 );
+ assert.deepEqual( jQuery( "#en" ).siblings().addBack().get(), q( "sndp", "en", "sap" ), "Check for siblings and self" );
+ assert.deepEqual( jQuery( "#foo" ).children().addBack().get(), q( "foo", "sndp", "en", "sap" ), "Check for children and self" );
+ assert.deepEqual( jQuery( "#sndp, #en" ).parent().addBack().get(), q( "foo", "sndp", "en" ), "Check for parent and self" );
+ assert.deepEqual( jQuery( "#groups" ).parents( "p, div" ).addBack().get(), q( "qunit-fixture", "ap", "groups" ), "Check for parents and self" );
+ assert.deepEqual( jQuery( "#select1 > option" ).filter( ":first-child" ).addBack( ":last-child" ).get(), q( "option1a", "option1d" ), "Should contain the last elems plus the *filtered* prior set elements" );
+} );
+
+QUnit.test( "siblings([String])", function( assert ) {
+ assert.expect( 6 );
+ assert.deepEqual( jQuery( "#en" ).siblings().get(), q( "sndp", "sap" ), "Check for siblings" );
+ assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).siblings().get(), q( "nonnodesElement" ), "Check for text node siblings" );
+ assert.deepEqual( jQuery( "#foo" ).siblings( "form, b" ).get(), q( "form", "floatTest", "lengthtest", "name-tests", "testForm" ), "Check for multiple filters" );
+
+ var set = q( "sndp", "en", "sap" );
+ assert.deepEqual( jQuery( "#en, #sndp" ).siblings().get(), set, "Check for unique results from siblings" );
+ assert.deepEqual( jQuery( "#option5a" ).siblings( "option[data-attr]" ).get(), q( "option5c" ), "Has attribute selector in siblings (#9261)" );
+ assert.equal( jQuery( "<a/>" ).siblings().length, 0, "Detached elements have no siblings (#11370)" );
+} );
+
+QUnit.test( "siblings([String]) - jQuery only", function( assert ) {
+ assert.expect( 2 );
+ assert.deepEqual( jQuery( "#sndp" ).siblings( ":has(code)" ).get(), q( "sap" ), "Check for filtered siblings (has code child element)" );
+ assert.deepEqual( jQuery( "#sndp" ).siblings( ":has(a)" ).get(), q( "en", "sap" ), "Check for filtered siblings (has anchor child element)" );
+} );
+
+QUnit.test( "children([String])", function( assert ) {
+ assert.expect( 2 );
+ assert.deepEqual( jQuery( "#foo" ).children().get(), q( "sndp", "en", "sap" ), "Check for children" );
+ assert.deepEqual( jQuery( "#foo" ).children( "#en, #sap" ).get(), q( "en", "sap" ), "Check for multiple filters" );
+} );
+
+QUnit.test( "children([String]) - jQuery only", function( assert ) {
+ assert.expect( 1 );
+ assert.deepEqual( jQuery( "#foo" ).children( ":has(code)" ).get(), q( "sndp", "sap" ), "Check for filtered children" );
+} );
+
+QUnit.test( "parent([String])", function( assert ) {
+ assert.expect( 6 );
var $el;
- assert.equal( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
- assert.equal( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
- assert.equal( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
- assert.equal( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
- assert.deepEqual( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
+ assert.equal( jQuery( "#groups" ).parent()[ 0 ].id, "ap", "Simple parent check" );
+ assert.equal( jQuery( "#groups" ).parent( "p" )[ 0 ].id, "ap", "Filtered parent check" );
+ assert.equal( jQuery( "#groups" ).parent( "div" ).length, 0, "Filtered parent check, no match" );
+ assert.equal( jQuery( "#groups" ).parent( "div, p" )[ 0 ].id, "ap", "Check for multiple filters" );
+ assert.deepEqual( jQuery( "#en, #sndp" ).parent().get(), q( "foo" ), "Check for unique results from parent" );
- $el = jQuery("<div>text</div>");
+ $el = jQuery( "<div>text</div>" );
assert.deepEqual( $el.contents().parent().get(), $el.get(), "Check for parent of text node (#13265)" );
-});
-
-QUnit.test("parents([String])", function( assert ) {
- assert.expect(6);
- assert.equal( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
- assert.deepEqual( jQuery("#nonnodes").contents().eq(1).parents().eq(0).get(), q("nonnodes"), "Text node parents check" );
- assert.equal( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
- assert.equal( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" );
- assert.deepEqual( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" );
- assert.deepEqual( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" );
-});
-
-QUnit.test("parentsUntil([String])", function( assert ) {
- assert.expect(10);
-
- var parents = jQuery("#groups").parents();
-
- assert.deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
- assert.deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
- assert.deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.slice(0, -1).get(), "Simple parentsUntil check" );
- assert.equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" );
- assert.deepEqual( jQuery("#nonnodes").contents().eq(1).parentsUntil("#html").eq(0).get(), q("nonnodes"), "Text node parentsUntil check" );
- assert.deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
- assert.deepEqual( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" );
- assert.deepEqual( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" );
- assert.equal( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" );
- assert.deepEqual( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" );
-});
-
-QUnit.test("next([String])", function( assert ) {
- assert.expect(6);
- assert.equal( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
- assert.equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).next().attr("id"), "element", "Text node next check" );
- assert.equal( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
- assert.equal( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
- assert.equal( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
- assert.equal( jQuery("body").next().length, 0, "Simple next check, no match" );
-});
-
-QUnit.test("prev([String])", function( assert ) {
- assert.expect(5);
- assert.equal( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
- assert.deepEqual( jQuery("#nonnodes").contents().eq(1).prev().get(), q("nonnodesElement"), "Text node prev check" );
- assert.equal( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
- assert.equal( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
- assert.equal( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
-});
-
-QUnit.test("nextAll([String])", function( assert ) {
- assert.expect(5);
-
- var elems = jQuery("#form").children();
-
- assert.deepEqual( jQuery("#label-for").nextAll().get(), elems.slice(1).get(), "Simple nextAll check" );
- assert.equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).nextAll().attr("id"), "element", "Text node nextAll check" );
- assert.deepEqual( jQuery("#label-for").nextAll("input").get(), elems.slice(1).filter("input").get(), "Filtered nextAll check" );
- assert.deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multiple-filtered nextAll check" );
- assert.deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" );
-});
-
-QUnit.test("prevAll([String])", function( assert ) {
- assert.expect(5);
-
- var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() );
-
- assert.deepEqual( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" );
- assert.deepEqual( jQuery("#nonnodes").contents().eq(1).prevAll().get(), q("nonnodesElement"), "Text node prevAll check" );
- assert.deepEqual( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" );
- assert.deepEqual( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" );
- assert.deepEqual( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" );
-});
-
-QUnit.test("nextUntil([String])", function( assert ) {
- assert.expect(12);
-
- var elems = jQuery("#form").children().slice( 2, 12 );
-
- assert.deepEqual( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" );
- assert.equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).nextUntil().attr("id"), "element", "Text node nextUntil with no selector (nextAll)" );
- assert.deepEqual( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" );
- assert.deepEqual( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" );
- assert.equal( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" );
- assert.deepEqual( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" );
- assert.deepEqual( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" );
- assert.deepEqual( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" );
- assert.deepEqual( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" );
- assert.equal( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" );
- assert.deepEqual( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" );
-
- assert.deepEqual( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" );
-});
-
-QUnit.test("prevUntil([String])", function( assert ) {
- assert.expect(11);
-
- var elems = jQuery("#area1").prevAll();
-
- assert.deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
- assert.deepEqual( jQuery("#nonnodes").contents().eq(1).prevUntil().get(), q("nonnodesElement"), "Text node prevUntil with no selector (prevAll)" );
- assert.deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
- assert.deepEqual( jQuery("#area1").prevUntil("label").get(), elems.slice(0, -1).get(), "Simple prevUntil check" );
- assert.equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" );
- assert.deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" );
- assert.deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.slice(0, -1).not("button").get(), "Filtered prevUntil check" );
- assert.deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.slice(0, -1).not("input").get(), "Filtered prevUntil check" );
- assert.deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multiple-filtered prevUntil check" );
- assert.equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" );
- assert.deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multi-source, multiple-filtered prevUntil check" );
-});
-
-QUnit.test("contents()", function( assert ) {
- assert.expect(12);
+} );
+
+QUnit.test( "parents([String])", function( assert ) {
+ assert.expect( 6 );
+ assert.equal( jQuery( "#groups" ).parents()[ 0 ].id, "ap", "Simple parents check" );
+ assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).parents().eq( 0 ).get(), q( "nonnodes" ), "Text node parents check" );
+ assert.equal( jQuery( "#groups" ).parents( "p" )[ 0 ].id, "ap", "Filtered parents check" );
+ assert.equal( jQuery( "#groups" ).parents( "div" )[ 0 ].id, "qunit-fixture", "Filtered parents check2" );
+ assert.deepEqual( jQuery( "#groups" ).parents( "p, div" ).get(), q( "ap", "qunit-fixture" ), "Check for multiple filters" );
+ assert.deepEqual( jQuery( "#en, #sndp" ).parents().get(), q( "foo", "qunit-fixture", "dl", "body", "html" ), "Check for unique results from parents" );
+} );
+
+QUnit.test( "parentsUntil([String])", function( assert ) {
+ assert.expect( 10 );
+
+ var parents = jQuery( "#groups" ).parents();
+
+ assert.deepEqual( jQuery( "#groups" ).parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
+ assert.deepEqual( jQuery( "#groups" ).parentsUntil( ".foo" ).get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
+ assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html" ).get(), parents.slice( 0, -1 ).get(), "Simple parentsUntil check" );
+ assert.equal( jQuery( "#groups" ).parentsUntil( "#ap" ).length, 0, "Simple parentsUntil check" );
+ assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).parentsUntil( "#html" ).eq( 0 ).get(), q( "nonnodes" ), "Text node parentsUntil check" );
+ assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html, #body" ).get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
+ assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html", "div" ).get(), jQuery( "#qunit-fixture" ).get(), "Filtered parentsUntil check" );
+ assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html", "p,div,dl" ).get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" );
+ assert.equal( jQuery( "#groups" ).parentsUntil( "#html", "span" ).length, 0, "Filtered parentsUntil check, no match" );
+ assert.deepEqual( jQuery( "#groups, #ap" ).parentsUntil( "#html", "p,div,dl" ).get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" );
+} );
+
+QUnit.test( "next([String])", function( assert ) {
+ assert.expect( 6 );
+ assert.equal( jQuery( "#ap" ).next()[ 0 ].id, "foo", "Simple next check" );
+ assert.equal( jQuery( "<div>text<a id='element'></a></div>" ).contents().eq( 0 ).next().attr( "id" ), "element", "Text node next check" );
+ assert.equal( jQuery( "#ap" ).next( "div" )[ 0 ].id, "foo", "Filtered next check" );
+ assert.equal( jQuery( "#ap" ).next( "p" ).length, 0, "Filtered next check, no match" );
+ assert.equal( jQuery( "#ap" ).next( "div, p" )[ 0 ].id, "foo", "Multiple filters" );
+ assert.equal( jQuery( "body" ).next().length, 0, "Simple next check, no match" );
+} );
+
+QUnit.test( "prev([String])", function( assert ) {
+ assert.expect( 5 );
+ assert.equal( jQuery( "#foo" ).prev()[ 0 ].id, "ap", "Simple prev check" );
+ assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).prev().get(), q( "nonnodesElement" ), "Text node prev check" );
+ assert.equal( jQuery( "#foo" ).prev( "p" )[ 0 ].id, "ap", "Filtered prev check" );
+ assert.equal( jQuery( "#foo" ).prev( "div" ).length, 0, "Filtered prev check, no match" );
+ assert.equal( jQuery( "#foo" ).prev( "p, div" )[ 0 ].id, "ap", "Multiple filters" );
+} );
+
+QUnit.test( "nextAll([String])", function( assert ) {
+ assert.expect( 5 );
+
+ var elems = jQuery( "#form" ).children();
+
+ assert.deepEqual( jQuery( "#label-for" ).nextAll().get(), elems.slice( 1 ).get(), "Simple nextAll check" );
+ assert.equal( jQuery( "<div>text<a id='element'></a></div>" ).contents().eq( 0 ).nextAll().attr( "id" ), "element", "Text node nextAll check" );
+ assert.deepEqual( jQuery( "#label-for" ).nextAll( "input" ).get(), elems.slice( 1 ).filter( "input" ).get(), "Filtered nextAll check" );
+ assert.deepEqual( jQuery( "#label-for" ).nextAll( "input,select" ).get(), elems.slice( 1 ).filter( "input,select" ).get(), "Multiple-filtered nextAll check" );
+ assert.deepEqual( jQuery( "#label-for, #hidden1" ).nextAll( "input,select" ).get(), elems.slice( 1 ).filter( "input,select" ).get(), "Multi-source, multiple-filtered nextAll check" );
+} );
+
+QUnit.test( "prevAll([String])", function( assert ) {
+ assert.expect( 5 );
+
+ var elems = jQuery( jQuery( "#form" ).children().slice( 0, 12 ).get().reverse() );
+
+ assert.deepEqual( jQuery( "#area1" ).prevAll().get(), elems.get(), "Simple prevAll check" );
+ assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).prevAll().get(), q( "nonnodesElement" ), "Text node prevAll check" );
+ assert.deepEqual( jQuery( "#area1" ).prevAll( "input" ).get(), elems.filter( "input" ).get(), "Filtered prevAll check" );
+ assert.deepEqual( jQuery( "#area1" ).prevAll( "input,select" ).get(), elems.filter( "input,select" ).get(), "Multiple-filtered prevAll check" );
+ assert.deepEqual( jQuery( "#area1, #hidden1" ).prevAll( "input,select" ).get(), elems.filter( "input,select" ).get(), "Multi-source, multiple-filtered prevAll check" );
+} );
+
+QUnit.test( "nextUntil([String])", function( assert ) {
+ assert.expect( 12 );
+
+ var elems = jQuery( "#form" ).children().slice( 2, 12 );
+
+ assert.deepEqual( jQuery( "#text1" ).nextUntil().get(), jQuery( "#text1" ).nextAll().get(), "nextUntil with no selector (nextAll)" );
+ assert.equal( jQuery( "<div>text<a id='element'></a></div>" ).contents().eq( 0 ).nextUntil().attr( "id" ), "element", "Text node nextUntil with no selector (nextAll)" );
+ assert.deepEqual( jQuery( "#text1" ).nextUntil( ".foo" ).get(), jQuery( "#text1" ).nextAll().get(), "nextUntil with invalid selector (nextAll)" );
+ assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1" ).get(), elems.get(), "Simple nextUntil check" );
+ assert.equal( jQuery( "#text1" ).nextUntil( "#text2" ).length, 0, "Simple nextUntil check" );
+ assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1, #radio1" ).get(), jQuery( "#text1" ).next().get(), "Less simple nextUntil check" );
+ assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1", "input" ).get(), elems.not( "button" ).get(), "Filtered nextUntil check" );
+ assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1", "button" ).get(), elems.not( "input" ).get(), "Filtered nextUntil check" );
+ assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1", "button,input" ).get(), elems.get(), "Multiple-filtered nextUntil check" );
+ assert.equal( jQuery( "#text1" ).nextUntil( "#area1", "div" ).length, 0, "Filtered nextUntil check, no match" );
+ assert.deepEqual( jQuery( "#text1, #hidden1" ).nextUntil( "#area1", "button,input" ).get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" );
+
+ assert.deepEqual( jQuery( "#text1" ).nextUntil( "[class=foo]" ).get(), jQuery( "#text1" ).nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" );
+} );
+
+QUnit.test( "prevUntil([String])", function( assert ) {
+ assert.expect( 11 );
+
+ var elems = jQuery( "#area1" ).prevAll();
+
+ assert.deepEqual( jQuery( "#area1" ).prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
+ assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).prevUntil().get(), q( "nonnodesElement" ), "Text node prevUntil with no selector (prevAll)" );
+ assert.deepEqual( jQuery( "#area1" ).prevUntil( ".foo" ).get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
+ assert.deepEqual( jQuery( "#area1" ).prevUntil( "label" ).get(), elems.slice( 0, -1 ).get(), "Simple prevUntil check" );
+ assert.equal( jQuery( "#area1" ).prevUntil( "#button" ).length, 0, "Simple prevUntil check" );
+ assert.deepEqual( jQuery( "#area1" ).prevUntil( "label, #search" ).get(), jQuery( "#area1" ).prev().get(), "Less simple prevUntil check" );
+ assert.deepEqual( jQuery( "#area1" ).prevUntil( "label", "input" ).get(), elems.slice( 0, -1 ).not( "button" ).get(), "Filtered prevUntil check" );
+ assert.deepEqual( jQuery( "#area1" ).prevUntil( "label", "button" ).get(), elems.slice( 0, -1 ).not( "input" ).get(), "Filtered prevUntil check" );
+ assert.deepEqual( jQuery( "#area1" ).prevUntil( "label", "button,input" ).get(), elems.slice( 0, -1 ).get(), "Multiple-filtered prevUntil check" );
+ assert.equal( jQuery( "#area1" ).prevUntil( "label", "div" ).length, 0, "Filtered prevUntil check, no match" );
+ assert.deepEqual( jQuery( "#area1, #hidden1" ).prevUntil( "label", "button,input" ).get(), elems.slice( 0, -1 ).get(), "Multi-source, multiple-filtered prevUntil check" );
+} );
+
+QUnit.test( "contents()", function( assert ) {
+ assert.expect( 12 );
var ibody, c;
- assert.equal( jQuery("#ap").contents().length, 9, "Check element contents" );
- assert.ok( jQuery("#iframe").contents()[0], "Check existence of IFrame document" );
- ibody = jQuery("#loadediframe").contents()[0].body;
+ assert.equal( jQuery( "#ap" ).contents().length, 9, "Check element contents" );
+ assert.ok( jQuery( "#iframe" ).contents()[ 0 ], "Check existence of IFrame document" );
+ ibody = jQuery( "#loadediframe" ).contents()[ 0 ].body;
assert.ok( ibody, "Check existence of IFrame body" );
- assert.equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
+ assert.equal( jQuery( "span", ibody ).text(), "span text", "Find span in IFrame and check its text" );
- jQuery(ibody).append("<div>init text</div>");
- assert.equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
+ jQuery( ibody ).append( "<div>init text</div>" );
+ assert.equal( jQuery( "div", ibody ).length, 2, "Check the original div and the new div are in IFrame" );
- assert.equal( jQuery("div", ibody).last().text(), "init text", "Add text to div in IFrame" );
+ assert.equal( jQuery( "div", ibody ).last().text(), "init text", "Add text to div in IFrame" );
- jQuery("div", ibody).last().text("div text");
- assert.equal( jQuery("div", ibody).last().text(), "div text", "Add text to div in IFrame" );
+ jQuery( "div", ibody ).last().text( "div text" );
+ assert.equal( jQuery( "div", ibody ).last().text(), "div text", "Add text to div in IFrame" );
- jQuery("div", ibody).last().remove();
- assert.equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
+ jQuery( "div", ibody ).last().remove();
+ assert.equal( jQuery( "div", ibody ).length, 1, "Delete the div and check only one div left in IFrame" );
- assert.equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
+ assert.equal( jQuery( "div", ibody ).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
- jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
- jQuery("table", ibody).remove();
- assert.equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
+ jQuery( "<table/>", ibody ).append( "<tr><td>cell</td></tr>" ).appendTo( ibody );
+ jQuery( "table", ibody ).remove();
+ assert.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
- c = jQuery("#nonnodes").contents().contents();
+ c = jQuery( "#nonnodes" ).contents().contents();
assert.equal( c.length, 1, "Check node,textnode,comment contents is just one" );
- assert.equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
-});
+ assert.equal( c[ 0 ].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
+} );
-QUnit.test("sort direction", function( assert ) {
+QUnit.test( "sort direction", function( assert ) {
assert.expect( 12 );
- var elems = jQuery("#ap, #select1 > *, #moretests > form"),
+ var elems = jQuery( "#ap, #select1 > *, #moretests > form" ),
methodDirections = {
parent: false,
parents: true,
@@ -698,99 +697,98 @@ QUnit.test("sort direction", function( assert ) {
var actual = elems[ method ]().get(),
forward = jQuery.uniqueSort( [].concat( actual ) );
assert.deepEqual( actual, reversed ? forward.reverse() : forward, "Correct sort direction for " + method );
- });
-});
+ } );
+} );
-QUnit.test("add(String selector)", function( assert ) {
+QUnit.test( "add(String selector)", function( assert ) {
assert.expect( 2 );
var divs;
assert.deepEqual(
- jQuery("#sndp").add("#en").add("#sap").toArray(),
- q("sndp", "en", "sap"),
+ jQuery( "#sndp" ).add( "#en" ).add( "#sap" ).toArray(),
+ q( "sndp", "en", "sap" ),
"Check elements from document"
);
- divs = jQuery("<div/>").add("#sndp");
- assert.ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
-});
+ divs = jQuery( "<div/>" ).add( "#sndp" );
+ assert.ok( divs[ 0 ].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
+} );
-QUnit.test("add(String selector, String context)", function( assert ) {
+QUnit.test( "add(String selector, String context)", function( assert ) {
assert.expect( 1 );
assert.deepEqual(
- jQuery([]).add("div", "#nothiddendiv").toArray(),
- q("nothiddendivchild"),
+ jQuery( [] ).add( "div", "#nothiddendiv" ).toArray(),
+ q( "nothiddendivchild" ),
"Check elements from document"
);
-});
+} );
-QUnit.test("add(String html)", function( assert ) {
+QUnit.test( "add(String html)", function( assert ) {
assert.expect( 3 );
var x,
- divs = jQuery("#sndp").add("<div/>");
+ divs = jQuery( "#sndp" ).add( "<div/>" );
- assert.ok( !divs[1].parentNode, "Sort with the disconnected node last." );
+ assert.ok( !divs[ 1 ].parentNode, "Sort with the disconnected node last." );
+ x = jQuery( [] ).add( "<p id='x1'>xxx</p>" ).add( "<p id='x2'>xxx</p>" );
+ assert.equal( x[ 0 ].id, "x1", "Check detached element1" );
+ assert.equal( x[ 1 ].id, "x2", "Check detached element2" );
+} );
- x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
- assert.equal( x[0].id, "x1", "Check detached element1" );
- assert.equal( x[1].id, "x2", "Check detached element2" );
-});
-
-QUnit.test("add(jQuery)", function( assert ) {
+QUnit.test( "add(jQuery)", function( assert ) {
assert.expect( 4 );
var x,
- tmp = jQuery("<div/>");
+ tmp = jQuery( "<div/>" );
- x = jQuery([])
+ x = jQuery( [] )
.add(
- jQuery("<p id='x1'>xxx</p>").appendTo(tmp)
+ jQuery( "<p id='x1'>xxx</p>" ).appendTo( tmp )
)
.add(
- jQuery("<p id='x2'>xxx</p>").appendTo(tmp)
+ jQuery( "<p id='x2'>xxx</p>" ).appendTo( tmp )
);
- assert.equal( x[0].id, "x1", "Check element1 in detached parent" );
- assert.equal( x[1].id, "x2", "Check element2 in detached parent" );
+ assert.equal( x[ 0 ].id, "x1", "Check element1 in detached parent" );
+ assert.equal( x[ 1 ].id, "x2", "Check element2 in detached parent" );
- x = jQuery([])
+ x = jQuery( [] )
.add(
- jQuery("<p id='x1'>xxx</p>")
+ jQuery( "<p id='x1'>xxx</p>" )
)
.add(
- jQuery("<p id='x2'>xxx</p>")
+ jQuery( "<p id='x2'>xxx</p>" )
);
- assert.equal( x[0].id, "x1", "Check detached element1" );
- assert.equal( x[1].id, "x2", "Check detached element2" );
-});
+ assert.equal( x[ 0 ].id, "x1", "Check detached element1" );
+ assert.equal( x[ 1 ].id, "x2", "Check detached element2" );
+} );
-QUnit.test("add(Element)", function( assert ) {
+QUnit.test( "add(Element)", function( assert ) {
assert.expect( 2 );
var x,
- tmp = jQuery("<div/>");
+ tmp = jQuery( "<div/>" );
- x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]);
- assert.equal( x[0].id, "x1", "Check on-the-fly element1" );
- assert.equal( x[1].id, "x2", "Check on-the-fly element2" );
-});
+ x = jQuery( [] ).add( jQuery( "<p id='x1'>xxx</p>" ).appendTo( tmp )[ 0 ] ).add( jQuery( "<p id='x2'>xxx</p>" ).appendTo( tmp )[ 0 ] );
+ assert.equal( x[ 0 ].id, "x1", "Check on-the-fly element1" );
+ assert.equal( x[ 1 ].id, "x2", "Check on-the-fly element2" );
+} );
-QUnit.test("add(Array elements)", function( assert ) {
+QUnit.test( "add(Array elements)", function( assert ) {
assert.expect( 1 );
assert.deepEqual(
- jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).toArray(),
- q("sndp", "en", "sap"),
+ jQuery( "#sndp" ).add( jQuery( "#en" )[ 0 ] ).add( jQuery( "#sap" ) ).toArray(),
+ q( "sndp", "en", "sap" ),
"Check elements from document"
);
-});
+} );
-QUnit.test("add(Window)", function( assert ) {
+QUnit.test( "add(Window)", function( assert ) {
assert.expect( 1 );
var frame1 = document.createElement( "iframe" ),
@@ -802,25 +800,25 @@ QUnit.test("add(Window)", function( assert ) {
// Window is tricky because it is a lot like an array, even Array#slice will
// turn it into a multi-item array.
- assert.equal( jQuery([]).add( window ).length, 1, "Add a window" );
+ assert.equal( jQuery( [] ).add( window ).length, 1, "Add a window" );
document.body.removeChild( frame1 );
document.body.removeChild( frame2 );
-});
+} );
-QUnit.test("add(NodeList|undefined|HTMLFormElement|HTMLSelectElement)", function( assert ) {
+QUnit.test( "add(NodeList|undefined|HTMLFormElement|HTMLSelectElement)", function( assert ) {
assert.expect( 4 );
var ps, notDefined;
- ps = document.getElementsByTagName("p");
+ ps = document.getElementsByTagName( "p" );
- assert.equal( jQuery([]).add(ps).length, ps.length, "Add a NodeList" );
+ assert.equal( jQuery( [] ).add( ps ).length, ps.length, "Add a NodeList" );
- assert.equal( jQuery([]).add(notDefined).length, 0, "Adding undefined adds nothing" );
+ assert.equal( jQuery( [] ).add( notDefined ).length, 0, "Adding undefined adds nothing" );
- assert.equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
- assert.equal( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" );
+ assert.equal( jQuery( [] ).add( document.getElementById( "form" ) ).length, 1, "Add a form" );
+ assert.equal( jQuery( [] ).add( document.getElementById( "select1" ) ).length, 1, "Add a select" );
// We no longer support .add(form.elements), unfortunately.
// There is no way, in browsers, to reliably determine the difference
@@ -831,53 +829,53 @@ QUnit.test("add(NodeList|undefined|HTMLFormElement|HTMLSelectElement)", function
// For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
// 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()" );
-});
+} );
-QUnit.test("add(String, Context)", function( assert ) {
- assert.expect(6);
+QUnit.test( "add(String, Context)", function( assert ) {
+ assert.expect( 6 );
assert.deepEqual( jQuery( "#firstp" ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add selector to selector " );
- assert.deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" );
- assert.deepEqual( jQuery( document.getElementById("firstp") ).add( document.getElementById("ap") ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" );
+ assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" );
+ assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( document.getElementById( "ap" ) ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" );
- var ctx = document.getElementById("firstp");
+ var ctx = document.getElementById( "firstp" );
assert.deepEqual( jQuery( "#firstp" ).add( "#ap", ctx ).get(), q( "firstp" ), "Add selector to selector " );
- assert.deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" );
- assert.deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", document.getElementsByTagName("body")[0] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" );
-});
+ assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" );
+ assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( "#ap", document.getElementsByTagName( "body" )[ 0 ] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" );
+} );
-QUnit.test("eq('-1') #10616", function( assert ) {
- assert.expect(3);
+QUnit.test( "eq('-1') #10616", function( assert ) {
+ assert.expect( 3 );
var $divs = jQuery( "div" );
assert.equal( $divs.eq( -1 ).length, 1, "The number -1 returns a selection that has length 1" );
assert.equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" );
assert.deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" );
-});
+} );
-QUnit.test("index(no arg) #10977", function( assert ) {
- assert.expect(2);
+QUnit.test( "index(no arg) #10977", function( assert ) {
+ assert.expect( 2 );
var $list, fragment, div;
- $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 = 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") );
+ div = fragment.appendChild( document.createElement( "div" ) );
assert.equal( jQuery( div ).index(), 0, "If jQuery#index called on element whose parent is fragment, it still should work correctly" );
-});
+} );
-QUnit.test("traversing non-elements with attribute filters (#12523)", function( assert ) {
- assert.expect(5);
+QUnit.test( "traversing non-elements with attribute filters (#12523)", function( assert ) {
+ assert.expect( 5 );
- var nonnodes = jQuery("#nonnodes").contents();
+ var nonnodes = jQuery( "#nonnodes" ).contents();
- assert.equal( nonnodes.filter("[id]").length, 1, ".filter" );
- assert.equal( nonnodes.find("[id]").length, 0, ".find" );
- assert.strictEqual( nonnodes.is("[id]"), true, ".is" );
- assert.deepEqual( nonnodes.closest("[id='nonnodes']").get(), q("nonnodes"), ".closest" );
- assert.deepEqual( nonnodes.parents("[id='nonnodes']").get(), q("nonnodes"), ".parents" );
-});
+ assert.equal( nonnodes.filter( "[id]" ).length, 1, ".filter" );
+ assert.equal( nonnodes.find( "[id]" ).length, 0, ".find" );
+ assert.strictEqual( nonnodes.is( "[id]" ), true, ".is" );
+ assert.deepEqual( nonnodes.closest( "[id='nonnodes']" ).get(), q( "nonnodes" ), ".closest" );
+ assert.deepEqual( nonnodes.parents( "[id='nonnodes']" ).get(), q( "nonnodes" ), ".parents" );
+} );
diff --git a/test/unit/wrap.js b/test/unit/wrap.js
index cefbcfc18..80abd9e87 100644
--- a/test/unit/wrap.js
+++ b/test/unit/wrap.js
@@ -1,4 +1,4 @@
-(function() {
+( function() {
if ( !jQuery.fn.wrap ) { // no wrap module
return;
@@ -6,7 +6,7 @@ if ( !jQuery.fn.wrap ) { // no wrap module
QUnit.module( "wrap", {
teardown: moduleTeardown
-});
+} );
// See test/unit/manipulation.js for explanation about these 2 functions
function manipulationBareObj( value ) {
@@ -19,36 +19,54 @@ function manipulationFunctionReturningObj( value ) {
};
}
-function testWrap( val , assert ) {
+function testWrap( val, assert ) {
assert.expect( 19 );
var defaultText, result, j, i, cacheLength;
defaultText = "Try them out:";
- result = jQuery("#first").wrap( val("<div class='red'><span></span></div>") ).text();
-
- assert.equal( defaultText, result, "Check for wrapping of on-the-fly html" );
- assert.ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
-
- result = jQuery("#first").wrap( val(document.getElementById("empty")) ).parent();
- assert.ok( result.is("ol"), "Check for element wrapping" );
- assert.equal( result.text(), defaultText, "Check for element wrapping" );
-
- jQuery("#check1").on( "click", function() {
+ result = jQuery( "#first" ).wrap( val( "<div class='red'><span></span></div>" ) ).text();
+
+ assert.equal(
+ defaultText, result, "Check for wrapping of on-the-fly html"
+ );
+ assert.ok(
+ jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
+ );
+
+ result = jQuery( "#first" ).wrap( val( document.getElementById( "empty" ) ) ).parent();
+ assert.ok(
+ result.is( "ol" ), "Check for element wrapping"
+ );
+ assert.equal(
+ result.text(), defaultText, "Check for element wrapping"
+ );
+
+ jQuery( "#check1" ).on( "click", function() {
var checkbox = this;
- assert.ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
- jQuery( checkbox ).wrap( val("<div id='c1' style='display:none;'></div>") );
- assert.ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
- }).prop( "checked", false )[ 0 ].click();
+ assert.ok(
+ checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
+ );
+ jQuery( checkbox ).wrap( val( "<div id='c1' style='display:none;'></div>" ) );
+ assert.ok(
+ checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
+ );
+ } ).prop( "checked", false )[ 0 ].click();
// using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
- j.wrap( val("<i></i>") );
-
- assert.equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" );
- assert.equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
+ j = jQuery( "#nonnodes" ).contents();
+ j.wrap( val( "<i></i>" ) );
+
+ assert.equal(
+ jQuery( "#nonnodes > i" ).length, jQuery( "#nonnodes" )[ 0 ].childNodes.length,
+ "Check node,textnode,comment wraps ok"
+ );
+ assert.equal(
+ jQuery( "#nonnodes > i" ).text(), j.text(),
+ "Check node,textnode,comment wraps doesn't hurt text"
+ );
// Try wrapping a disconnected node
cacheLength = 0;
@@ -56,79 +74,109 @@ function testWrap( val , assert ) {
cacheLength++;
}
- j = jQuery("<label/>").wrap( val("<li/>") );
- assert.equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" );
- assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
+ j = jQuery( "<label/>" ).wrap( val( "<li/>" ) );
+ assert.equal(
+ j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label"
+ );
+ assert.equal(
+ j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped"
+ );
for ( i in jQuery.cache ) {
cacheLength--;
}
- assert.equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" );
+ assert.equal(
+ cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)"
+ );
// Wrap an element containing a text node
- j = jQuery("<span/>").wrap("<div>test</div>");
- assert.equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
- assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
+ j = jQuery( "<span/>" ).wrap( "<div>test</div>" );
+ assert.equal(
+ j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element"
+ );
+ assert.equal(
+ j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element."
+ );
// Try to wrap an element with multiple elements (should fail)
- j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
- assert.equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
- assert.equal( j.length, 1, "There should only be one element (no cloning)." );
- assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
+ j = jQuery( "<div><span></span></div>" ).children().wrap( "<p></p><div></div>" );
+ assert.equal(
+ j[ 0 ].parentNode.parentNode.childNodes.length, 1,
+ "There should only be one element wrapping."
+ );
+ assert.equal(
+ j.length, 1, "There should only be one element (no cloning)."
+ );
+ assert.equal(
+ j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph."
+ );
// Wrap an element with a jQuery set
- j = jQuery("<span/>").wrap( jQuery("<div></div>") );
- assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
+ j = jQuery( "<span/>" ).wrap( jQuery( "<div></div>" ) );
+ assert.equal(
+ j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
+ );
// Wrap an element with a jQuery set and event
- result = jQuery("<div></div>").on( "click", function() {
- assert.ok( true, "Event triggered." );
+ result = jQuery( "<div></div>" ).on( "click", function() {
+ assert.ok(
+ true, "Event triggered."
+ );
// Remove handlers on detached elements
result.off();
- jQuery(this).off();
- });
+ jQuery( this ).off();
+ } );
- j = jQuery("<span/>").wrap( result );
- assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
+ j = jQuery( "<span/>" ).wrap( result );
+ assert.equal(
+ j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
+ );
- j.parent().trigger("click");
+ j.parent().trigger( "click" );
}
QUnit.test( "wrap(String|Element)", function( assert ) {
testWrap( manipulationBareObj, assert );
-});
+} );
QUnit.test( "wrap(Function)", function( assert ) {
testWrap( manipulationFunctionReturningObj, assert );
-});
+} );
QUnit.test( "wrap(Function) with index (#10177)", function( assert ) {
var expectedIndex = 0,
- targets = jQuery("#qunit-fixture p");
+ targets = jQuery( "#qunit-fixture p" );
assert.expect( targets.length );
- targets.wrap(function(i) {
- assert.equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
+ targets.wrap( function( i ) {
+ assert.equal(
+ i, expectedIndex,
+ "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")"
+ );
expectedIndex++;
return "<div id='wrap_index_'" + i + "'></div>";
- });
-});
+ } );
+} );
QUnit.test( "wrap(String) consecutive elements (#10177)", function( assert ) {
- var targets = jQuery("#qunit-fixture p");
+ var targets = jQuery( "#qunit-fixture p" );
assert.expect( targets.length * 2 );
- targets.wrap("<div class='wrapper'></div>");
+ targets.wrap( "<div class='wrapper'></div>" );
- targets.each(function() {
- var $this = jQuery(this);
+ targets.each( function() {
+ var $this = jQuery( this );
- assert.ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" );
- assert.equal( $this.siblings().length, 0, "Each element should be wrapped individually" );
- });
-});
+ assert.ok(
+ $this.parent().is( ".wrapper" ), "Check each elements parent is correct (.wrapper)"
+ );
+ assert.equal(
+ $this.siblings().length, 0, "Each element should be wrapped individually"
+ );
+ } );
+} );
QUnit.test( "wrapAll(String)", function( assert ) {
@@ -136,65 +184,97 @@ QUnit.test( "wrapAll(String)", function( assert ) {
var prev, p, result;
- prev = jQuery("#firstp")[ 0 ].previousSibling;
- p = jQuery("#firstp,#first")[ 0 ].parentNode;
- result = jQuery("#firstp,#first").wrapAll( "<div class='red'><div class='tmp'></div></div>" );
-
- assert.equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
- assert.ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
- assert.ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
- assert.equal( jQuery("#first").parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
- assert.equal( jQuery("#first").parent().parent()[ 0 ].parentNode, p, "Correct Parent" );
-
-});
+ prev = jQuery( "#firstp" )[ 0 ].previousSibling;
+ p = jQuery( "#firstp,#first" )[ 0 ].parentNode;
+ result = jQuery( "#firstp,#first" ).wrapAll( "<div class='red'><div class='tmp'></div></div>" );
+
+ assert.equal(
+ result.parent().length, 1, "Check for wrapping of on-the-fly html"
+ );
+ assert.ok(
+ jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
+ );
+ assert.ok(
+ jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
+ );
+ assert.equal(
+ jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
+ );
+ assert.equal(
+ jQuery( "#first" ).parent().parent()[ 0 ].parentNode, p, "Correct Parent"
+ );
+
+} );
QUnit.test( "wrapAll(Function)", function( assert ) {
assert.expect( 5 );
var prev = jQuery( "#firstp" )[ 0 ].previousSibling,
p = jQuery( "#firstp,#first" )[ 0 ].parentNode,
- result = jQuery( "#firstp,#first" ).wrapAll(function() {
+ result = jQuery( "#firstp,#first" ).wrapAll( function() {
return "<div class='red'><div class='tmp'></div></div>";
- });
-
- assert.equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
- assert.ok( jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" );
- assert.ok( jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" );
- assert.ok( jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent" );
- assert.strictEqual( jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
-});
+ } );
+
+ assert.equal(
+ result.parent().length, 1, "Check for wrapping of on-the-fly html"
+ );
+ assert.ok(
+ jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
+ );
+ assert.ok(
+ jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
+ );
+ assert.ok(
+ jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent"
+ );
+ assert.strictEqual(
+ jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
+ );
+} );
QUnit.test( "wrapAll(Function) check execution characteristics", function( assert ) {
assert.expect( 3 );
var i = 0;
- jQuery( "non-existent" ).wrapAll(function() {
+ jQuery( "non-existent" ).wrapAll( function() {
i++;
return "";
- });
-
- assert.ok( !i, "should not execute function argument if target element does not exist" );
-
- jQuery( "#firstp" ).wrapAll(function( index ) {
- assert.strictEqual( this, jQuery( "#firstp" )[ 0 ], "context must be the first found element" );
- assert.strictEqual( index, undefined, "index argument should not be included in function execution" );
- });
-});
+ } );
+
+ assert.ok(
+ !i, "should not execute function argument if target element does not exist"
+ );
+
+ jQuery( "#firstp" ).wrapAll( function( index ) {
+ assert.strictEqual(
+ this, jQuery( "#firstp" )[ 0 ], "context must be the first found element"
+ );
+ assert.strictEqual(
+ index, undefined, "index argument should not be included in function execution"
+ );
+ } );
+} );
QUnit.test( "wrapAll(Element)", function( assert ) {
assert.expect( 3 );
var prev, p;
- prev = jQuery("#firstp")[ 0 ].previousSibling;
- p = jQuery("#first")[ 0 ].parentNode;
- jQuery("#firstp,#first").wrapAll( document.getElementById("empty") );
-
- assert.equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" );
- assert.equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
- assert.equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
-});
+ prev = jQuery( "#firstp" )[ 0 ].previousSibling;
+ p = jQuery( "#first" )[ 0 ].parentNode;
+ jQuery( "#firstp,#first" ).wrapAll( document.getElementById( "empty" ) );
+
+ assert.equal(
+ jQuery( "#first" ).parent()[ 0 ], jQuery( "#firstp" ).parent()[ 0 ], "Same Parent"
+ );
+ assert.equal(
+ jQuery( "#first" ).parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
+ );
+ assert.equal(
+ jQuery( "#first" ).parent()[ 0 ].parentNode, p, "Correct Parent"
+ );
+} );
QUnit.test( "wrapInner(String)", function( assert ) {
@@ -202,37 +282,59 @@ QUnit.test( "wrapInner(String)", function( assert ) {
var num;
- num = jQuery("#first").children().length;
- jQuery("#first").wrapInner( "<div class='red'><div id='tmp'></div></div>" );
-
- assert.equal( jQuery("#first").children().length, 1, "Only one child" );
- assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
- assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
-
- num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
- jQuery("#first").wrapInner( "<div class='red'><div id='tmp'></div></div>" );
- assert.equal( jQuery("#first").children().length, 1, "Only one child" );
- assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
- assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
-});
+ num = jQuery( "#first" ).children().length;
+ jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
+
+ assert.equal(
+ jQuery( "#first" ).children().length, 1, "Only one child"
+ );
+ assert.ok(
+ jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
+ );
+ assert.equal(
+ jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
+ );
+
+ num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
+ jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
+ assert.equal(
+ jQuery( "#first" ).children().length, 1, "Only one child"
+ );
+ assert.ok(
+ jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
+ );
+ assert.equal(
+ jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
+ );
+} );
QUnit.test( "wrapInner(Element)", function( assert ) {
assert.expect( 5 );
var num,
- div = jQuery("<div/>");
-
- num = jQuery("#first").children().length;
- jQuery("#first").wrapInner( document.getElementById("empty") );
- assert.equal( jQuery("#first").children().length, 1, "Only one child" );
- assert.ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
- assert.equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
+ div = jQuery( "<div/>" );
+
+ num = jQuery( "#first" ).children().length;
+ jQuery( "#first" ).wrapInner( document.getElementById( "empty" ) );
+ assert.equal(
+ jQuery( "#first" ).children().length, 1, "Only one child"
+ );
+ assert.ok(
+ jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
+ );
+ assert.equal(
+ jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
+ );
div.wrapInner( "<span></span>" );
- assert.equal( div.children().length, 1, "The contents were wrapped." );
- assert.equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
-});
+ assert.equal(
+ div.children().length, 1, "The contents were wrapped."
+ );
+ assert.equal(
+ div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
+ );
+} );
QUnit.test( "wrapInner(Function) returns String", function( assert ) {
@@ -241,19 +343,31 @@ QUnit.test( "wrapInner(Function) returns String", function( assert ) {
var num,
val = manipulationFunctionReturningObj;
- num = jQuery("#first").children().length;
- jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
-
- assert.equal( jQuery("#first").children().length, 1, "Only one child" );
- assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
- assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
-
- num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
- jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
- assert.equal( jQuery("#first").children().length, 1, "Only one child" );
- assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
- assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
-});
+ num = jQuery( "#first" ).children().length;
+ jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
+
+ assert.equal(
+ jQuery( "#first" ).children().length, 1, "Only one child"
+ );
+ assert.ok(
+ jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
+ );
+ assert.equal(
+ jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
+ );
+
+ num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
+ jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
+ assert.equal(
+ jQuery( "#first" ).children().length, 1, "Only one child"
+ );
+ assert.ok(
+ jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
+ );
+ assert.equal(
+ jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
+ );
+} );
QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
@@ -261,71 +375,127 @@ QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
var num,
val = manipulationFunctionReturningObj,
- div = jQuery("<div/>");
-
- num = jQuery("#first").children().length;
- jQuery("#first").wrapInner( val(document.getElementById("empty")) );
- assert.equal( jQuery("#first").children().length, 1, "Only one child" );
- assert.ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
- assert.equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
-
- div.wrapInner( val("<span></span>") );
- assert.equal( div.children().length, 1, "The contents were wrapped." );
- assert.equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
-});
+ div = jQuery( "<div/>" );
+
+ num = jQuery( "#first" ).children().length;
+ jQuery( "#first" ).wrapInner( val( document.getElementById( "empty" ) ) );
+ assert.equal(
+ jQuery( "#first" ).children().length, 1, "Only one child"
+ );
+ assert.ok(
+ jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
+ );
+ assert.equal(
+ jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
+ );
+
+ div.wrapInner( val( "<span></span>" ) );
+ assert.equal(
+ div.children().length, 1, "The contents were wrapped."
+ );
+ assert.equal(
+ div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
+ );
+} );
QUnit.test( "unwrap()", function( assert ) {
assert.expect( 9 );
- jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>");
-
- var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
- abcdef = jQuery("#unwrap span").get();
-
- assert.equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" );
- assert.deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" );
-
- assert.deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
-
- assert.deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
-
- assert.deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
-
- assert.deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
-
- assert.deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" );
- assert.deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
-
- assert.deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
-
- jQuery("body > span.unwrap").remove();
-});
+ jQuery( "body" ).append(
+ " <div id='unwrap' style='display: none;'> <div id='unwrap1'>" +
+ " <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'>" +
+ " <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'>" +
+ " <b><span class='unwrap unwrap3'>e</span></b>" +
+ " <b><span class='unwrap unwrap3'>f</span></b> </div> </div>"
+ );
+
+ var abcd = jQuery( "#unwrap1 > span, #unwrap2 > span" ).get(),
+ abcdef = jQuery( "#unwrap span" ).get();
+
+ assert.equal(
+ jQuery( "#unwrap1 span" ).add( "#unwrap2 span:first-child" ).unwrap().length, 3,
+ "make #unwrap1 and #unwrap2 go away"
+ );
+ assert.deepEqual(
+ jQuery( "#unwrap > span" ).get(), abcd, "all four spans should still exist"
+ );
+
+ assert.deepEqual(
+ jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap3 > span" ).get(),
+ "make all b in #unwrap3 go away"
+ );
+
+ assert.deepEqual(
+ jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap > span.unwrap3" ).get(),
+ "make #unwrap3 go away"
+ );
+
+ assert.deepEqual(
+ jQuery( "#unwrap" ).children().get(), abcdef, "#unwrap only contains 6 child spans"
+ );
+
+ assert.deepEqual(
+ jQuery( "#unwrap > span" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
+ "make the 6 spans become children of body"
+ );
+
+ assert.deepEqual(
+ jQuery( "body > span.unwrap" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
+ "can't unwrap children of body"
+ );
+ assert.deepEqual(
+ jQuery( "body > span.unwrap" ).unwrap().get(), abcdef, "can't unwrap children of body"
+ );
+
+ assert.deepEqual(
+ jQuery( "body > span.unwrap" ).get(), abcdef, "body contains 6 .unwrap child spans"
+ );
+
+ jQuery( "body > span.unwrap" ).remove();
+} );
QUnit.test( "unwrap( selector )", function( assert ) {
assert.expect( 5 );
- jQuery( "body" ).append( " <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> </div>" );
+ jQuery( "body" ).append(
+ " <div id='unwrap' style='display: none;'> <div id='unwrap1'>" +
+ "<span class='unwrap'>a</span> <span class='unwrap'>b</span> </div>" +
+ " <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span>" +
+ " </div> </div>"
+ );
// Shouldn't unwrap, no match
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap2" );
- assert.equal( jQuery("#unwrap1").length, 1, "still wrapped" );
+ assert.equal(
+ jQuery( "#unwrap1" ).length, 1, "still wrapped"
+ );
// Shouldn't unwrap, no match
jQuery( "#unwrap1 span" ) .unwrap( "span" );
- assert.equal( jQuery("#unwrap1").length, 1, "still wrapped" );
+ assert.equal(
+ jQuery( "#unwrap1" ).length, 1, "still wrapped"
+ );
// Unwraps
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap1" );
- assert.equal( jQuery("#unwrap1").length, 0, "unwrapped match" );
+ assert.equal(
+ jQuery( "#unwrap1" ).length, 0, "unwrapped match"
+ );
// Check return values
- assert.deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(), "return on unmatched unwrap" );
- assert.deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(), "return on matched unwrap" );
-
- jQuery("body > span.unwrap").remove();
-});
+ assert.deepEqual(
+ jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(),
+ "return on unmatched unwrap"
+ );
+ assert.deepEqual(
+ jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(),
+ "return on matched unwrap"
+ );
+
+ jQuery( "body > span.unwrap" ).remove();
+} );
QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function( assert ) {
@@ -334,24 +504,33 @@ QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", f
var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ),
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
- $wraptarget.wrapAll("<aside style='background-color:green'></aside>");
+ $wraptarget.wrapAll( "<aside style='background-color:green'></aside>" );
- assert.notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" );
- assert.notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
-});
+ assert.notEqual(
+ $wraptarget.parent( "aside" ).get( 0 ).style.backgroundColor, "transparent",
+ "HTML5 elements created with wrapAll inherit styles"
+ );
+ assert.notEqual(
+ $section.get( 0 ).style.backgroundColor, "transparent",
+ "HTML5 elements create with jQuery( string ) inherit styles"
+ );
+} );
QUnit.test( "wrapping scripts (#10470)", function( assert ) {
assert.expect( 2 );
- var script = document.createElement("script");
- script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
+ var script = document.createElement( "script" );
+ script.text = script.textContent =
+ "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
document.eval10470 = false;
- jQuery("#qunit-fixture").empty()[0].appendChild( script );
- jQuery("#qunit-fixture script").wrap("<b></b>");
- assert.strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" );
+ jQuery( "#qunit-fixture" ).empty()[ 0 ].appendChild( script );
+ jQuery( "#qunit-fixture script" ).wrap( "<b></b>" );
+ assert.strictEqual(
+ script.parentNode, jQuery( "#qunit-fixture > b" )[ 0 ], "correctly wrapped"
+ );
jQuery( script ).remove();
-});
+} );
-})();
+} )();