Skip to content

Commit ebaf374

Browse files
committed
Add .css(Function) incoming value tests.
1 parent 0bb4fd0 commit ebaf374

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/unit/css.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,36 @@ test("css(String, Function)", function() {
149149
jQuery("#cssFunctionTest").remove();
150150
});
151151

152+
test("css(String, Function) with incoming value", function() {
153+
expect(3);
154+
155+
var sizes = ["10px", "20px", "30px"];
156+
157+
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
158+
"<div class='cssFunction'></div>" +
159+
"<div class='cssFunction'></div></div>")
160+
.appendTo("body");
161+
162+
var index = 0;
163+
164+
jQuery("#cssFunctionTest div").css("font-size", function() {
165+
var size = sizes[index];
166+
index++;
167+
return size;
168+
});
169+
170+
index = 0;
171+
172+
jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
173+
var expectedSize = sizes[index]
174+
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
175+
index++;
176+
return computedSize;
177+
});
178+
179+
jQuery("#cssFunctionTest").remove();
180+
});
181+
152182
test("css(Object) where values are Functions", function() {
153183
expect(3);
154184

@@ -179,6 +209,36 @@ test("css(Object) where values are Functions", function() {
179209
jQuery("#cssFunctionTest").remove();
180210
});
181211

212+
test("css(Object) where values are Functions with incoming values", function() {
213+
expect(3);
214+
215+
var sizes = ["10px", "20px", "30px"];
216+
217+
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
218+
"<div class='cssFunction'></div>" +
219+
"<div class='cssFunction'></div></div>")
220+
.appendTo("body");
221+
222+
var index = 0;
223+
224+
jQuery("#cssFunctionTest div").css({fontSize: function() {
225+
var size = sizes[index];
226+
index++;
227+
return size;
228+
}});
229+
230+
index = 0;
231+
232+
jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
233+
var expectedSize = sizes[index]
234+
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
235+
index++;
236+
return computedSize;
237+
}});
238+
239+
jQuery("#cssFunctionTest").remove();
240+
});
241+
182242
test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
183243
expect(4);
184244

0 commit comments

Comments
 (0)