]> source.dussan.org Git - jquery.git/commitdiff
Tests: Fix CSS relative adjustment test for round-down browsers
authorRichard Gibson <richard.gibson@gmail.com>
Tue, 17 Mar 2015 03:05:36 +0000 (23:05 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Tue, 17 Mar 2015 03:07:39 +0000 (23:07 -0400)
Ref 9b03f6df88a8d9dbda3f7893cdd84e3a3c70da17
Ref 6fb2cefc602cf8bd8b85373f480e978bb8978e37

(cherry picked from commit 48be675200e817f40fa8ec25da1be2ab0839d28d)

test/unit/css.js

index 9dcc9101d563ffd2a0f96fd2226d503ba7947347..1fdbfd78ada326529700594a6ae393217e0f470f 100644 (file)
@@ -222,13 +222,25 @@ test( "css() non-px relative values (gh-1711)", 17, function() {
                units = {},
                $child = jQuery( "#nothiddendivchild" ),
                add = function( prop, val, unit ) {
-                       var str = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit;
-                       $child.css( prop, str );
-                       equal(
-                               Math.round( parseFloat( $child.css( prop ) ) ),
-                               Math.round( cssCurrent += val * units[ prop ][ unit ] ),
-                               prop + ": '" + str + "'"
-                       );
+                       var difference,
+                               adjustment = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit,
+                               message = prop + ": " + adjustment,
+                               cssOld = cssCurrent,
+                               expected = cssOld + val * units[ prop ][ unit ];
+
+                       // Apply change
+                       $child.css( prop, adjustment );
+                       cssCurrent = parseFloat( $child.css( prop ) );
+
+                       // Require a difference of less than one pixel
+                       difference = Math.abs( cssCurrent - expected );
+                       if ( difference < 1 ) {
+                               ok( true, message );
+
+                       // ...or fail with actual and expected values
+                       } else {
+                               ok( false, message + " (actual " + cssCurrent + ", expected " + expected + ")" );
+                       }
                },
                getUnits = function( prop ) {
                        units[ prop ] = {