Skip to content

Commit 48be675

Browse files
committed
Tests: Fix CSS relative adjustment test for round-down browsers
Ref 9b03f6d
1 parent 7632b74 commit 48be675

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
@@ -208,13 +208,25 @@ test( "css() non-px relative values (gh-1711)", 17, function() {
208208
units = {},
209209
$child = jQuery( "#nothiddendivchild" ),
210210
add = function( prop, val, unit ) {
211-
var str = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit;
212-
$child.css( prop, str );
213-
equal(
214-
Math.round( parseFloat( $child.css( prop ) ) ),
215-
Math.round( cssCurrent += val * units[ prop ][ unit ] ),
216-
prop + ": '" + str + "'"
217-
);
211+
var difference,
212+
adjustment = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit,
213+
message = prop + ": " + adjustment,
214+
cssOld = cssCurrent,
215+
expected = cssOld + val * units[ prop ][ unit ];
216+
217+
// Apply change
218+
$child.css( prop, adjustment );
219+
cssCurrent = parseFloat( $child.css( prop ) );
220+
221+
// Require a difference of less than one pixel
222+
difference = Math.abs( cssCurrent - expected );
223+
if ( difference < 1 ) {
224+
ok( true, message );
225+
226+
// ...or fail with actual and expected values
227+
} else {
228+
ok( false, message + " (actual " + cssCurrent + ", expected " + expected + ")" );
229+
}
218230
},
219231
getUnits = function( prop ) {
220232
units[ prop ] = {

0 commit comments

Comments
 (0)