summaryrefslogtreecommitdiffstats
path: root/test/unit/css.js
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2015-07-02 01:20:18 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2015-07-07 18:09:45 +0200
commitb60b26e18477d21fa5ec9c6572e114fc5d441730 (patch)
treea37a0e2b53c1fb3986c59b1ee3d5bfee59ce294e /test/unit/css.js
parent84ccf2606c6b97d5875774bf774f9f2aae950ae7 (diff)
downloadjquery-b60b26e18477d21fa5ec9c6572e114fc5d441730.tar.gz
jquery-b60b26e18477d21fa5ec9c6572e114fc5d441730.zip
CSS: Make .css("width") & .css("height") return fractional values
Fixes gh-1724 Closes gh-2439
Diffstat (limited to 'test/unit/css.js')
-rw-r--r--test/unit/css.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/unit/css.js b/test/unit/css.js
index 22a3c7636..06de4acd9 100644
--- a/test/unit/css.js
+++ b/test/unit/css.js
@@ -846,6 +846,51 @@ testIframeWithCallback( "css('width') should work correctly before document read
}
);
+( function() {
+ var supportsFractionalGBCR,
+ qunitFixture = document.getElementById( "qunit-fixture" ),
+ div = document.createElement( "div" );
+ div.style.width = "3.3px";
+ qunitFixture.appendChild( div );
+ supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed(1) === "3.3";
+ qunitFixture.removeChild( div );
+
+ test( "css('width') and css('height') should return fractional values for nodes in the document", function() {
+ if ( !supportsFractionalGBCR ) {
+ expect( 1 );
+ ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
+ return;
+ }
+
+ expect( 2 );
+
+ var el = jQuery( "<div class='test-div'></div>" ).appendTo( "#qunit-fixture" );
+ jQuery( "<style>.test-div { width: 33.3px; height: 88.8px; }</style>" ).appendTo( "#qunit-fixture" );
+
+ equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
+ "css('width') should return fractional values" );
+ equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
+ "css('height') should return fractional values" );
+ } );
+
+ test( "css('width') and css('height') should return fractional values for disconnected nodes", function() {
+ if ( !supportsFractionalGBCR ) {
+ expect( 1 );
+ ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
+ return;
+ }
+
+ expect( 2 );
+
+ var el = jQuery( "<div style='width: 33.3px; height: 88.8px;'></div>" );
+
+ equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
+ "css('width') should return fractional values" );
+ equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
+ "css('height') should return fractional values" );
+ } );
+} )();
+
test("certain css values of 'normal' should be convertable to a number, see #8627", function() {
expect ( 3 );