Skip to content

Commit 9ea690a

Browse files
authored
Tests: Make some number comparisons less strict
Some of the APIs return fractional values in newer jQueries, making comparisons sometimes not being 100% accurate. Allow some delta. This is similar to what was already done in 98b5391 but a few cases affecting IE and/or Edge Legacy were missed. Closes gh-1947
1 parent 1029849 commit 9ea690a

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

tests/unit/draggable/options.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ QUnit.test( "zIndex, default, switching after initialization", function( assert
14691469
} );
14701470

14711471
QUnit.test( "iframeFix", function( assert ) {
1472-
assert.expect( 5 );
1472+
assert.expect( 6 );
14731473

14741474
var element = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable( { iframeFix: true } ),
14751475
element2 = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable( { iframeFix: ".iframe" } ),
@@ -1485,14 +1485,22 @@ QUnit.test( "iframeFix", function( assert ) {
14851485
} );
14861486

14871487
element.one( "drag", function() {
1488-
var div = $( this ).children().not( "iframe" );
1488+
var divOffset, iframeOffset,
1489+
div = $( this ).children().not( "iframe" );
14891490

14901491
// http://bugs.jqueryui.com/ticket/9671
14911492
// iframeFix doesn't handle iframes that move
14921493
assert.equal( div.length, 1, "blocking div added as sibling" );
14931494
assert.equal( div.outerWidth(), iframe.outerWidth(), "blocking div is wide enough" );
14941495
assert.equal( div.outerHeight(), iframe.outerHeight(), "blocking div is tall enough" );
1495-
assert.deepEqual( div.offset(), iframe.offset(), "blocking div is tall enough" );
1496+
1497+
divOffset = div.offset();
1498+
iframeOffset = iframe.offset();
1499+
1500+
// Support: Edge <79 only
1501+
// In Edge Legacy these values differ a little.
1502+
assert.ok( Math.abs( divOffset.top - iframeOffset.top ) < 0.25, "Check top within 0.25 of expected" );
1503+
assert.ok( Math.abs( divOffset.left - iframeOffset.left ) < 0.25, "Check left within 0.25 of expected" );
14961504
} );
14971505

14981506
element.simulate( "drag", {

tests/unit/sortable/options.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,24 @@ QUnit.test( "{ forcePlaceholderSize: true } table rows", function( assert ) {
286286
assert.expect( 2 );
287287

288288
// Table should have the placeholder's height set the same as the row we're dragging
289-
var element = $( "#sortable-table2 tbody" );
289+
var element = $( "#sortable-table2 tbody" ),
290+
jqMinor = $.fn.jquery.substring( 0, 4 );
290291

291292
element.sortable( {
292293
placeholder: "test",
293294
forcePlaceholderSize: true,
294295
start: function( event, ui ) {
295-
assert.equal( ui.placeholder.height(), ui.item.height(),
296-
"placeholder is same height as item" );
296+
297+
// Support: IE 11+, Edge <79 only
298+
// In IE & Edge Legacy these values may differ a little
299+
// when jQuery >=3.0 <3.2 is used.
300+
if ( jqMinor === "3.0." || jqMinor === "3.1." ) {
301+
assert.ok( Math.abs( ui.placeholder.height() - ui.item.height() ) < 0.25,
302+
"placeholder height is within 0.25 px of item's" );
303+
} else {
304+
assert.equal( ui.placeholder.height(), ui.item.height(),
305+
"placeholder is same height as item" );
306+
}
297307
}
298308
} );
299309

0 commit comments

Comments
 (0)