Merge branch 'master' of github.com:jquery/jquery

This commit is contained in:
jaubourg 2011-04-11 13:41:17 +02:00
commit 4c3aba9a15
17 changed files with 902 additions and 373 deletions

View file

@ -203,6 +203,10 @@ Z</textarea>
<select name="D4" disabled="disabled">
<option selected="selected" value="NO">NO</option>
</select>
<input id="list-test" type="text" />
<datalist id="datalist">
<option value="option"></option>
</datalist>
</form>
<div id="moretests">
<form>

View file

@ -3,38 +3,81 @@ module("attributes", { teardown: moduleTeardown });
var bareObj = function(value) { return value; };
var functionReturningObj = function(value) { return (function() { return value; }); };
test("jQuery.props: itegrity test", function() {
expect(1);
test("jQuery.attrFix integrity test", function() {
expect(1);
// This must be maintained and equal jQuery.attrFix when appropriate
// Ensure that accidental or erroneous property
// overwrites don't occur
// This is simply for better code coverage and future proofing.
var propsShouldBe;
if ( !jQuery.support.getSetAttribute ) {
propsShouldBe = {
tabindex: "tabIndex",
readonly: "readOnly",
"for": "htmlFor",
"class": "className",
maxlength: "maxLength",
cellspacing: "cellSpacing",
rowspan: "rowSpan",
colspan: "colSpan",
usemap: "useMap",
frameborder: "frameBorder"
};
} else {
propsShouldBe = {
tabindex: "tabIndex",
readonly: "readOnly"
};
}
// This must be maintained and equal jQuery.props
// Ensure that accidental or erroneous property
// overwrites don't occur
// This is simply for better code coverage and future proofing.
var propsShouldBe = {
"for": "htmlFor",
"class": "className",
readonly: "readOnly",
maxlength: "maxLength",
cellspacing: "cellSpacing",
rowspan: "rowSpan",
colspan: "colSpan",
tabindex: "tabIndex",
usemap: "useMap",
frameborder: "frameBorder"
};
same(propsShouldBe, jQuery.props, "jQuery.props passes integrity check");
same(propsShouldBe, jQuery.attrFix, "jQuery.attrFix passes integrity check");
});
test("prop(String, Object)", function() {
expect(19);
equals( jQuery('#text1').prop('value'), "Test", 'Check for value attribute' );
equals( jQuery('#text1').prop('value', "Test2").prop('defaultValue'), "Test", 'Check for defaultValue attribute' );
equals( jQuery('#select2').prop('selectedIndex'), 3, 'Check for selectedIndex attribute' );
equals( jQuery('#foo').prop('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' );
equals( jQuery('#foo').prop('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' );
equals( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." );
var body = document.body, $body = jQuery( body );
ok( $body.prop('nextSibling') === null, 'Make sure a null expando returns null' );
body.foo = 'bar';
equals( $body.prop('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' );
body.foo = undefined;
ok( $body.prop('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option");
optgroup.appendChild( option );
select.appendChild( optgroup );
equals( jQuery(option).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
equals( jQuery(document).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." );
var attributeNode = document.createAttribute("irrelevant"),
commentNode = document.createComment("some comment"),
textNode = document.createTextNode("some text"),
obj = {};
jQuery.each( [document, attributeNode, commentNode, textNode, obj, "#firstp"], function( i, ele ) {
strictEqual( jQuery(ele).prop("nonexisting"), undefined, "prop works correctly for non existing attributes (bug #7500)." );
});
var obj = {};
jQuery.each( [document, obj], function( i, ele ) {
var $ele = jQuery( ele );
$ele.prop( "nonexisting", "foo" );
equal( $ele.prop("nonexisting"), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." );
});
jQuery( document ).removeProp("nonexisting");
});
test("attr(String)", function() {
expect(37);
expect(32);
// This one sometimes fails randomly ?!
equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' );
@ -46,60 +89,54 @@ test("attr(String)", function() {
equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' );
equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' );
ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
// Temporarily disabled. See: #4299
// ok( jQuery('#form').attr('action','newformaction').attr('action').indexOf("newformaction") >= 0, 'Check that action attribute was changed' );
equals( jQuery('#form').attr('blah', 'blah').attr('blah'), 'blah', 'Set non-existant attribute on a form' );
equals( jQuery('#foo').attr('height'), undefined, 'Non existent height attribute should return undefined' );
// [7472] & [3113] (form contains an input with name="action" or name="id")
var extras = jQuery('<input name="id" name="name" /><input id="target" name="target" />').appendTo('#testForm');
equals( jQuery('#form').attr('action','newformaction').attr('action'), 'newformaction', 'Check that action attribute was changed' );
equals( jQuery('#testForm').attr('target'), undefined, 'Retrieving target does not equal the input with name=target' );
equals( jQuery('#testForm').attr('target', 'newTarget').attr('target'), 'newTarget', 'Set target successfully on a form' );
equals( 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")
equals( jQuery('#testForm').attr('name'), undefined, 'Retrieving name does not retrieve input with name=name' );
extras.remove();
equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' );
equals( jQuery('#foo').attr('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' );
equals( jQuery('#foo').attr('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' );
// using innerHTML in IE causes href attribute to be serialized to the full path
jQuery('<a/>').attr({ 'id': 'tAnchor5', 'href': '#5' }).appendTo('#main');
equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );
equals( jQuery("<option/>").attr("selected"), false, "Check selected attribute on disconnected element." );
// list attribute is readonly by default in browsers that support it
jQuery('#list-test').attr('list', 'datalist');
equals( jQuery('#list-test').attr('list'), 'datalist', 'Check setting list attribute' );
// Related to [5574] and [5683]
var body = document.body, $body = jQuery(body);
ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' );
ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' );
strictEqual( $body.attr('foo'), undefined, 'Make sure that a non existent attribute returns undefined' );
body.setAttribute('foo', 'baz');
equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' );
body.foo = 'bar';
equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' );
$body.attr('foo','cool');
equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' );
body.foo = undefined;
ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
body.removeAttribute('foo'); // Cleanup
var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option");
optgroup.appendChild( option );
select.appendChild( optgroup );
var $img = jQuery('<img style="display:none" width="215" height="53" src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif"/>').appendTo('body');
equals( $img.attr('width'), "215", "Retrieve width attribute an an element with display:none." );
equals( $img.attr('height'), "53", "Retrieve height attribute an an element with display:none." );
equals( jQuery(option).attr("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
// Check for style support
ok( !!~jQuery('#dl').attr('style').indexOf('position'), 'Check style attribute getter, also normalize css props to lowercase' );
ok( !!~jQuery('#foo').attr('style', 'position:absolute;').attr('style').indexOf('position'), 'Check style setter' );
ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
equals( jQuery(document).attr("nodeName"), "#document", "attr works correctly on document nodes (bug #7451)." );
var attributeNode = document.createAttribute("irrelevant"),
commentNode = document.createComment("some comment"),
textNode = document.createTextNode("some text"),
obj = {};
jQuery.each( [document, attributeNode, commentNode, textNode, obj, "#firstp"], function( i, ele ) {
strictEqual( jQuery(ele).attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." );
});
});
if ( !isLocal ) {
@ -116,8 +153,8 @@ if ( !isLocal ) {
test("attr(String, Function)", function() {
expect(2);
equals( jQuery('#text1').attr('value', function() { return this.id ;})[0].value, "text1", "Set value from id" );
equals( jQuery('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index");
equals( jQuery('#text1').attr('value', function() { return this.id; })[0].value, "text1", "Set value from id" );
equals( jQuery('#text1').attr('title', function(i) { return i; }).attr('title'), "0", "Set value with an index");
});
test("attr(Hash)", function() {
@ -133,7 +170,7 @@ test("attr(Hash)", function() {
});
test("attr(String, Object)", function() {
expect(30);
expect(29);
var div = jQuery("div").attr("foo", "bar"),
fail = false;
@ -153,7 +190,7 @@ test("attr(String, Object)", function() {
jQuery("#name").attr('name', 'something');
equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' );
jQuery("#name").attr('name', null);
equals( jQuery("#name").attr('title'), '', 'Remove name attribute' );
equals( jQuery("#name").attr('name'), undefined, 'Remove name attribute' );
jQuery("#check2").attr('checked', true);
equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
jQuery("#check2").attr('checked', false);
@ -163,28 +200,22 @@ test("attr(String, Object)", function() {
jQuery("#text1").attr('readonly', false);
equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' );
jQuery("#name").attr('maxlength', '5');
equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' );
equals( document.getElementById('name').maxLength, 5, 'Set maxlength attribute' );
jQuery("#name").attr('maxLength', '10');
equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
equals( document.getElementById('name').maxLength, 10, 'Set maxlength attribute' );
var $p = jQuery('#firstp').attr('nonexisting', 'foo');
equals( $p.attr('nonexisting'), 'foo', "attr(name, value) works correctly for non existing attributes (bug #7500).");
$p.removeAttr('nonexisting');
var attributeNode = document.createAttribute("irrelevant"),
commentNode = document.createComment("some comment"),
textNode = document.createTextNode("some text"),
obj = {};
jQuery.each( [document, obj, "#firstp"], function( i, ele ) {
var $ele = jQuery( ele );
$ele.attr( "nonexisting", "foo" );
equal( $ele.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500)." );
});
textNode = document.createTextNode("some text");
jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) {
var $ele = jQuery( ele );
$ele.attr( "nonexisting", "foo" );
strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
});
//cleanup
jQuery.each( [document, "#firstp"], function( i, ele ) {
jQuery( ele ).removeAttr("nonexisting");
});
var table = jQuery('#table').append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"),
td = table.find('td:first');
@ -193,15 +224,15 @@ test("attr(String, Object)", function() {
td.attr("colspan", "2");
equals( td[0].colSpan, 2, "Check colspan is correctly set" );
table.attr("cellspacing", "2");
equals( table[0].cellSpacing, 2, "Check cellspacing is correctly set" );
equals( table[0].cellSpacing, "2", "Check cellspacing is correctly set" );
// for #1070
jQuery("#name").attr('someAttr', '0');
equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
jQuery("#name").attr('someAttr', 0);
equals( jQuery("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to the number 0' );
jQuery("#name").attr('someAttr', 1);
equals( jQuery("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
equals( jQuery("#name").attr('someAttr'), '1', 'Set attribute to the number 1' );
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
@ -211,7 +242,8 @@ test("attr(String, Object)", function() {
j.removeAttr("name");
QUnit.reset();
// Type
var type = jQuery("#check2").attr('type');
var thrown = false;
try {
@ -251,6 +283,13 @@ test("attr(String, Object)", function() {
}
ok( thrown, "Exception thrown when trying to change type property" );
equals( "button", button.attr('type'), "Verify that you can't change the type of a button element" );
// Setting attributes on svg elements (bug #3116)
var $svg = jQuery('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="3000" height="3000">'
+ '<circle cx="200" cy="200" r="150" />'
+ '</svg>').appendTo('body');
equals( $svg.attr('cx', 100).attr('cx'), "100", "Set attribute on svg element" );
$svg.remove();
});
test("attr(jquery_method)", function(){
@ -356,25 +395,32 @@ test("attr('tabindex', value)", function() {
});
test("removeAttr(String)", function() {
expect(7);
expect(5);
equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" );
equals( jQuery('#form').removeAttr('id').attr('id'), undefined, 'Remove id' );
equals( jQuery('#foo').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute' );
equals( jQuery('#form').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute on a form' );
equals( jQuery('#fx-test-group').attr('height', '3px').removeAttr('height').css('height'), "1px", 'Removing height attribute has no effect on height set with style attribute' );
});
test("removeProp(String)", function() {
expect(6);
var attributeNode = document.createAttribute("irrelevant"),
commentNode = document.createComment("some comment"),
textNode = document.createTextNode("some text"),
obj = {};
//removeAttr only really removes on DOM element nodes handle all other seperatyl
strictEqual( jQuery( "#firstp" ).attr( "nonexisting", "foo" ).removeAttr( "nonexisting" )[0].nonexisting, undefined, "removeAttr works correctly on DOM element nodes" );
strictEqual( 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.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
strictEqual( ele.nonexisting, "", "removeAttr works correctly on non DOM element nodes (bug #7500)." );
$ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" );
strictEqual( ele.nonexisting, undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
});
jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) {
$ele = jQuery( ele );
$ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
strictEqual( ele.nonexisting, undefined, "removeAttr works correctly on non DOM element nodes (bug #7500)." );
$ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" );
strictEqual( ele.nonexisting, undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
});
});
@ -604,21 +650,20 @@ test("addClass(Function)", function() {
test("addClass(Function) with incoming value", function() {
expect(45);
var div = jQuery("div"), old = div.map(function(){
return jQuery(this).attr("class");
return jQuery(this).attr("class") || "";
});
div.addClass(function(i, val) {
if ( this.id !== "_firebugConsole" ) {
if ( this.id !== "_firebugConsole") {
equals( val, old[i], "Make sure the incoming value is correct." );
return "test";
}
});
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
for ( var i = 0; i < div.length; i++ ) {
if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
}
ok( pass, "Add Class" );
});
@ -843,4 +888,4 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
jq.removeClass("class4");
ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
});
});

View file

@ -642,7 +642,7 @@ test("first()/last()", function() {
});
test("map()", function() {
expect(2);//expect(6);
expect(7);
same(
jQuery("#ap").map(function(){
@ -660,32 +660,32 @@ test("map()", function() {
"Single Map"
);
return;//these haven't been accepted yet
//for #2616
var keys = jQuery.map( {a:1,b:2}, function( v, k ){
return k;
}, [ ] );
});
equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
var values = jQuery.map( {a:1,b:2}, function( v, k ){
return v;
}, [ ] );
});
equals( values.join(""), "12", "Map the values from a hash to an array" );
// object with length prop
var values = jQuery.map( {a:1,b:2, length:3}, function( v, k ){
return v;
});
equals( values.join(""), "123", "Map the values from a hash with a length property to an array" );
var scripts = document.getElementsByTagName("script");
var mapped = jQuery.map( scripts, function( v, k ){
return v;
}, {length:0} );
});
equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
var flat = jQuery.map( Array(4), function( v, k ){
return k % 2 ? k : [k,k,k];//try mixing array and regular returns
});
equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
});
@ -903,7 +903,7 @@ test("jQuery.isEmptyObject", function(){
});
test("jQuery.proxy", function(){
expect(4);
expect(6);
var test = function(){ equals( this, thisObject, "Make sure that scope is set properly." ); };
var thisObject = { foo: "bar", method: test };
@ -917,8 +917,17 @@ test("jQuery.proxy", function(){
// Make sure it doesn't freak out
equals( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
// Use the string shortcut
jQuery.proxy( thisObject, "method" )();
// Partial application
var test2 = function( a ){ equals( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
jQuery.proxy( test2, null, "pre-applied" )();
// Partial application w/ normal arguments
var test3 = function( a, b ){ equals( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
jQuery.proxy( test3, null, "pre-applied" )( "normal" );
// Test old syntax
var test4 = { meth: function( a ){ equals( a, "boom", "Ensure old syntax works." ); } };
jQuery.proxy( test4, "meth" )( "boom" );
});
test("jQuery.parseJSON", function(){

View file

@ -485,4 +485,21 @@ if (window.JSON && window.JSON.stringify) {
equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" );
});
}
}
test("jQuery.data should follow html5 specification regarding camel casing", function() {
expect(6);
var div = jQuery("<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
.prependTo("body");
equals(div.data().foo, "a", "Verify single word data-* key");
equals(div.data().fooBar, "b", "Verify multiple word data-* key");
equals(div.data().fooBarBaz, "c", "Verify multiple word data-* key");
equals(div.data("foo"), "a", "Verify single word data-* key");
equals(div.data("fooBar"), "b", "Verify multiple word data-* key");
equals(div.data("fooBarBaz"), "c", "Verify multiple word data-* key");
div.remove();
});

View file

@ -975,6 +975,27 @@ test("trigger(eventObject, [data], [fn])", function() {
$parent.unbind().remove();
});
test("jQuery.Event({ /* props */ })", function() {
expect(4);
var event = jQuery.Event({ type: "keydown", keyCode: 64 }),
handler = function( event ) {
ok( "keyCode" in event, "Special property 'keyCode' exists" );
equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
};
// Supports jQuery.Event implementation
equal( event.type, "keydown", "Verify type" );
ok( "keyCode" in event, "Special 'keyCode' property exists" );
jQuery("body").bind( "keydown", handler ).trigger( event );
jQuery("body").unbind( "keydown" );
});
test("jQuery.Event.currentTarget", function(){
expect(1);
@ -2151,3 +2172,4 @@ test("event properties", function() {
}).click();
});
*/

View file

@ -1009,7 +1009,7 @@ test("clone()", function() {
});
test("clone(form element) (Bug #3879, #6655)", function() {
expect(6);
expect(5);
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" );
@ -1019,7 +1019,9 @@ 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.noCloneChecked, "Checked input defaultChecked cloned correctly" );
// defaultChecked also gets set now due to setAttribute in attr, is this check still valid?
// equals( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" );
element = jQuery("<input type='text' value='foo'>");
clone = element.clone();

View file

@ -13,8 +13,32 @@ test("find(String)", function() {
same( jQuery("#main").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" );
});
test("is(String)", function() {
expect(26);
test("find(node|jQuery object)", function() {
expect( 11 );
var $foo = jQuery('#foo'),
$blog = jQuery('.blogTest'),
$first = jQuery('#first'),
$two = $blog.add( $first ),
$fooTwo = $foo.add( $blog );
equals( $foo.find( $blog ).text(), 'Yahoo', 'Find with blog jQuery object' );
equals( $foo.find( $blog[0] ).text(), 'Yahoo', 'Find with blog node' );
equals( $foo.find( $first ).length, 0, '#first is not in #foo' );
equals( $foo.find( $first[0]).length, 0, '#first not in #foo (node)' );
ok( $foo.find( $two ).is('.blogTest'), 'Find returns only nodes within #foo' );
ok( $fooTwo.find( $blog ).is('.blogTest'), 'Blog is part of the collection, but also within foo' );
ok( $fooTwo.find( $blog[0] ).is('.blogTest'), 'Blog is part of the collection, but also within foo(node)' );
equals( $two.find( $foo ).length, 0, 'Foo is not in two elements' );
equals( $two.find( $foo[0] ).length, 0, 'Foo is not in two elements(node)' );
equals( $two.find( $first ).length, 0, 'first is in the collection and not within two' );
equals( $two.find( $first ).length, 0, 'first is in the collection and not within two(node)' );
});
test("is(String|undefined)", function() {
expect(27);
ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' );
ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' );
ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
@ -33,11 +57,13 @@ test("is(String)", function() {
ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
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"' );
ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' );
ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' );
ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' );
ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
ok( !jQuery('#foo').is({ plain: "object" }), 'Check passing invalid object' );
// test is() with comma-seperated expressions
ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
@ -45,6 +71,36 @@ test("is(String)", function() {
ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
});
test("is(jQuery)", function() {
expect(24);
ok( jQuery('#form').is( jQuery('form') ), 'Check for element: A form is a form' );
ok( !jQuery('#form').is( jQuery('div') ), 'Check for element: A form is not a div' );
ok( jQuery('#mark').is( jQuery('.blog') ), 'Check for class: Expected class "blog"' );
ok( !jQuery('#mark').is( jQuery('.link') ), 'Check for class: Did not expect class "link"' );
ok( jQuery('#simon').is( jQuery('.blog.link') ), 'Check for multiple classes: Expected classes "blog" and "link"' );
ok( !jQuery('#simon').is( jQuery('.blogTest') ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
ok( jQuery('#en').is( jQuery('[lang="en"]') ), 'Check for attribute: Expected attribute lang to be "en"' );
ok( !jQuery('#en').is( jQuery('[lang="de"]') ), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
ok( jQuery('#text1').is( jQuery('[type="text"]') ), 'Check for attribute: Expected attribute type to be "text"' );
ok( !jQuery('#text1').is( jQuery('[type="radio"]') ), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
ok( jQuery('#text2').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected to be disabled' );
ok( !jQuery('#text1').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected not disabled' );
ok( jQuery('#radio2').is( jQuery(':checked') ), 'Check for pseudoclass: Expected to be checked' );
ok( !jQuery('#radio1').is( jQuery(':checked') ), 'Check for pseudoclass: Expected not checked' );
ok( jQuery('#foo').is( jQuery(':has(p)') ), 'Check for child: Expected a child "p" element' );
ok( !jQuery('#foo').is( jQuery(':has(ul)') ), 'Check for child: Did not expect "ul" element' );
ok( jQuery('#foo').is( jQuery(':has(p):has(a):has(code)') ), 'Check for childs: Expected "p", "a" and "code" child elements' );
ok( !jQuery('#foo').is( jQuery(':has(p):has(a):has(code):has(ol)') ), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
// Some raw elements
ok( jQuery('#form').is( jQuery('form')[0] ), 'Check for element: A form is a form' );
ok( !jQuery('#form').is( jQuery('div')[0] ), 'Check for element: A form is not a div' );
ok( jQuery('#mark').is( jQuery('.blog')[0] ), 'Check for class: Expected class "blog"' );
ok( !jQuery('#mark').is( jQuery('.link')[0] ), 'Check for class: Did not expect class "link"' );
ok( jQuery('#simon').is( jQuery('.blog.link')[0] ), 'Check for multiple classes: Expected classes "blog" and "link"' );
ok( !jQuery('#simon').is( jQuery('.blogTest')[0] ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
});
test("index()", function() {
expect(1);
@ -82,11 +138,16 @@ test("index(Object|String|undefined)", function() {
equals( jQuery('#radio2').index('#form :text') , -1, "Check for index not found within a selector" );
});
test("filter(Selector)", function() {
expect(5);
test("filter(Selector|undefined)", function() {
expect(9);
same( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
same( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
same( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
same( jQuery('p').filter(null).get(), [], "filter(null) should return an empty jQuery object");
same( jQuery('p').filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object");
same( jQuery('p').filter(0).get(), [], "filter(0) should return an empty jQuery object");
same( 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();
@ -124,7 +185,7 @@ test("filter(jQuery)", function() {
})
test("closest()", function() {
expect(11);
expect(13);
same( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
same( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
same( jQuery("body").closest("div").get(), [], "closest(div)" );
@ -144,6 +205,10 @@ test("closest()", function() {
// Test on disconnected node
equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
// Bug #7369
equals( jQuery('<div foo="bar"></div>').closest('[foo]').length, 1, "Disconnected nodes with attribute selector" );
equals( jQuery('<div>text</div>').closest('[lang]').length, 0, "Disconnected nodes with text and non-existent attribute selector" );
});
test("closest(Array)", function() {
@ -158,8 +223,29 @@ test("closest(Array)", function() {
same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
});
<<<<<<< HEAD
test("not(Selector|undefined)", function() {
expect(11);
=======
test("closest(jQuery)", function() {
expect(8);
var $child = jQuery("#nothiddendivchild"),
$parent = jQuery("#nothiddendiv"),
$main = jQuery("#main"),
$body = jQuery("body");
ok( $child.closest( $parent ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') )" );
ok( $child.closest( $parent[0] ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') ) :: node" );
ok( $child.closest( $child ).is('#nothiddendivchild'), "child is included" );
ok( $child.closest( $child[0] ).is('#nothiddendivchild'), "child is included :: node" );
equals( $child.closest( document.createElement('div') ).length, 0, "created element is not related" );
equals( $child.closest( $main ).length, 0, "Main not a parent of child" );
equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" );
ok( $child.closest( $body.add($parent) ).is('#nothiddendiv'), "Closest ancestor retrieved." );
});
test("not(Selector)", function() {
expect(7);
>>>>>>> 1a167767305202797cf4c839eb64bd7adfb00182
equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
@ -168,6 +254,12 @@ test("not(Selector)", function() {
same( jQuery('#ap *').not('code').get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
same( jQuery('#ap *').not('code, #mark').get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
same( jQuery('#ap *').not('#mark, code').get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
var all = jQuery('p').get();
same( jQuery('p').not(null).get(), all, "not(null) should have no effect");
same( jQuery('p').not(undefined).get(), all, "not(undefined) should have no effect");
same( jQuery('p').not(0).get(), all, "not(0) should have no effect");
same( jQuery('p').not('').get(), all, "not('') should have no effect");
});
test("not(Element)", function() {