Merge branch 'master' of git://github.com/jquery/jquery into bug_2773

This commit is contained in:
timmywil 2011-02-26 18:53:25 -05:00
commit 9e5ec378e3
70 changed files with 1736 additions and 15275 deletions

View file

@ -240,6 +240,68 @@ test("jQuery.ajax() - error callbacks", function() {
});
});
test( "jQuery.ajax - multiple method signatures introduced in 1.5 ( #8107)", function() {
expect( 4 );
stop();
jQuery.when(
jQuery.ajax().success(function() { ok( true, 'With no arguments' ); }),
jQuery.ajax('data/name.html').success(function() { ok( true, 'With only string URL argument' ); }),
jQuery.ajax('data/name.html', {} ).success(function() { ok( true, 'With string URL param and map' ); }),
jQuery.ajax({ url: 'data/name.html'} ).success(function() { ok( true, 'With only map' ); })
).then( start, start );
});
test("jQuery.ajax() - textStatus and errorThrown values", function() {
var nb = 2;
expect( 2 * nb );
stop();
function startN() {
if ( !( --nb ) ) {
start();
}
}
/*
Safari 3.x returns "OK" instead of "Not Found"
Safari 4.x doesn't have this issue so the test should be re-instated once
we drop support for 3.x
jQuery.ajax({
url: url("data/nonExistingURL"),
error: function( _ , textStatus , errorThrown ){
strictEqual( textStatus, "error", "textStatus is 'error' for 404" );
strictEqual( errorThrown, "Not Found", "errorThrown is 'Not Found' for 404");
startN();
}
});
*/
jQuery.ajax({
url: url("data/name.php?wait=5"),
error: function( _ , textStatus , errorThrown ){
strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort");
startN();
}
}).abort();
jQuery.ajax({
url: url("data/name.php?wait=5"),
error: function( _ , textStatus , errorThrown ){
strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')");
startN();
}
}).abort( "mystatus" );
});
test("jQuery.ajax() - responseText on error", function() {
expect( 1 );
@ -249,7 +311,7 @@ test("jQuery.ajax() - responseText on error", function() {
jQuery.ajax({
url: url("data/errorWithText.php"),
error: function(xhr) {
strictEqual( xhr.responseText , "plain text message" , "Test jXHR.responseText is filled for HTTP errors" );
strictEqual( xhr.responseText , "plain text message" , "Test jqXHR.responseText is filled for HTTP errors" );
},
complete: function() {
start();
@ -282,14 +344,18 @@ test(".ajax() - retry with jQuery.ajax( this )", function() {
test(".ajax() - headers" , function() {
expect( 2 );
expect( 4 );
stop();
jQuery('#foo').ajaxSend(function( evt, xhr ) {
xhr.setRequestHeader( "ajax-send", "test" );
});
var requestHeaders = {
siMPle: "value",
"SometHing-elsE": "other value",
OthEr: "something else"
siMPle: "value",
"SometHing-elsE": "other value",
OthEr: "something else"
},
list = [],
i;
@ -297,22 +363,31 @@ test(".ajax() - headers" , function() {
for( i in requestHeaders ) {
list.push( i );
}
list.push( "ajax-send" );
jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
headers: requestHeaders,
success: function( data , _ , xhr ) {
var tmp = [];
for ( i in requestHeaders ) {
tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
}
tmp.push( "ajax-send: test\n" );
tmp = tmp.join( "" );
equals( data , tmp , "Headers were sent" );
equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
start();
strictEqual( data , tmp , "Headers were sent" );
strictEqual( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
if ( jQuery.browser.mozilla ) {
ok( true, "Firefox doesn't support empty headers" );
} else {
strictEqual( xhr.getResponseHeader( "Empty-Header" ) , "" , "Empty header received" );
}
strictEqual( xhr.getResponseHeader( "Sample-Header2" ) , "Hello World 2" , "Second sample header received" );
},
error: function(){ ok(false, "error"); }
});
}).then( start, start );
});
@ -374,6 +449,18 @@ test(".ajax() - contentType" , function() {
});
test(".ajax() - protocol-less urls", function() {
expect(1);
jQuery.ajax({
url: "//somedomain.com",
beforeSend: function( xhr, settings ) {
equals(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added.");
return false;
}
});
});
test(".ajax() - hash", function() {
expect(3);
@ -405,7 +492,7 @@ test(".ajax() - hash", function() {
test("jQuery ajax - cross-domain detection", function() {
expect( 4 );
expect( 5 );
var loc = document.location,
otherPort = loc.port === 666 ? 667 : 666,
@ -420,6 +507,14 @@ test("jQuery ajax - cross-domain detection", function() {
}
});
jQuery.ajax({
url: 'app:/path',
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
@ -450,22 +545,7 @@ test("jQuery ajax - cross-domain detection", function() {
});
test(".ajax() - 304", function() {
expect( 1 );
stop();
jQuery.ajax({
url: url("data/notmodified.php"),
success: function(){ ok(true, "304 ok"); },
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
error: function(){ ok(jQuery.browser.opera, "304 not ok "); },
complete: function(xhr){ start(); }
});
});
test(".load()) - 404 error callbacks", function() {
test(".load() - 404 error callbacks", function() {
expect( 6 );
stop();
@ -856,7 +936,7 @@ test("serialize()", function() {
});
test("jQuery.param()", function() {
expect(22);
expect(24);
equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
@ -891,6 +971,9 @@ test("jQuery.param()", function() {
equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
// #7945
equals( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
jQuery.ajaxSetup({ traditional: true });
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
@ -919,6 +1002,9 @@ test("jQuery.param()", function() {
params = { param1: null };
equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
params = {'test': {'length': 3, 'foo': 'bar'} };
equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
});
test("synchronous request", function() {
@ -1124,6 +1210,21 @@ test("load(String, String, Function)", function() {
});
});
test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() {
expect(1);
stop();
jQuery.ajaxSetup({
data: "helloworld"
});
jQuery.get(url('data/echoQuery.php'), function(data) {
ok( /helloworld$/.test( data ), 'Data from ajaxSettings was used');
jQuery.ajaxSetup({
data: null
});
start();
});
});
test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
expect(2);
stop();
@ -1139,10 +1240,11 @@ test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", f
});
test("jQuery.getScript(String, Function) - with callback", function() {
expect(2);
expect(3);
stop();
jQuery.getScript(url("data/test.js"), function() {
jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) {
equals( foobar, "bar", 'Check if script was evaluated' );
strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
setTimeout(start, 100);
});
});
@ -1158,10 +1260,10 @@ test("jQuery.getScript(String, Function) - no callback", function() {
jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
test("jQuery.ajax() - JSONP, " + label, function() {
expect(17);
expect(20);
var count = 0;
function plus(){ if ( ++count == 17 ) start(); }
function plus(){ if ( ++count == 18 ) start(); }
stop();
@ -1265,23 +1367,6 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
}
});
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
data: {
callback: "?"
},
success: function(data){
ok( data.data, "JSON results returned (GET, processed data callback)" );
plus();
},
error: function(data){
ok( false, "Ajax error JSON (GET, processed data callback)" );
plus();
}
});
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
@ -1318,6 +1403,38 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
}
});
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
jsonpCallback: "functionToCleanUp",
success: function(data){
ok( data.data, "JSON results returned (GET, custom callback name to be cleaned up)" );
strictEqual( window.functionToCleanUp, undefined, "Callback was removed (GET, custom callback name to be cleaned up)" );
plus();
var xhr;
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
jsonpCallback: "functionToCleanUp",
beforeSend: function( jqXHR ) {
xhr = jqXHR;
return false;
}
});
xhr.error(function() {
ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
strictEqual( window.functionToCleanUp, undefined, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
plus();
});
},
error: function(data){
ok( false, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
plus();
}
});
jQuery.ajax({
type: "POST",
url: "data/jsonp.php",
@ -1480,17 +1597,23 @@ test("jQuery.ajax() - malformed JSON", function() {
});
test("jQuery.ajax() - script by content-type", function() {
expect(1);
expect(2);
stop();
jQuery.ajax({
url: "data/script.php",
data: { header: "script" },
success: function() {
start();
}
});
jQuery.when(
jQuery.ajax({
url: "data/script.php",
data: { header: "script" }
}),
jQuery.ajax({
url: "data/script.php",
data: { header: "ecma" }
})
).then( start, start );
});
test("jQuery.ajax() - json by content-type", function() {
@ -1593,17 +1716,32 @@ test("jQuery.getJSON(String, Function) - JSON object with absolute url to local
});
});
test("jQuery.post - data", function() {
expect(2);
test("jQuery.post - data", 3, function() {
stop();
jQuery.post(url("data/name.php"), {xml: "5-2", length: 3}, function(xml){
jQuery('math', xml).each(function() {
equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
equals( jQuery('result', this).text(), '3', 'Check for XML' );
});
start();
});
jQuery.when(
jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) {
jQuery( 'math', xml ).each( function() {
equals( jQuery( 'calculation', this ).text(), '5-2', 'Check for XML' );
equals( jQuery( 'result', this ).text(), '3', 'Check for XML' );
});
}),
jQuery.ajax({
url: url('data/echoData.php'),
type: "POST",
data: {
'test': {
'length': 7,
'foo': 'bar'
}
},
success: function( data ) {
strictEqual( data, 'test%5Blength%5D=7&test%5Bfoo%5D=bar', 'Check if a sub-object with a length param is serialized correctly');
}
})
).then( start, start );
});
test("jQuery.post(String, Hash, Function) - simple with xml", function() {
@ -1768,96 +1906,105 @@ test("data option: empty bodies for non-GET requests", function() {
});
});
test("jQuery.ajax - If-Modified-Since support", function() {
expect( 3 );
var ifModifiedNow = new Date();
stop();
jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ) {
var url = "data/if_modified_since.php?ts=" + new Date();
test("jQuery.ajax - If-Modified-Since support" + label, function() {
expect( 3 );
jQuery.ajax({
url: url,
ifModified: true,
success: function(data, status) {
equals(status, "success");
stop();
jQuery.ajax({
url: url,
ifModified: true,
success: function(data, status) {
if ( data === "FAIL" ) {
ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
} else {
equals(status, "notmodified");
ok(data == null, "response body should be empty");
var url = "data/if_modified_since.php?ts=" + ifModifiedNow++;
jQuery.ajax({
url: url,
ifModified: true,
cache: cache,
success: function(data, status) {
equals(status, "success" );
jQuery.ajax({
url: url,
ifModified: true,
cache: cache,
success: function(data, status) {
if ( data === "FAIL" ) {
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
} else {
equals(status, "notmodified");
ok(data == null, "response body should be empty");
}
start();
},
error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
ok(jQuery.browser.opera, "error");
start();
}
start();
},
error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
ok(jQuery.browser.opera, "error");
start();
}
});
},
error: function() {
equals(false, "error");
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
start();
}
});
},
error: function() {
equals(false, "error");
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
start();
}
});
});
});
test("jQuery.ajax - Etag support", function() {
expect( 3 );
test("jQuery.ajax - Etag support" + label, function() {
expect( 3 );
stop();
stop();
var url = "data/etag.php?ts=" + new Date();
var url = "data/etag.php?ts=" + ifModifiedNow++;
jQuery.ajax({
url: url,
ifModified: true,
success: function(data, status) {
equals(status, "success");
jQuery.ajax({
url: url,
ifModified: true,
cache: cache,
success: function(data, status) {
equals(status, "success" );
jQuery.ajax({
url: url,
ifModified: true,
success: function(data, status) {
if ( data === "FAIL" ) {
ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
} else {
equals(status, "notmodified");
ok(data == null, "response body should be empty");
jQuery.ajax({
url: url,
ifModified: true,
cache: cache,
success: function(data, status) {
if ( data === "FAIL" ) {
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
} else {
equals(status, "notmodified");
ok(data == null, "response body should be empty");
}
start();
},
error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
ok(jQuery.browser.opera, "error");
start();
}
start();
},
error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
ok(jQuery.browser.opera, "error");
start();
}
});
},
error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
start();
}
});
},
error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(jQuery.browser.opera, "error");
start();
}
});
});
});
@ -1949,16 +2096,16 @@ test( "jQuery.ajax - statusCode" , function() {
}).statusCode( createStatusCodes( "immediately with method" , isSuccess ) );
jQuery.ajax( url( uri ) , {
complete: function(jXHR) {
jXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
complete: function(jqXHR) {
jqXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
countComplete();
}
});
jQuery.ajax( url( uri ) , {
complete: function(jXHR) {
complete: function(jqXHR) {
setTimeout( function() {
jXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
jqXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
countComplete();
} , 100 );
}
@ -1966,10 +2113,10 @@ test( "jQuery.ajax - statusCode" , function() {
jQuery.ajax( url( uri ) , {
statusCode: createStatusCodes( "all (options)" , isSuccess ),
complete: function(jXHR) {
jXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
complete: function(jqXHR) {
jqXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
setTimeout( function() {
jXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
jqXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
countComplete();
} , 100 );
}
@ -1978,22 +2125,22 @@ test( "jQuery.ajax - statusCode" , function() {
var testString = "";
jQuery.ajax( url( uri ), {
success: function( a , b , jXHR ) {
success: function( a , b , jqXHR ) {
ok( isSuccess , "success" );
var statusCode = {};
statusCode[ jXHR.status ] = function() {
statusCode[ jqXHR.status ] = function() {
testString += "B";
};
jXHR.statusCode( statusCode );
jqXHR.statusCode( statusCode );
testString += "A";
},
error: function( jXHR ) {
error: function( jqXHR ) {
ok( ! isSuccess , "error" );
var statusCode = {};
statusCode[ jXHR.status ] = function() {
statusCode[ jqXHR.status ] = function() {
testString += "B";
};
jXHR.statusCode( statusCode );
jqXHR.statusCode( statusCode );
testString += "A";
},
complete: function() {
@ -2016,12 +2163,12 @@ test("jQuery.ajax - transitive conversions", function() {
jQuery.ajax( url("data/json.php") , {
converters: {
"json myjson": function( data ) {
"json myJson": function( data ) {
ok( true , "converter called" );
return data;
}
},
dataType: "myjson",
dataType: "myJson",
success: function() {
ok( true , "Transitive conversion worked" );
strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" );
@ -2031,13 +2178,13 @@ test("jQuery.ajax - transitive conversions", function() {
jQuery.ajax( url("data/json.php") , {
converters: {
"json myjson": function( data ) {
"json myJson": function( data ) {
ok( true , "converter called (*)" );
return data;
}
},
contents: false, /* headers are wrong so we ignore them */
dataType: "* myjson",
dataType: "* myJson",
success: function() {
ok( true , "Transitive conversion worked (*)" );
strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" );
@ -2049,6 +2196,53 @@ test("jQuery.ajax - transitive conversions", function() {
});
test("jQuery.ajax - overrideMimeType", function() {
expect( 2 );
stop();
jQuery.when(
jQuery.ajax( url("data/json.php") , {
beforeSend: function( xhr ) {
xhr.overrideMimeType( "application/json" );
},
success: function( json ) {
ok( json.data , "Mimetype overriden using beforeSend" );
}
}),
jQuery.ajax( url("data/json.php") , {
mimeType: "application/json",
success: function( json ) {
ok( json.data , "Mimetype overriden using mimeType option" );
}
})
).then( start , start );
});
test("jQuery.ajax - abort in prefilter", function() {
expect( 1 );
jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
if ( options.abortInPrefilter ) {
jqXHR.abort();
}
});
strictEqual( jQuery.ajax({
abortInPrefilter: true,
error: function() {
ok( false, "error callback called" );
}
}), false, "Request was properly aborted early by the prefilter" );
});
test("jQuery.ajax - active counter", function() {
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
});

View file

@ -546,6 +546,25 @@ test("val(Function) with incoming value", function() {
equals( 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)
test("val(select) after form.reset() (Bug #2551)", function() {
expect(3);
jQuery('<form id="kk" name="kk"><select id="kkk"><option value="cf">cf</option><option value="gf">gf</option></select></form>').appendTo("#main");
jQuery("#kkk").val( "gf" );
document.kk.reset();
equal( jQuery("#kkk")[0].value, "cf", "Check value of select after form reset." );
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
same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
jQuery("#kk").remove();
});
var testAddClass = function(valueObj) {
expect(5);
var div = jQuery("div");

View file

@ -537,29 +537,29 @@ test("end()", function() {
test("length", function() {
expect(1);
equals( jQuery("p").length, 6, "Get Number of Elements Found" );
equals( jQuery("#main p").length, 6, "Get Number of Elements Found" );
});
test("size()", function() {
expect(1);
equals( jQuery("p").size(), 6, "Get Number of Elements Found" );
equals( jQuery("#main p").size(), 6, "Get Number of Elements Found" );
});
test("get()", function() {
expect(1);
same( jQuery("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
same( jQuery("#main p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
});
test("toArray()", function() {
expect(1);
same( jQuery("p").toArray(),
same( jQuery("#main p").toArray(),
q("firstp","ap","sndp","en","sap","first"),
"Convert jQuery object to an Array" )
})
test("get(Number)", function() {
expect(2);
equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
equals( jQuery("#main p").get(0), document.getElementById("firstp"), "Get A Single Element" );
strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
});
@ -1129,11 +1129,60 @@ test("jQuery.when() - joined", function() {
});
});
test("jQuery.subclass", function(){
test("jQuery.sub() - Static Methods", function(){
expect(18);
var Subclass = jQuery.sub();
Subclass.extend({
topLevelMethod: function() {return this.debug;},
debug: false,
config: {
locale: 'en_US'
},
setup: function(config) {
this.extend(true, this.config, config);
}
});
Subclass.fn.extend({subClassMethod: function() { return this;}});
//Test Simple Subclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
//Create a SubSubclass
var SubSubclass = Subclass.sub();
//Make Sure the SubSubclass inherited properly
ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true');
ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!');
same(SubSubclass.config.test, undefined, 'SubSubclass.config.test is set incorrectly');
equal(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
//Modify The Subclass and test the Modifications
SubSubclass.fn.extend({subSubClassMethod: function() { return this;}});
SubSubclass.setup({locale: 'es_MX', test: 'worked'});
SubSubclass.debug = true;
SubSubclass.ajax = function() {return false;};
ok(SubSubclass.topLevelMethod(), 'SubSubclass.topLevelMethod thought debug was false');
same(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, 'Methods Differ!');
ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!');
ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly');
notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
//This shows that the modifications to the SubSubClass did not bubble back up to it's superclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
same(Subclass(document).subSubClassMethod, undefined, 'subSubClassMethod set incorrectly');
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
});
test("jQuery.sub() - .fn Methods", function(){
expect(378);
var Subclass = jQuery.subclass(),
SubclassSubclass = Subclass.subclass(),
var Subclass = jQuery.sub(),
SubclassSubclass = Subclass.sub(),
jQueryDocument = jQuery(document),
selectors, contexts, methods, method, arg, description;

View file

@ -180,15 +180,28 @@ test(".data()", function() {
var div = jQuery("#foo");
strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
div.data("test", "success");
same( div.data(), {test: "success"}, "data() get the entire data object" );
var dataObj = div.data();
// TODO: Remove this hack which was introduced in 1.5.1
delete dataObj.toJSON;
same( dataObj, {test: "success"}, "data() get the entire data object" );
strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
var nodiv = jQuery("#unfound");
equals( nodiv.data(), null, "data() on empty set returns null" );
var obj = { foo: "bar" };
deepEqual( jQuery(obj).data(), {}, "Retrieve data object from a wrapped JS object (#7524)" );
})
jQuery(obj).data("foo", "baz");
dataObj = jQuery.extend(true, {}, jQuery(obj).data());
// TODO: Remove this hack which was introduced for 1.5.1
delete dataObj.toJSON;
deepEqual( dataObj, { foo: "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
});
test(".data(String) and .data(String, Object)", function() {
expect(29);
@ -461,4 +474,15 @@ test(".removeData()", function() {
div.removeData("test.foo");
equals( div.data("test.foo"), undefined, "Make sure data is intact" );
});
});
if (window.JSON && window.JSON.stringify) {
test("JSON serialization (#8108)", function () {
expect(1);
var obj = { foo: "bar" };
jQuery.data(obj, "hidden", true);
equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" );
});
}

146
test/unit/effects.js vendored
View file

@ -39,24 +39,23 @@ test("show()", function() {
ok( pass, "Show" );
var speeds = {
"null speed": null,
"undefined speed": undefined,
"empty string speed": "",
"false speed": false
"null speed": null,
"undefined speed": undefined,
"empty string speed": "",
"false speed": false
};
jQuery.each(speeds, function(name, speed) {
pass = true;
div.hide().show(speed).each(function() {
if ( this.style.display == "none" ) pass = false;
});
ok( pass, "Show with " + name);
});
pass = true;
div.hide().show(speed).each(function() {
if ( this.style.display == "none" ) pass = false;
});
ok( pass, "Show with " + name);
});
jQuery.each(speeds, function(name, speed) {
pass = true;
div.hide().show(speed, function() {
pass = true;
div.hide().show(speed, function() {
pass = false;
});
ok( pass, "Show with " + name + " does not call animate callback" );
@ -132,9 +131,9 @@ test("show(Number) - other displays", function() {
// Supports #7397
// Supports #7397
test("Persist correct display value", function() {
expect(3);
expect(3);
QUnit.reset();
stop();
@ -142,31 +141,25 @@ test("Persist correct display value", function() {
jQuery("#main").append('<div id="show-tests"><span style="position:absolute;">foo</span></div>');
var $span = jQuery("#show-tests span"),
displayNone = $span.css("display"),
display = '', num = 0;
displayNone = $span.css("display"),
display = '', num = 0;
$span.show();
$span.show();
display = $span.css("display");
display = $span.css("display");
$span.hide();
$span.hide();
$span.fadeIn(100, function() {
equals($span.css("display"), display, "Expecting display: " + display);
$span.fadeOut(100, function () {
equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
$span.fadeIn(100, function() {
equals($span.css("display"), display, "Expecting display: " + display);
start();
});
});
});
$span.fadeIn(100, function() {
equals($span.css("display"), display, "Expecting display: " + display);
$span.fadeOut(100, function () {
equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
$span.fadeIn(100, function() {
equals($span.css("display"), display, "Expecting display: " + display);
start();
});
});
});
});
test("animate(Hash, Object, Function)", function() {
@ -565,21 +558,54 @@ jQuery.checkOverflowDisplay = function(){
start();
}
test("support negative values < -10000 (bug #7193)", function () {
expect(1);
stop();
test( "jQuery.fx.prototype.cur()", 6, function() {
var div = jQuery( "<div></div>" ).appendTo( "#main" ).css({
color: "#ABC",
border: "5px solid black",
left: "auto",
marginBottom: "-11000px"
})[0];
jQuery.extend(jQuery.fx.step, {
"marginBottom": function(fx) {
equals( fx.cur(), -11000, "Element has margin-bottom of -11000" );
delete jQuery.fx.step.marginBottom;
equals(
( new jQuery.fx( div, {}, "color" ) ).cur(),
jQuery.css( div, "color" ),
"Return the same value as jQuery.css for complex properties (bug #7912)"
);
strictEqual(
( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
5,
"Return simple values parsed as Float"
);
// backgroundPosition actually returns 0% 0% in most browser
// this fakes a "" return
jQuery.cssHooks.backgroundPosition = {
get: function() {
ok( true, "hook used" );
return "";
}
});
};
jQuery("#main").css("marginBottom", "-11000px").animate({ marginBottom: "-11001px" }, {
duration: 1,
complete: start
});
strictEqual(
( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
0,
"Return 0 when jQuery.css returns an empty string"
);
delete jQuery.cssHooks.backgroundPosition;
strictEqual(
( new jQuery.fx( div, {}, "left" ) ).cur(),
0,
"Return 0 when jQuery.css returns 'auto'"
);
equals(
( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
-11000,
"support negative values < -10000 (bug #7193)"
);
});
test("JS Overflow and Display", function() {
@ -803,7 +829,7 @@ test("Chain toggle out", function() {
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
});
test("Chain toggle out with easing and callback", function() {
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
});
test("Chain slideDown slideUp", function() {
jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
@ -850,16 +876,16 @@ jQuery.makeTest.id = 1;
test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
expect(4);
stop();
stop();
var $checkedtest = jQuery("#checkedtest");
// IE6 was clearing "checked" in jQuery(elem).show("fast");
$checkedtest.hide().show("fast", function() {
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
start();
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
start();
});
});
@ -926,3 +952,13 @@ test("hide hidden elements, with animation (bug #7141)", function() {
});
});
});
test("animate unit-less properties (#4966)", 2, function() {
stop();
var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#main" );
equal( div.css( "z-index" ), "0", "z-index is 0" );
div.animate({ zIndex: 2 }, function() {
equal( div.css( "z-index" ), "2", "z-index is 2" );
start();
});
});

View file

@ -2,22 +2,16 @@ module("event", { teardown: moduleTeardown });
test("null or undefined handler", function() {
expect(2);
// Supports Fixes bug #7229
try {
// Supports Fixes bug #7229
try {
jQuery("#firstp").click(null);
ok(true, "Passing a null handler will not throw an exception");
} catch (e) {}
jQuery("#firstp").click(null);
ok(true, "Passing a null handler will not throw an exception");
} catch (e) {}
try {
jQuery("#firstp").click(undefined);
ok(true, "Passing an undefined handler will not throw an exception");
} catch (e) {}
try {
jQuery("#firstp").click(undefined);
ok(true, "Passing an undefined handler will not throw an exception");
} catch (e) {}
});
test("bind(), with data", function() {
@ -312,7 +306,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
// Use a native click so we don't get jQuery simulated bubbling
if ( document.createEvent ) {
var e = document.createEvent( 'MouseEvents' );
e.initEvent( "click", true, true );
e.initEvent( "click", true, true );
$jq[0].dispatchEvent(e);
}
else if ( $jq[0].click ) {
@ -367,38 +361,47 @@ test("bind(), trigger change on select", function() {
}).trigger('change');
});
test("bind(), namespaced events, cloned events", function() {
expect(6);
test("bind(), namespaced events, cloned events", 18, function() {
var firstp = jQuery( "#firstp" );
jQuery("#firstp").bind("custom.test",function(e){
ok(true, "Custom event triggered");
firstp.bind("custom.test",function(e){
ok(false, "Custom event triggered");
});
jQuery("#firstp").bind("click",function(e){
firstp.bind("click",function(e){
ok(true, "Normal click triggered");
equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
});
jQuery("#firstp").bind("click.test",function(e){
ok(true, "Namespaced click triggered");
firstp.bind("click.test",function(e){
var check = "click";
ok( true, "Namespaced click triggered" );
if ( e.namespace ) {
check += "test";
}
equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" );
});
// Trigger both bound fn (2)
jQuery("#firstp").trigger("click");
//clone(true) element to verify events are cloned correctly
firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) );
// Trigger one bound fn (1)
jQuery("#firstp").trigger("click.test");
// Trigger both bound fn (8)
firstp.trigger("click");
// Trigger one bound fn (4)
firstp.trigger("click.test");
// Remove only the one fn
jQuery("#firstp").unbind("click.test");
firstp.unbind("click.test");
// Trigger the remaining fn (1)
jQuery("#firstp").trigger("click");
// Trigger the remaining fn (4)
firstp.trigger("click");
// Remove the remaining fn
jQuery("#firstp").unbind(".test");
// Remove the remaining namespaced fn
firstp.unbind(".test");
// Trigger the remaining fn (0)
jQuery("#firstp").trigger("custom");
// Try triggering the custom event (0)
firstp.trigger("custom");
// using contents will get comments regular, text, and comment nodes
jQuery("#nonnodes").contents().bind("tester", function () {
@ -406,7 +409,7 @@ test("bind(), namespaced events, cloned events", function() {
}).trigger("tester");
// Make sure events stick with appendTo'd elements (which are cloned) #2027
jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("#main");
ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
});
@ -471,7 +474,7 @@ test("bind(), multi-namespaced events", function() {
test("bind(), with same function", function() {
expect(2)
var count = 0 , func = function(){
var count = 0, func = function(){
count++;
};
@ -548,7 +551,7 @@ test("bind(name, false), unbind(name, false)", function() {
});
test("bind()/trigger()/unbind() on plain object", function() {
expect( 8 );
expect( 7 );
var obj = {};
@ -570,7 +573,6 @@ test("bind()/trigger()/unbind() on plain object", function() {
var events = jQuery._data(obj, "events");
ok( events, "Object has events bound." );
equals( obj.events, undefined, "Events object on plain objects is not events" );
equals( typeof events, "function", "'events' expando is a function on plain objects." );
equals( obj.test, undefined, "Make sure that test event is not on the plain object." );
equals( obj.handle, undefined, "Make sure that the event handler is not on the plain object." );
@ -588,7 +590,7 @@ test("bind()/trigger()/unbind() on plain object", function() {
jQuery(obj).unbind("test");
equals( obj && obj[ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ].events, undefined, "Make sure events object is removed" );
});
@ -613,18 +615,18 @@ test("unbind(type)", function() {
message = "unbind many with function";
$elem.bind('error1 error2',error)
.unbind('error1 error2', error )
.trigger('error1').triggerHandler('error2');
.unbind('error1 error2', error )
.trigger('error1').triggerHandler('error2');
message = "unbind many"; // #3538
$elem.bind('error1 error2',error)
.unbind('error1 error2')
.trigger('error1').triggerHandler('error2');
.unbind('error1 error2')
.trigger('error1').triggerHandler('error2');
message = "unbind without a type or handler";
$elem.bind("error1 error2.test",error)
.unbind()
.trigger("error1").triggerHandler("error2");
.unbind()
.trigger("error1").triggerHandler("error2");
});
test("unbind(eventObject)", function() {
@ -1453,6 +1455,8 @@ test("live with change", function(){
});
test("live with submit", function() {
expect(5);
var count1 = 0, count2 = 0;
jQuery("#testForm").live("submit", function(ev) {
@ -1469,7 +1473,16 @@ test("live with submit", function() {
equals( count1, 1, "Verify form submit." );
equals( count2, 1, "Verify body submit." );
jQuery("#testForm input[name=sub1]").live("click", function(ev) {
ok( true, "cancelling submit still calls click handler" );
});
jQuery("#testForm input[name=sub1]")[0].click();
equals( count1, 2, "Verify form submit." );
equals( count2, 2, "Verify body submit." );
jQuery("#testForm").die("submit");
jQuery("#testForm input[name=sub1]").die("click");
jQuery("body").die("submit");
});

View file

@ -402,7 +402,8 @@ test("append(Function) with incoming value", function() {
});
test("append the same fragment with events (Bug #6997, 5566)", function () {
expect(2 + (document.fireEvent ? 1 : 0));
var doExtra = !jQuery.support.noCloneEvent && document.fireEvent;
expect(2 + (doExtra ? 1 : 0));
stop(1000);
var element;
@ -410,7 +411,7 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
// This patch modified the way that cloning occurs in IE; we need to make sure that
// native event handlers on the original object don't get disturbed when they are
// modified on the clone
if (!jQuery.support.noCloneEvent && document.fireEvent) {
if ( doExtra ) {
element = jQuery("div:first").click(function () {
ok(true, "Event exists on original after being unbound on clone");
jQuery(this).unbind('click');
@ -883,6 +884,19 @@ test("jQuery.clone() (#8017)", function() {
equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
});
test("clone() (#8070)", function () {
expect(2);
jQuery('<select class="test8070"></select><select class="test8070"></select>').appendTo('#main');
var selects = jQuery('.test8070');
selects.append('<OPTION>1</OPTION><OPTION>2</OPTION>');
equals( selects[0].childNodes.length, 2, "First select got two nodes" );
equals( selects[1].childNodes.length, 2, "Second select got two nodes" );
selects.remove();
});
test("clone()", function() {
expect(37);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
@ -940,6 +954,17 @@ test("clone()", function() {
div.remove();
clone.remove();
var divEvt = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
ok( false, "Bound event still exists after .clone()." );
}),
cloneEvt = divEvt.clone();
// Make sure that doing .clone() doesn't clone events
cloneEvt.trigger("click");
cloneEvt.remove();
divEvt.remove();
// 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.
@ -982,7 +1007,7 @@ test("clone()", function() {
test("clone(form element) (Bug #3879, #6655)", function() {
expect(6);
element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
var element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
@ -991,7 +1016,7 @@ test("clone(form element) (Bug #3879, #6655)", function() {
equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
equals( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
equals( clone[0].defaultChecked, !jQuery.support.noCloneEvent, "Checked input defaultChecked cloned correctly" );
equals( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" );
element = jQuery("<input type='text' value='foo'>");
clone = element.clone();
@ -1002,6 +1027,14 @@ test("clone(form element) (Bug #3879, #6655)", function() {
equals( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
});
test("clone(multiple selected options) (Bug #8129)", function() {
expect(1);
var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>");
equals( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" );
});
if (!isLocal) {
test("clone() on XML nodes", function() {
expect(2);

View file

@ -1,510 +0,0 @@
module("selector", { teardown: moduleTeardown });
test("element", function() {
expect(21);
QUnit.reset();
ok( jQuery("*").size() >= 30, "Select all" );
var all = jQuery("*"), good = true;
for ( var i = 0; i < all.length; i++ )
if ( all[i].nodeType == 8 )
good = false;
ok( good, "Select all elements, no comment nodes" );
t( "Element Selector", "p", ["firstp","ap","sndp","en","sap","first"] );
t( "Element Selector", "body", ["body"] );
t( "Element Selector", "html", ["html"] );
t( "Parent Element", "div p", ["firstp","ap","sndp","en","sap","first"] );
equals( jQuery("param", "#object1").length, 2, "Object/param as context" );
same( jQuery("p", document.getElementsByTagName("div")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
same( jQuery("p", "div").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
same( jQuery("p", jQuery("div")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
same( jQuery("div").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
same( jQuery("#form").find("select").get(), q("select1","select2","select3","select4","select5"), "Finding selects with a context." );
ok( jQuery("#length").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
ok( jQuery("#lengthtest input").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
// Check for unique-ness and sort order
same( jQuery("p, div p").get(), jQuery("p").get(), "Check for duplicates: p, div p" );
t( "Checking sort order", "h2, h1", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
t( "Checking sort order", "h2:first, h1:first", ["qunit-header", "qunit-banner"] );
t( "Checking sort order", "p, p a", ["firstp", "simon1", "ap", "google", "groups", "anchor1", "mark", "sndp", "en", "yahoo", "sap", "anchor2", "simon", "first"] );
// Test Conflict ID
same( jQuery("#lengthtest").find("#idTest").get(), q("idTest"), "Finding element with id of ID." );
same( jQuery("#lengthtest").find("[name='id']").get(), q("idTest"), "Finding element with id of ID." );
same( jQuery("#lengthtest").find("input[id='idTest']").get(), q("idTest"), "Finding elements with a context." );
});
if ( location.protocol != "file:" ) {
test("XML Document Selectors", function() {
expect(8);
stop();
jQuery.get("data/with_fries.xml", function(xml) {
equals( jQuery("foo_bar", xml).length, 1, "Element Selector with underscore" );
equals( jQuery(".component", xml).length, 1, "Class selector" );
equals( jQuery("[class*=component]", xml).length, 1, "Attribute selector for class" );
equals( jQuery("property[name=prop2]", xml).length, 1, "Attribute selector with name" );
equals( jQuery("[name=prop2]", xml).length, 1, "Attribute selector with name" );
equals( jQuery("#seite1", xml).length, 1, "Attribute selector with ID" );
equals( jQuery("component#seite1", xml).length, 1, "Attribute selector with ID" );
equals( jQuery("component", xml).filter("#seite1").length, 1, "Attribute selector filter with ID" );
start();
});
});
}
test("broken", function() {
expect(19);
function broken(name, selector) {
try {
jQuery(selector);
ok( false, name + ": " + selector );
} catch(e){
ok( typeof e === "string" && e.indexOf("Syntax error") >= 0,
name + ": " + selector );
}
}
broken( "Broken Selector", "[", [] );
broken( "Broken Selector", "(", [] );
broken( "Broken Selector", "{", [] );
broken( "Broken Selector", "<", [] );
broken( "Broken Selector", "()", [] );
broken( "Broken Selector", "<>", [] );
broken( "Broken Selector", "{}", [] );
broken( "Doesn't exist", ":visble", [] );
broken( "Nth-child", ":nth-child", [] );
broken( "Nth-child", ":nth-child(-)", [] );
// Sigh. WebKit thinks this is a real selector in qSA
// They've already fixed this and it'll be coming into
// current browsers soon.
//broken( "Nth-child", ":nth-child(asdf)", [] );
broken( "Nth-child", ":nth-child(2n+-0)", [] );
broken( "Nth-child", ":nth-child(2+0)", [] );
broken( "Nth-child", ":nth-child(- 1n)", [] );
broken( "Nth-child", ":nth-child(-1 n)", [] );
broken( "First-child", ":first-child(n)", [] );
broken( "Last-child", ":last-child(n)", [] );
broken( "Only-child", ":only-child(n)", [] );
// Make sure attribute value quoting works correctly. See: #6093
var attrbad = jQuery('<input type="hidden" value="2" name="foo.baz" id="attrbad1"/><input type="hidden" value="2" name="foo[baz]" id="attrbad2"/>').appendTo("body");
broken( "Attribute not escaped", "input[name=foo.baz]", [] );
broken( "Attribute not escaped", "input[name=foo[baz]]", [] );
attrbad.remove();
});
test("id", function() {
expect(29);
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 non-existant 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, 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 with no children", "#firstUL > *", [] );
var a = jQuery('<div><a name="tName1">tName1 A</a><a name="tName2">tName2 A</a><div id="tName1">tName1 Div</div></div>').appendTo('#main');
equals( jQuery("#tName1")[0].id, 'tName1', "ID selector with same value for a name attribute" );
equals( jQuery("#tName2").length, 0, "ID selector non-existing but name attribute on an A tag" );
a.remove();
t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] );
t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986
same( jQuery("body").find("div#form").get(), [], "ID selector within the context of another element" );
//#7533
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" );
t( "Underscore ID", "#types_all", ["types_all"] );
t( "Dash ID", "#fx-queue", ["fx-queue"] );
t( "ID with weird characters in it", "#name\\+value", ["name+value"] );
});
test("class", function() {
expect(22);
t( "Class Selector", ".blog", ["mark","simon"] );
t( "Class Selector", ".GROUPS", ["groups"] );
t( "Class Selector", ".blog.link", ["simon"] );
t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
t( "Parent Class Selector", "p .blog", ["mark","simon"] );
same( jQuery(".blog", document.getElementsByTagName("p")).get(), q("mark", "simon"), "Finding elements with a context." );
same( jQuery(".blog", "p").get(), q("mark", "simon"), "Finding elements with a context." );
same( jQuery(".blog", jQuery("p")).get(), q("mark", "simon"), "Finding elements with a context." );
same( jQuery("p").find(".blog").get(), q("mark", "simon"), "Finding elements with a context." );
t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] );
//t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] );
t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] );
t( "Escaped Class", ".foo\\:bar", ["foo:bar"] );
t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] );
t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
var div = document.createElement("div");
div.innerHTML = "<div class='test e'></div><div class='test'></div>";
same( jQuery(".e", div).get(), [ div.firstChild ], "Finding a second class." );
div.lastChild.className = "e";
same( jQuery(".e", div).get(), [ div.firstChild, div.lastChild ], "Finding a modified class." );
});
test("name", function() {
expect(15);
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 non-input", "[name=test]", ["length", "fx-queue"] );
t( "Name selector non-input", "[name=div]", ["fadein"] );
t( "Name selector non-input", "*[name=iframe]", ["iframe"] );
t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] )
same( jQuery("#form").find("input[name=action]").get(), q("text1"), "Name selector within the context of another element" );
same( jQuery("#form").find("input[name='foo[bar]']").get(), q("hidden2"), "Name selector for grouped form element within the context of another element" );
var form = jQuery("<form><input name='id'/></form>").appendTo("body");
equals( form.find("input").length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
form.remove();
var a = jQuery('<div><a id="tName1ID" name="tName1">tName1 A</a><a id="tName2ID" name="tName2">tName2 A</a><div id="tName1">tName1 Div</div></div>').appendTo('#main').children();
equals( a.length, 3, "Make sure the right number of elements were inserted." );
equals( a[1].id, "tName2ID", "Make sure the right number of elements were inserted." );
equals( jQuery("[name=tName1]")[0], a[0], "Find elements that have similar IDs" );
equals( jQuery("[name=tName2]")[0], a[1], "Find elements that have similar IDs" );
t( "Find elements that have similar IDs", "#tName2ID", ["tName2ID"] );
a.remove();
});
test("multiple", function() {
expect(4);
t( "Comma Support", "h2, p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"]);
t( "Comma Support", "h2 , p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"]);
t( "Comma Support", "h2 , p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"]);
t( "Comma Support", "h2,p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"]);
});
test("child and adjacent", function() {
expect(31);
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", "#main a + a", ["groups"] );
t( "Adjacent", "#main a +a", ["groups"] );
t( "Adjacent", "#main a+ a", ["groups"] );
t( "Adjacent", "#main a+a", ["groups"] );
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( "Comma, Child, and Adjacent", "#main a + a, code > a", ["groups","anchor1","anchor2"] );
t( "Element Preceded By", "p ~ div", ["foo", "moretests","tabindex-tests", "liveHandlerOrder", "siblingTest"] );
t( "Element Preceded By", "#first ~ div", ["moretests","tabindex-tests", "liveHandlerOrder", "siblingTest"] );
t( "Element Preceded By", "#groups ~ a", ["mark"] );
t( "Element Preceded By", "#length ~ input", ["idTest"] );
t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext"] );
same( jQuery("#siblingfirst").find("~ em").get(), q("siblingnext"), "Element Preceded By with a context." );
same( jQuery("#siblingfirst").find("+ em").get(), q("siblingnext"), "Element Directly Preceded By with a context." );
var a = jQuery("<div id='foo'></div><p id='bar'></p><p id='bar2'></p>");
same( jQuery("~ p", a[0]).get(), [a[1], a[2]], "Detached Element Directly Preceded By with a context." );
same( jQuery("+ p", a[0]).get(), [a[1]], "Detached Element Preceded By with a context." );
t( "Verify deep class selector", "div.blah > p > a", [] );
t( "No element deep selector", "div.foo > span > a", [] );
same( jQuery("> :first", document.getElementById("nothiddendiv")).get(), q("nothiddendivchild"), "Verify child context positional selctor" );
same( jQuery("> :eq(0)", document.getElementById("nothiddendiv")).get(), q("nothiddendivchild"), "Verify child context positional selctor" );
same( jQuery("> *:first", document.getElementById("nothiddendiv")).get(), q("nothiddendivchild"), "Verify child context positional selctor" );
t( "Non-existant ancestors", ".fototab > .thumbnails > a", [] );
});
test("attributes", function() {
expect(41);
t( "Attribute Exists", "a[title]", ["google"] );
t( "Attribute Exists", "*[title]", ["google"] );
t( "Attribute Exists", "[title]", ["google"] );
t( "Attribute Exists", "a[ title ]", ["google"] );
t( "Attribute Equals", "a[rel='bookmark']", ["simon1"] );
t( "Attribute Equals", 'a[rel="bookmark"]', ["simon1"] );
t( "Attribute Equals", "a[rel=bookmark]", ["simon1"] );
t( "Attribute Equals", "a[href='http://www.google.com/']", ["google"] );
t( "Attribute Equals", "a[ rel = 'bookmark' ]", ["simon1"] );
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( "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( "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"] );
var opt = document.getElementById("option1a"),
match = (window.Sizzle || window.jQuery.find).matchesSelector;
opt.setAttribute("test", "");
ok( match( opt, "[id*=option1][type!=checkbox]" ), "Attribute Is Not Equal Matches" );
ok( match( opt, "[id*=option1]" ), "Attribute With No Quotes Contains Matches" );
ok( match( opt, "[test=]" ), "Attribute With No Quotes No Content Matches" );
ok( match( opt, "[id=option1a]" ), "Attribute With No Quotes Equals Matches" );
ok( match( document.getElementById("simon1"), "a[href*=#]" ), "Attribute With No Quotes Href Contains Matches" );
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( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] );
// Make sure attribute value quoting works correctly. See: #6093
var attrbad = jQuery('<input type="hidden" value="2" name="foo.baz" id="attrbad1"/><input type="hidden" value="2" name="foo[baz]" id="attrbad2"/>').appendTo("body");
t("Find escaped attribute value", "input[name=foo\\.baz]", ["attrbad1"]);
t("Find escaped attribute value", "input[name=foo\\[baz\\]]", ["attrbad2"]);
attrbad.remove();
});
test("pseudo - child", function() {
expect(38);
t( "First Child", "p:first-child", ["firstp","sndp"] );
t( "Last Child", "p:last-child", ["sap"] );
t( "Only Child", "#main a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
t( "Empty", "ul:empty", ["firstUL"] );
t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
t( "First Child", "p:first-child", ["firstp","sndp"] );
t( "Nth Child", "p:nth-child(1)", ["firstp","sndp"] );
t( "Nth Child With Whitespace", "p:nth-child( 1 )", ["firstp","sndp"] );
t( "Not Nth Child", "p:not(:nth-child(1))", ["ap","en","sap","first"] );
// Verify that the child position isn't being cached improperly
jQuery("p:first-child").after("<div></div>");
jQuery("p:first-child").before("<div></div>").next().remove();
t( "First Child", "p:first-child", [] );
QUnit.reset();
t( "Last Child", "p:last-child", ["sap"] );
t( "Last Child", "#main a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon","liveLink1","liveLink2"] );
t( "Nth-child", "#main form#form > *:nth-child(2)", ["text1"] );
t( "Nth-child", "#main form#form > :nth-child(2)", ["text1"] );
t( "Nth-child", "#form select:first option:nth-child(-1)", [] );
t( "Nth-child", "#form select:first option:nth-child(3)", ["option1c"] );
t( "Nth-child", "#form select:first option:nth-child(0n+3)", ["option1c"] );
t( "Nth-child", "#form select:first option:nth-child(1n+0)", ["option1a", "option1b", "option1c", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(1n)", ["option1a", "option1b", "option1c", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(n)", ["option1a", "option1b", "option1c", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(+n)", ["option1a", "option1b", "option1c", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(even)", ["option1b", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(odd)", ["option1a", "option1c"] );
t( "Nth-child", "#form select:first option:nth-child(2n)", ["option1b", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(2n+1)", ["option1a", "option1c"] );
t( "Nth-child", "#form select:first option:nth-child(2n + 1)", ["option1a", "option1c"] );
t( "Nth-child", "#form select:first option:nth-child(+2n + 1)", ["option1a", "option1c"] );
t( "Nth-child", "#form select:first option:nth-child(3n)", ["option1c"] );
t( "Nth-child", "#form select:first option:nth-child(3n+1)", ["option1a", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(3n+2)", ["option1b"] );
t( "Nth-child", "#form select:first option:nth-child(3n+3)", ["option1c"] );
t( "Nth-child", "#form select:first option:nth-child(3n-1)", ["option1b"] );
t( "Nth-child", "#form select:first option:nth-child(3n-2)", ["option1a", "option1d"] );
t( "Nth-child", "#form select:first option:nth-child(3n-3)", ["option1c"] );
t( "Nth-child", "#form select:first option:nth-child(3n+0)", ["option1c"] );
t( "Nth-child", "#form select:first option:nth-child(-1n+3)", ["option1a", "option1b", "option1c"] );
t( "Nth-child", "#form select:first option:nth-child(-n+3)", ["option1a", "option1b", "option1c"] );
t( "Nth-child", "#form select:first option:nth-child(-1n + 3)", ["option1a", "option1b", "option1c"] );
});
test("pseudo - misc", function() {
expect(7);
t( "Headers", ":header", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
t( "Has Children - :has()", "p:has(a)", ["firstp","ap","en","sap"] );
var select = document.getElementById("select1");
ok( (window.Sizzle || window.jQuery.find).matchesSelector( select, ":has(option)" ), "Has Option Matches" );
t( "Text Contains", "a:contains(Google)", ["google","groups"] );
t( "Text Contains", "a:contains(Google Groups)", ["groups"] );
t( "Text Contains", "a:contains(Google Groups (Link))", ["groups"] );
t( "Text Contains", "a:contains((Link))", ["groups"] );
});
test("pseudo - :not", function() {
expect(24);
t( "Not", "a.blog:not(.link)", ["mark"] );
t( "Not - multiple", "#form option:not(:contains(Nothing),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e", "option4e", "option5b", "option5c"] );
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
t( ":not() failing interior", "p:not(.foo)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(div.foo)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(p.foo)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(#blargh)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(div#blargh)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not() failing interior", "p:not(p#blargh)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not Multiple", "p:not(a)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not Multiple", "p:not(a, b)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not Multiple", "p:not(a, b, div)", ["firstp","ap","sndp","en","sap","first"] );
t( ":not Multiple", "p:not(p)", [] );
t( ":not Multiple", "p:not(a,p)", [] );
t( ":not Multiple", "p:not(p,a)", [] );
t( ":not Multiple", "p:not(a,p,b)", [] );
t( ":not Multiple", ":input:not(:image,:input,:submit)", [] );
t( "No element not selector", ".container div:not(.excluded) div", [] );
t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2", "select5"]);
t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3", "select4","select5"]);
t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3", "select4", "select5"]);
t( ":not() Multiple Class", "#foo a:not(.blog)", ["yahoo","anchor2"] );
t( ":not() Multiple Class", "#foo a:not(.link)", ["yahoo","anchor2"] );
t( ":not() Multiple Class", "#foo a:not(.blog.link)", ["yahoo","anchor2"] );
});
test("pseudo - position", function() {
expect(25);
t( "nth Element", "p:nth(1)", ["ap"] );
t( "First Element", "p:first", ["firstp"] );
t( "Last Element", "p:last", ["first"] );
t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
t( "Odd Elements", "p:odd", ["ap","en","first"] );
t( "Position Equals", "p:eq(1)", ["ap"] );
t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
t( "Check position filtering", "div#nothiddendiv:eq(0)", ["nothiddendiv"] );
t( "Check position filtering", "div#nothiddendiv:last", ["nothiddendiv"] );
t( "Check position filtering", "div#nothiddendiv:not(:gt(0))", ["nothiddendiv"] );
t( "Check position filtering", "#foo > :not(:first)", ["en", "sap"] );
t( "Check position filtering", "select > :not(:gt(2))", ["option1a", "option1b", "option1c"] );
t( "Check position filtering", "select:lt(2) :not(:first)", ["option1b", "option1c", "option1d", "option2a", "option2b", "option2c", "option2d"] );
t( "Check position filtering", "div.nothiddendiv:eq(0)", ["nothiddendiv"] );
t( "Check position filtering", "div.nothiddendiv:last", ["nothiddendiv"] );
t( "Check position filtering", "div.nothiddendiv:not(:lt(0))", ["nothiddendiv"] );
t( "Check element position", "div div:eq(0)", ["nothiddendivchild"] );
t( "Check element position", "div div:eq(5)", ["t2037"] );
t( "Check element position", "div div:eq(28)", ["hide"] );
t( "Check element position", "div div:first", ["nothiddendivchild"] );
t( "Check element position", "div > div:first", ["nothiddendivchild"] );
t( "Check element position", "#dl div:first div:first", ["foo"] );
t( "Check element position", "#dl div:first > div:first", ["foo"] );
t( "Check element position", "div#nothiddendiv:first > div:first", ["nothiddendivchild"] );
});
if ( (window.Sizzle || jQuery.find).selectors.filters.visibility ) {
test("pseudo - visibility", function() {
expect(11);
t( "Is Visible", "#form input:visible", [] );
t( "Is Visible", "div:visible:not(#qunit-testrunner-toolbar):lt(2)", ["nothiddendiv", "nothiddendivchild"] );
t( "Is Hidden", "#form input:hidden", ["text1","text2","radio1","radio2","check1","check2","hidden1","hidden2","name","search"] );
t( "Is Hidden", "#main:hidden", ["main"] );
t( "Is Hidden", "#dl:hidden", ["dl"] );
var $div = jQuery('<div/>').appendTo("body");
$div.css({ fontSize: 0, lineHeight: 0 });// IE also needs to set font-size and line-height to 0
$div.width(1).height(0);
t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
$div.width(0).height(1);
t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
$div.width(1).height(1);
t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
$div.remove();
});
}
test("pseudo - form", function() {
expect(8);
t( "Form element :input", "#form :input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "search", "button", "area1", "select1", "select2", "select3", "select4", "select5"] );
t( "Form element :radio", "#form :radio", ["radio1", "radio2"] );
t( "Form element :checkbox", "#form :checkbox", ["check1", "check2"] );
t( "Form element :text", "#form :text:not(#search)", ["text1", "text2", "hidden2", "name"] );
t( "Form element :radio:checked", "#form :radio:checked", ["radio2"] );
t( "Form element :checkbox:checked", "#form :checkbox:checked", ["check1"] );
t( "Form element :radio:checked, :checkbox:checked", "#form :radio:checked, #form :checkbox:checked", ["radio2", "check1"] );
t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c","option4b","option4c","option4d","option5a"] );
});

View file

@ -147,9 +147,9 @@ test("filter(Selector|undefined)", function() {
test("filter(Function)", function() {
expect(2);
same( jQuery("p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
same( jQuery("#main p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
same( jQuery("p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" );
same( jQuery("#main p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" );
});
test("filter(Element)", function() {
@ -228,7 +228,7 @@ test("not(Element)", function() {
});
test("not(Function)", function() {
same( jQuery("p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" );
same( jQuery("#main p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" );
});
test("not(Array)", function() {