Fixed typo in logic, also disabled function setters in this case to allow the functi...
[jquery.git] / test / unit / core.js
index 3020543..85b421d 100644 (file)
@@ -12,7 +12,7 @@ test("Basic requirements", function() {
 });
 
 test("jQuery()", function() {
-       expect(22);
+       expect(23);
 
        // Basic constructor's behavior
 
@@ -63,9 +63,12 @@ test("jQuery()", function() {
 
        equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" );
 
+       var exec = false;
+
        var elem = jQuery("<div/>", {
                width: 10,
                css: { paddingLeft:1, paddingRight:1 },
+               click: function(){ ok(exec, "Click executed."); },
                text: "test",
                "class": "test2",
                id: "test3"
@@ -78,6 +81,9 @@ test("jQuery()", function() {
        equals( elem[0].firstChild.nodeValue, "test", 'jQuery quick setter text');
        equals( elem[0].className, "test2", 'jQuery() quick setter class');
        equals( elem[0].id, "test3", 'jQuery() quick setter id');
+
+       exec = true;
+       elem.click();
 });
 
 test("selector state", function() {
@@ -643,7 +649,7 @@ test("jQuery.merge()", function() {
 });
 
 test("jQuery.extend(Object, Object)", function() {
-       expect(25);
+       expect(27);
 
        var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
                options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
@@ -653,7 +659,9 @@ test("jQuery.extend(Object, Object)", function() {
                deep1copy = { foo: { bar: true } },
                deep2 = { foo: { baz: true }, foo2: document },
                deep2copy = { foo: { baz: true }, foo2: document },
-               deepmerged = { foo: { bar: true, baz: true }, foo2: document };
+               deepmerged = { foo: { bar: true, baz: true }, foo2: document },
+               arr = [1, 2, 3],
+               nestedarray = { arr: arr };
 
        jQuery.extend(settings, options);
        same( settings, merged, "Check if extended: settings must be extended" );
@@ -668,6 +676,9 @@ test("jQuery.extend(Object, Object)", function() {
        same( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
        equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
 
+       ok( jQuery.extend(true, [], arr) !== arr, "Deep extend of array must clone array" );
+       ok( jQuery.extend(true, {}, nestedarray).arr !== arr, "Deep extend of object must clone child array" );
+
        var empty = {};
        var optionsWithLength = { foo: { length: -1 } };
        jQuery.extend(true, empty, optionsWithLength);
@@ -825,3 +836,22 @@ test("jQuery.isEmptyObject", function(){
        // What about this ?
        // equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
 });
+
+test("jQuery.proxy", function(){
+       expect(4);
+
+       var test = function(){ equals( this, thisObject, "Make sure that scope is set properly." ); };
+       var thisObject = { foo: "bar", method: test };
+
+       // Make sure normal works
+       test.call( thisObject );
+
+       // Basic scoping
+       jQuery.proxy( test, thisObject )();
+
+       // 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" )();
+});