From 48be675200e817f40fa8ec25da1be2ab0839d28d 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 --- 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 d6b14eea2..e97e16d6b 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -208,13 +208,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