dimensions.js (2658B)
1 module("dimensions"); 2 3 test("innerWidth()", function() { 4 expect(3); 5 6 var $div = $("#nothiddendiv"); 7 // set styles 8 $div.css({ 9 margin: 10, 10 border: "2px solid #fff", 11 width: 30 12 }); 13 14 equals($div.innerWidth(), 30, "Test with margin and border"); 15 $div.css("padding", "20px"); 16 equals($div.innerWidth(), 70, "Test with margin, border and padding"); 17 $div.hide(); 18 equals($div.innerWidth(), 70, "Test hidden div"); 19 20 // reset styles 21 $div.css({ display: "", border: "", padding: "", width: "", height: "" }); 22 }); 23 24 test("innerHeight()", function() { 25 expect(3); 26 27 var $div = $("#nothiddendiv"); 28 // set styles 29 $div.css({ 30 margin: 10, 31 border: "2px solid #fff", 32 height: 30 33 }); 34 35 equals($div.innerHeight(), 30, "Test with margin and border"); 36 $div.css("padding", "20px"); 37 equals($div.innerHeight(), 70, "Test with margin, border and padding"); 38 $div.hide(); 39 equals($div.innerHeight(), 70, "Test hidden div"); 40 41 // reset styles 42 $div.css({ display: "", border: "", padding: "", width: "", height: "" }); 43 }); 44 45 test("outerWidth()", function() { 46 expect(6); 47 48 var $div = $("#nothiddendiv"); 49 $div.css("width", 30); 50 51 equals($div.outerWidth(), 30, "Test with only width set"); 52 $div.css("padding", "20px"); 53 equals($div.outerWidth(), 70, "Test with padding"); 54 $div.css("border", "2px solid #fff"); 55 equals($div.outerWidth(), 74, "Test with padding and border"); 56 $div.css("margin", "10px"); 57 equals($div.outerWidth(), 74, "Test with padding, border and margin without margin option"); 58 $div.css("position", "absolute"); 59 equals($div.outerWidth(true), 94, "Test with padding, border and margin with margin option"); 60 $div.hide(); 61 equals($div.outerWidth(true), 94, "Test hidden div with padding, border and margin with margin option"); 62 63 // reset styles 64 $div.css({ position: "", display: "", border: "", padding: "", width: "", height: "" }); 65 }); 66 67 test("outerHeight()", function() { 68 expect(6); 69 70 var $div = $("#nothiddendiv"); 71 $div.css("height", 30); 72 73 equals($div.outerHeight(), 30, "Test with only width set"); 74 $div.css("padding", "20px"); 75 equals($div.outerHeight(), 70, "Test with padding"); 76 $div.css("border", "2px solid #fff"); 77 equals($div.outerHeight(), 74, "Test with padding and border"); 78 $div.css("margin", "10px"); 79 equals($div.outerHeight(), 74, "Test with padding, border and margin without margin option"); 80 equals($div.outerHeight(true), 94, "Test with padding, border and margin with margin option"); 81 $div.hide(); 82 equals($div.outerHeight(true), 94, "Test hidden div with padding, border and margin with margin option"); 83 84 // reset styles 85 $div.css({ display: "", border: "", padding: "", width: "", height: "" }); 86 });