From 4a8000b51a9854e21361e435e4c9b9cbd8ac458a Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 16 Mar 2015 23:05:36 -0400 Subject: [PATCH] Tests: Fix CSS relative adjustment test for round-down browsers Ref 9b03f6df88a8d9dbda3f7893cdd84e3a3c70da17 Ref 6fb2cefc602cf8bd8b85373f480e978bb8978e37 (cherry picked from commit 48be675200e817f40fa8ec25da1be2ab0839d28d) --- test/unit/css.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/test/unit/css.js b/test/unit/css.js index 9dcc9101d..1fdbfd78a 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -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 ] = { -- 2.39.5