Skip to content

Commit 998d7f5

Browse files
committed
Tests: Make dialog & draggable unit tests be less strict
Newest jQuery returns fractional results in some cases, making comparisons fail when there's a tiny difference. Tests were modified to be less strict.
1 parent c1bc711 commit 998d7f5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tests/unit/dialog/options.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,25 @@ QUnit.test( "height", function( assert ) {
251251
assert.expect( 4 );
252252

253253
var element = $( "<div></div>" ).dialog();
254-
assert.equal( element.dialog( "widget" ).outerHeight(), 150, "default height" );
254+
assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 150) < 0.25,
255+
"default height within 0.25 from expected" );
255256
element.remove();
256257

257258
element = $( "<div></div>" ).dialog( { height: 237 } );
258-
assert.equal( element.dialog( "widget" ).outerHeight(), 237, "explicit height" );
259+
assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 237) < 0.25,
260+
"explicit height within 0.25 from expected" );
259261
element.remove();
260262

261263
element = $( "<div></div>" ).dialog();
262264
element.dialog( "option", "height", 238 );
263-
assert.equal( element.dialog( "widget" ).outerHeight(), 238, "explicit height set after init" );
265+
assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 238) < 0.25,
266+
"explicit height set after init within 0.25 from expected" );
264267
element.remove();
265268

266269
element = $( "<div></div>" ).css( "padding", "20px" )
267270
.dialog( { height: 240 } );
268-
assert.equal( element.dialog( "widget" ).outerHeight(), 240, "explicit height with padding" );
271+
assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 240) < 0.25,
272+
"explicit height with padding within 0.25 from expected" );
269273
element.remove();
270274
} );
271275

tests/unit/draggable/options.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ QUnit.test( "cancelement, default, switching after initialization", function( as
252252
} );
253253

254254
QUnit.test( "connectToSortable, dragging out of a sortable", function( assert ) {
255-
assert.expect( 4 );
255+
assert.expect( 5 );
256256

257-
var sortItem, dragHelper,
257+
var sortItem, dragHelper, result,
258258
element = $( "#draggableSortable" ).draggable( {
259259
scroll: false,
260260
connectToSortable: "#sortable"
@@ -280,7 +280,12 @@ QUnit.test( "connectToSortable, dragging out of a sortable", function( assert )
280280

281281
// http://bugs.jqueryui.com/ticket/8809
282282
// Position issue when connected to sortable
283-
assert.deepEqual( ui.helper.offset(), offsetExpected, "draggable offset is correct" );
283+
result = ui.helper.offset();
284+
285+
// Support: Chrome <=45 - 73+
286+
// In recent Chrome these values differ a little.
287+
assert.ok( Math.abs( result.top - offsetExpected.top ) < 0.25, "draggable offset is within 0.25 of expected" );
288+
assert.ok( Math.abs( result.left - offsetExpected.left ) < 0.25, "draggable offset is within 0.25 of expected" );
284289

285290
// Http://bugs.jqueryui.com/ticket/7734
286291
// HTML IDs are removed when dragging to a Sortable

0 commit comments

Comments
 (0)