Probably not the optimal solution, but tests pass.
[jquery.git] / test / unit / css.js
index a917173..649db59 100644 (file)
@@ -81,6 +81,72 @@ test("css(String, Object)", function() {
        equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
 });
 
+test("css(String, Function)", function() {
+       try { 
+               expect(3);
+               
+               var sizes = ["10px", "20px", "30px"];
+       
+               jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
+                                        "<div class='cssFunction'></div>" + 
+                                        "<div class='cssFunction'></div></div>")
+                       .appendTo("body");
+       
+               var index = 0;
+       
+               jQuery("#cssFunctionTest div").css("font-size", function() {
+                       var size = sizes[index];
+                       index++;
+                       return size;
+               });
+               
+               index = 0;
+               
+               jQuery("#cssFunctionTest div").each(function() {
+                       var computedSize = jQuery(this).css("font-size")
+                       var expectedSize = sizes[index]
+                       equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
+                       index++;
+               });
+               
+       } finally {
+               jQuery("#cssFunctionTest").remove();
+       }
+});
+
+test("css(Object) where values are Functions", function() {
+       try { 
+               expect(3);
+               
+               var sizes = ["10px", "20px", "30px"];
+       
+               jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
+                                        "<div class='cssFunction'></div>" + 
+                                        "<div class='cssFunction'></div></div>")
+                       .appendTo("body");
+       
+               var index = 0;
+       
+               jQuery("#cssFunctionTest div").css({fontSize: function() {
+                       var size = sizes[index];
+                       index++;
+                       return size;
+               }});
+               
+               index = 0;
+               
+               jQuery("#cssFunctionTest div").each(function() {
+                       var computedSize = jQuery(this).css("font-size")
+                       var expectedSize = sizes[index]
+                       equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
+                       index++;
+               });
+               
+       } finally {
+               jQuery("#cssFunctionTest").remove();
+       }
+});
+
 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
        expect(4);