Skip to content

Commit 4a8000b

Browse files
committed
Tests: Fix CSS relative adjustment test for round-down browsers
Ref 9b03f6d Ref 6fb2cef (cherry picked from commit 48be675)
1 parent a403655 commit 4a8000b

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

test/unit/css.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,25 @@ test( "css() non-px relative values (gh-1711)", 17, function() {
222222
units = {},
223223
$child = jQuery( "#nothiddendivchild" ),
224224
add = function( prop, val, unit ) {
225-
var str = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit;
226-
$child.css( prop, str );
227-
equal(
228-
Math.round( parseFloat( $child.css( prop ) ) ),
229-
Math.round( cssCurrent += val * units[ prop ][ unit ] ),
230-
prop + ": '" + str + "'"
231-
);
225+
var difference,
226+
adjustment = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit,
227+
message = prop + ": " + adjustment,
228+
cssOld = cssCurrent,
229+
expected = cssOld + val * units[ prop ][ unit ];
230+
231+
// Apply change
232+
$child.css( prop, adjustment );
233+
cssCurrent = parseFloat( $child.css( prop ) );
234+
235+
// Require a difference of less than one pixel
236+
difference = Math.abs( cssCurrent - expected );
237+
if ( difference < 1 ) {
238+
ok( true, message );
239+
240+
// ...or fail with actual and expected values
241+
} else {
242+
ok( false, message + " (actual " + cssCurrent + ", expected " + expected + ")" );
243+
}
232244
},
233245
getUnits = function( prop ) {
234246
units[ prop ] = {

0 commit comments

Comments
 (0)