X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=test%2Funit%2Fcore.js;h=bfaceca38bf3c8f28ee93d3ea0a76f0f4fa40914;hb=1382ea8d98aa6d72c4240e42471917a350308d67;hp=ea13de2c71c8f62fdb19610c0b6681ff941042d8;hpb=9f0c0cfec5412dee5d7843e0b0b130d58038853c;p=jquery.git
diff --git a/test/unit/core.js b/test/unit/core.js
index ea13de2..bfaceca 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -121,10 +121,10 @@ test("isFunction", function() {
// Check built-ins
// Safari uses "(Internal Function)"
- ok( jQuery.isFunction(String), "String Function" );
- ok( jQuery.isFunction(Array), "Array Function" );
- ok( jQuery.isFunction(Object), "Object Function" );
- ok( jQuery.isFunction(Function), "Function Function" );
+ ok( jQuery.isFunction(String), "String Function("+String+")" );
+ ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
+ ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
+ ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
// When stringified, this could be misinterpreted
var mystr = "function";
@@ -261,7 +261,7 @@ test("get(Number)", function() {
});
test("add(String|Element|Array|undefined)", function() {
- expect(8);
+ expect(12);
isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
@@ -280,6 +280,12 @@ test("add(String|Element|Array|undefined)", function() {
var notDefined;
equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
+
+ // Added after #2811
+ equals( $([]).add([window,document,document.body,document]).length, 3, "Pass an array" );
+ equals( $(document).add(document).length, 1, "Check duplicated elements" );
+ equals( $(window).add(window).length, 1, "Check duplicated elements using the window" );
+ ok( $([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
});
test("each(Function)", function() {
@@ -294,16 +300,23 @@ test("each(Function)", function() {
});
test("index(Object)", function() {
- expect(8);
- equals( $([window, document]).index(window), 0, "Check for index of elements" );
- equals( $([window, document]).index(document), 1, "Check for index of elements" );
- var inputElements = $('#radio1,#radio2,#check1,#check2');
+ expect(10);
+
+ var elements = $([window, document]),
+ inputElements = $('#radio1,#radio2,#check1,#check2');
+
+ equals( elements.index(window), 0, "Check for index of elements" );
+ equals( elements.index(document), 1, "Check for index of elements" );
equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" );
equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" );
equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" );
equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" );
equals( inputElements.index(window), -1, "Check for not found index" );
equals( inputElements.index(document), -1, "Check for not found index" );
+
+ // enabled since [5500]
+ equals( elements.index( elements ), 0, "Pass in a jQuery object" );
+ equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
});
test("attr(String)", function() {
@@ -361,13 +374,15 @@ test("attr(Hash)", function() {
test("attr(String, Object)", function() {
expect(17);
- var div = $("div");
- div.attr("foo", "bar");
- var pass = true;
+ var div = $("div").attr("foo", "bar");
+ fail = false;
for ( var i = 0; i < div.size(); i++ ) {
- if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
+ if ( div.get(i).getAttribute('foo') != "bar" ){
+ fail = i;
+ break;
+ }
}
- ok( pass, "Set Attribute" );
+ equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
@@ -399,7 +414,7 @@ test("attr(String, Object)", function() {
j.attr("name", "attrvalue");
equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
- j.removeAttr("name")
+ j.removeAttr("name");
reset();
@@ -1148,6 +1163,9 @@ test("html(String)", function() {
// using contents will get comments regular, text, and comment nodes
var j = $("#nonnodes").contents();
j.html("bold");
+
+ // this is needed, or the expando added by jQuery unique will yield a different html
+ j.find('b').removeData();
equals( j.html().toLowerCase(), "bold", "Check node,textnode,comment with html()" );
$("#main").html("");
@@ -1651,4 +1669,4 @@ test("$.makeArray", function(){
equals( $.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
ok( $.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
-});
\ No newline at end of file
+});