jquery core: Simplifying isEmptyObject() and adding tests.
[jquery.git] / test / unit / core.js
index fe2e992..8aa883a 100644 (file)
@@ -386,6 +386,12 @@ test("each(Function)", function() {
        ok( pass, "Execute a function, Relative" );
 });
 
+test("index()", function() {
+       expect(1);
+
+       equals( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" )
+});
+
 test("index(Object|String|undefined)", function() {
        expect(16);
 
@@ -435,7 +441,7 @@ test("jQuery.merge()", function() {
 });
 
 test("jQuery.extend(Object, Object)", function() {
-       expect(21);
+       expect(23);
 
        var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
                options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
@@ -463,9 +469,19 @@ test("jQuery.extend(Object, Object)", function() {
        var empty = {};
        var optionsWithLength = { foo: { length: -1 } };
        jQuery.extend(true, empty, optionsWithLength);
-
        isObj( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
 
+       empty = {};
+       var optionsWithDate = { foo: { date: new Date } };
+       jQuery.extend(true, empty, optionsWithDate);
+       isObj( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
+
+       var myKlass = function() {};
+       empty = {};
+       var optionsWithCustomObject = { foo: { date: new myKlass } };
+       jQuery.extend(true, empty, optionsWithCustomObject);
+       isObj( empty.foo, optionsWithCustomObject.foo, "Custom objects copy correctly" );
+
        var nullUndef;
        nullUndef = jQuery.extend({}, options, { xnumber2: null });
        ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
@@ -583,3 +599,13 @@ test("jQuery.makeArray", function(){
 
        ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
 });
+
+test("jQuery.isEmptyObject", function(){
+       expect(2);
+       
+       equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
+       equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
+       
+       // What about this ?
+       // equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
+});
\ No newline at end of file