diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-12-08 22:23:08 +0100 |
---|---|---|
committer | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-12-08 22:23:08 +0100 |
commit | 98b539171b6e805fa79346a5e9896865e5213b9c (patch) | |
tree | f6c296195f081c538f90c96f43f28012670960a5 /tests/unit | |
parent | 74f8a0ac952f6f45f773312292baef1c26d81300 (diff) | |
download | jquery-ui-98b539171b6e805fa79346a5e9896865e5213b9c.tar.gz jquery-ui-98b539171b6e805fa79346a5e9896865e5213b9c.zip |
All: Migrate away from deprecated/removed Core APIs
Summary of the changes:
* Build: Add jQuery 3.2.0-3.4.1 to versions UI can be tested against
* Build: Load jQuery & Migrate via HTTPS
* Build: Add package-lock.json to .gitignore
* Build: Update jQuery Migrate from 3.0.0 to 3.1.0
* Build: Allow to run tests against jQuery 3.x-git
* Build: Fix formatting according to JSCS rules
* Build: Disable JSCS for the inlined jQuery Color
* All: Switch from $.isArray to Array.isArray (jQuery.isArray will be
removed in jQuery 4.0)
* All: Switch from `$.isFunction( x )` to `typeof x === "function"`
(jQuery.isFunction will be removed in jQuery 4.0)
* All: Inline jQuery.isWindow as it'll be removed in jQuery 4.0
* Effects: Fix a timing issue in a variable declaration. Previously,
a jQuery object was created, chained & assigned to a variable that
was then accessed in a callback used inside of this chained
definition. Due to a timing difference in when the callback fired for
the first time in latest jQuery master, it was being called before
the variable was defined.
* Tests: Make dialog & draggable unit tests less strict (newest jQuery
returns fractional results in some cases, making comparisons fail when
there's a tiny difference)
* All: Migrate from $.trim to bare String.prototype.trim (jQuery.trim
will be deprecated in jQuery 3.5)
Closes gh-1901
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/checkboxradio/options.js | 10 | ||||
-rw-r--r-- | tests/unit/core/core.js | 5 | ||||
-rw-r--r-- | tests/unit/dialog/deprecated.js | 2 | ||||
-rw-r--r-- | tests/unit/dialog/options.js | 22 | ||||
-rw-r--r-- | tests/unit/draggable/options.js | 11 | ||||
-rw-r--r-- | tests/unit/effects/core.js | 2 | ||||
-rw-r--r-- | tests/unit/menu/helper.js | 2 | ||||
-rw-r--r-- | tests/unit/selectmenu/core.js | 14 | ||||
-rw-r--r-- | tests/unit/selectmenu/methods.js | 8 | ||||
-rw-r--r-- | tests/unit/subsuite.js | 5 | ||||
-rw-r--r-- | tests/unit/widget/core.js | 10 |
11 files changed, 52 insertions, 39 deletions
diff --git a/tests/unit/checkboxradio/options.js b/tests/unit/checkboxradio/options.js index 7fe6a0710..c0fc333c3 100644 --- a/tests/unit/checkboxradio/options.js +++ b/tests/unit/checkboxradio/options.js @@ -137,7 +137,7 @@ QUnit.test( "label - default", function( assert ) { widget = checkbox.checkboxradio( "widget" ); assert.strictEqual( checkbox.checkboxradio( "option", "label" ), "checkbox label", "When no value passed on create text from dom is used for option" ); - assert.strictEqual( $.trim( widget.text() ), + assert.strictEqual( String.prototype.trim.call( widget.text() ), "checkbox label", "When no value passed on create text from dom is used in dom" ); } ); @@ -152,7 +152,7 @@ QUnit.test( "label - explicit value", function( assert ) { assert.strictEqual( checkbox.checkboxradio( "option", "label" ), "foo", "When value is passed on create value is used for option" ); - assert.strictEqual( $.trim( widget.text() ), + assert.strictEqual( String.prototype.trim.call( widget.text() ), "foo", "When value is passed on create value is used in dom" ); assert.strictEqual( icon.length, 1, "Icon is preserved when label is set on init when wrapped in label" ); @@ -177,7 +177,7 @@ QUnit.test( "label - explicit null value", function( assert ) { widget = checkbox.checkboxradio( "widget" ); assert.strictEqual( checkbox.checkboxradio( "option", "label" ), "checkbox label", "When null is passed on create text from dom is used for option" ); - assert.strictEqual( $.trim( widget.text() ), + assert.strictEqual( String.prototype.trim.call( widget.text() ), "checkbox label", "When null is passed on create text from dom is used in dom" ); } ); @@ -193,13 +193,13 @@ QUnit.test( "label", function( assert ) { checkbox.checkboxradio( "option", "label", "bar" ); assert.strictEqual( checkbox.checkboxradio( "option", "label" ), "bar", "When value is passed value is used for option" ); - assert.strictEqual( $.trim( widget.text() ), + assert.strictEqual( String.prototype.trim.call( widget.text() ), "bar", "When value is passed value is used in dom" ); checkbox.checkboxradio( "option", "label", null ); assert.strictEqual( checkbox.checkboxradio( "option", "label" ), "bar", "When null is passed text from dom is used for option" ); - assert.strictEqual( $.trim( widget.text() ), + assert.strictEqual( String.prototype.trim.call( widget.text() ), "bar", "When null is passed text from dom is used in dom" ); } ); diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index b5b6b3b81..acfc291ff 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -152,8 +152,9 @@ QUnit.test( "Labels", function( assert ) { var found = labels.map( function() { // Support: Core 1.9 Only - // We use $.trim() because core 1.9.x silently fails when white space is present - return $.trim( $( this ).text() ); + // We use String.prototype.trim because core 1.9.x silently fails + // when white space is present + return String.prototype.trim.call( $( this ).text() ); } ).get(); assert.deepEqual( found, expected, diff --git a/tests/unit/dialog/deprecated.js b/tests/unit/dialog/deprecated.js index 973a90893..eac0e123d 100644 --- a/tests/unit/dialog/deprecated.js +++ b/tests/unit/dialog/deprecated.js @@ -50,7 +50,7 @@ QUnit.test( "buttons - deprecated options", function( assert ) { buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" ); assert.equal( buttons.length, 1, "correct number of buttons" ); assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" ); - assert.equal( $.trim( buttons.text() ), "a button", "correct label" ); + assert.equal( String.prototype.trim.call( buttons.text() ), "a button", "correct label" ); assert.hasClasses( buttons, "additional-class" ); assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" ); assert.equal( buttons.button( "option", "showLabel" ), false ); diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 1be2888e3..4d8e4f717 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -166,7 +166,7 @@ QUnit.test( "buttons - advanced", function( assert ) { buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" ); assert.equal( buttons.length, 1, "correct number of buttons" ); assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" ); - assert.equal( $.trim( buttons.text() ), "a button", "correct label" ); + assert.equal( String.prototype.trim.call( buttons.text() ), "a button", "correct label" ); assert.hasClasses( buttons, "additional-class" ); assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" ); assert.equal( buttons.button( "option", "showLabel" ), false ); @@ -210,22 +210,22 @@ QUnit.test( "closeText", function( assert ) { assert.expect( 4 ); var element = $( "<div></div>" ).dialog(); - assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "Close", + assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "Close", "default close text" ); element.remove(); element = $( "<div></div>" ).dialog( { closeText: "foo" } ); - assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "foo", + assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "foo", "closeText on init" ); element.remove(); element = $( "<div></div>" ).dialog().dialog( "option", "closeText", "bar" ); - assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "bar", + assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "bar", "closeText via option method" ); element.remove(); element = $( "<div></div>" ).dialog( { closeText: "<span>foo</span>" } ); - assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "<span>foo</span>", + assert.equal( String.prototype.trim.call( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "<span>foo</span>", "closeText is escaped" ); element.remove(); } ); @@ -251,21 +251,25 @@ QUnit.test( "height", function( assert ) { assert.expect( 4 ); var element = $( "<div></div>" ).dialog(); - assert.equal( element.dialog( "widget" ).outerHeight(), 150, "default height" ); + assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 150 ) < 0.25, + "default height within 0.25 from expected" ); element.remove(); element = $( "<div></div>" ).dialog( { height: 237 } ); - assert.equal( element.dialog( "widget" ).outerHeight(), 237, "explicit height" ); + assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 237 ) < 0.25, + "explicit height within 0.25 from expected" ); element.remove(); element = $( "<div></div>" ).dialog(); element.dialog( "option", "height", 238 ); - assert.equal( element.dialog( "widget" ).outerHeight(), 238, "explicit height set after init" ); + assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 238 ) < 0.25, + "explicit height set after init within 0.25 from expected" ); element.remove(); element = $( "<div></div>" ).css( "padding", "20px" ) .dialog( { height: 240 } ); - assert.equal( element.dialog( "widget" ).outerHeight(), 240, "explicit height with padding" ); + assert.ok( Math.abs( element.dialog( "widget" ).outerHeight() - 240 ) < 0.25, + "explicit height with padding within 0.25 from expected" ); element.remove(); } ); diff --git a/tests/unit/draggable/options.js b/tests/unit/draggable/options.js index 656df621f..ff72f9d02 100644 --- a/tests/unit/draggable/options.js +++ b/tests/unit/draggable/options.js @@ -252,9 +252,9 @@ QUnit.test( "cancelement, default, switching after initialization", function( as } ); QUnit.test( "connectToSortable, dragging out of a sortable", function( assert ) { - assert.expect( 4 ); + assert.expect( 5 ); - var sortItem, dragHelper, + var sortItem, dragHelper, result, element = $( "#draggableSortable" ).draggable( { scroll: false, connectToSortable: "#sortable" @@ -280,7 +280,12 @@ QUnit.test( "connectToSortable, dragging out of a sortable", function( assert ) // http://bugs.jqueryui.com/ticket/8809 // Position issue when connected to sortable - assert.deepEqual( ui.helper.offset(), offsetExpected, "draggable offset is correct" ); + result = ui.helper.offset(); + + // Support: Chrome <=45 - 73+ + // In recent Chrome these values differ a little. + assert.ok( Math.abs( result.top - offsetExpected.top ) < 0.25, "draggable offset is within 0.25 of expected" ); + assert.ok( Math.abs( result.left - offsetExpected.left ) < 0.25, "draggable offset is within 0.25 of expected" ); // Http://bugs.jqueryui.com/ticket/7734 // HTML IDs are removed when dragging to a Sortable diff --git a/tests/unit/effects/core.js b/tests/unit/effects/core.js index 9863cd8ca..d095bfbd5 100644 --- a/tests/unit/effects/core.js +++ b/tests/unit/effects/core.js @@ -210,7 +210,7 @@ QUnit.test( "animateClass clears style properties when stopped", function( asser .stop( true, true ) .promise() .then( function() { - assert.equal( orig, $.trim( style.cssText ), "cssText is the same after stopping animation midway" ); + assert.equal( orig, String.prototype.trim.call( style.cssText ), "cssText is the same after stopping animation midway" ); ready(); } ); } ); diff --git a/tests/unit/menu/helper.js b/tests/unit/menu/helper.js index 445663985..1e4a21485 100644 --- a/tests/unit/menu/helper.js +++ b/tests/unit/menu/helper.js @@ -14,7 +14,7 @@ return $.extend( helper, { if ( message === undefined ) { message = lastItem; } - log.push( $.trim( message ) ); + log.push( String.prototype.trim.call( message ) ); }, logOutput: function() { diff --git a/tests/unit/selectmenu/core.js b/tests/unit/selectmenu/core.js index 708452312..b0f56f3b3 100644 --- a/tests/unit/selectmenu/core.js +++ b/tests/unit/selectmenu/core.js @@ -95,7 +95,7 @@ QUnit.test( "_renderButtonItem()", function( assert ) { element.selectmenu( "refresh" ); option = element.find( "option:selected" ); assert.equal( - $.trim( button.text() ), + String.prototype.trim.call( button.text() ), option.text() + element[ 0 ].selectedIndex, "refresh: button item text" ); @@ -104,7 +104,7 @@ QUnit.test( "_renderButtonItem()", function( assert ) { menu.find( "li" ).last().simulate( "mouseover" ).trigger( "click" ); option = element.find( "option" ).last(); assert.equal( - $.trim( button.text() ), + String.prototype.trim.call( button.text() ), option.text() + element[ 0 ].selectedIndex, "click: button item text" ); @@ -153,7 +153,7 @@ $.each( [ selected.val(), "original select state" ); - assert.equal( $.trim( button.text() ), selected.text(), "button text" ); + assert.equal( String.prototype.trim.call( button.text() ), selected.text(), "button text" ); ready(); } ); } ); @@ -189,7 +189,7 @@ $.each( [ selected.val(), "original select state" ); - assert.equal( $.trim( button.text() ), selected.text(), "button text" ); + assert.equal( String.prototype.trim.call( button.text() ), selected.text(), "button text" ); ready(); }, 1 ); } ); @@ -231,7 +231,7 @@ $.each( [ "button aria-activedescendant" ); assert.equal( element.find( "option:selected" ).val(), options.eq( 1 ).val(), "original select state" ); - assert.equal( $.trim( button.text() ), options.eq( 1 ).text(), "button text" ); + assert.equal( String.prototype.trim.call( button.text() ), options.eq( 1 ).text(), "button text" ); ready(); } ); } ); @@ -352,10 +352,10 @@ QUnit.test( "Selectmenu should reset when its parent form resets", function( ass element.val( "Slower" ); element.selectmenu( "refresh" ); - assert.equal( $.trim( widget.text() ), "Slower" ); + assert.equal( String.prototype.trim.call( widget.text() ), "Slower" ); form[ 0 ].reset(); setTimeout( function() { - assert.equal( $.trim( widget.text() ), initialValue ); + assert.equal( String.prototype.trim.call( widget.text() ), initialValue ); ready(); } ); } ); diff --git a/tests/unit/selectmenu/methods.js b/tests/unit/selectmenu/methods.js index c25d01af5..2722fed01 100644 --- a/tests/unit/selectmenu/methods.js +++ b/tests/unit/selectmenu/methods.js @@ -83,21 +83,21 @@ QUnit.test( "refresh - change selected option", function( assert ) { var element = $( "#speed" ).selectmenu(), button = element.selectmenu( "widget" ); - assert.equal( $.trim( button.text() ), "Medium", "button text after init" ); + assert.equal( String.prototype.trim.call( button.text() ), "Medium", "button text after init" ); button.simulate( "focus" ); setTimeout( function() { - assert.equal( $.trim( button.text() ), "Medium", "button text after focus" ); + assert.equal( String.prototype.trim.call( button.text() ), "Medium", "button text after focus" ); element[ 0 ].selectedIndex = 0; element.selectmenu( "refresh" ); - assert.equal( $.trim( button.text() ), "Slower", "button text after changing selected option" ); + assert.equal( String.prototype.trim.call( button.text() ), "Slower", "button text after changing selected option" ); element.find( "option" ).prop( "selected", false ); element.append( "<option selected value=\"selected_option\">Selected option</option>" ); element.selectmenu( "refresh" ); - assert.equal( $.trim( button.text() ), "Selected option", "button text after adding selected option" ); + assert.equal( String.prototype.trim.call( button.text() ), "Selected option", "button text after adding selected option" ); ready(); } ); diff --git a/tests/unit/subsuite.js b/tests/unit/subsuite.js index e8a2c72fa..3ffb04366 100644 --- a/tests/unit/subsuite.js +++ b/tests/unit/subsuite.js @@ -12,7 +12,10 @@ var versions = [ "2.2.0", "2.2.1", "2.2.2", "2.2.3", "2.2.4", "3.0.0", "3.1.0", "3.1.1", - "git", "custom" + "3.2.0", "3.2.1", + "3.3.0", "3.3.1", + "3.4.0", "3.4.1", + "3.x-git", "git", "custom" ], additionalTests = { diff --git a/tests/unit/widget/core.js b/tests/unit/widget/core.js index d6bb3efb8..283b55416 100644 --- a/tests/unit/widget/core.js +++ b/tests/unit/widget/core.js @@ -29,7 +29,7 @@ QUnit.test( "widget creation", function( assert ) { }; $.widget( "ui.testWidget", myPrototype ); - assert.ok( $.isFunction( $.ui.testWidget ), "constructor was created" ); + assert.ok( typeof $.ui.testWidget === "function", "constructor was created" ); assert.equal( typeof $.ui.testWidget.prototype, "object", "prototype was created" ); method = "_create"; $.ui.testWidget.prototype._create(); @@ -947,7 +947,7 @@ QUnit.test( "_on() with delegate", function( assert ) { this.element = { on: function( event, handler ) { assert.equal( event, "click.testWidget" + uuid ); - assert.ok( $.isFunction( handler ) ); + assert.ok( typeof handler === "function" ); }, trigger: $.noop }; @@ -956,7 +956,7 @@ QUnit.test( "_on() with delegate", function( assert ) { on: function( event, selector, handler ) { assert.equal( selector, "a" ); assert.equal( event, "click.testWidget" + uuid ); - assert.ok( $.isFunction( handler ) ); + assert.ok( typeof handler === "function" ); } }; }; @@ -969,7 +969,7 @@ QUnit.test( "_on() with delegate", function( assert ) { on: function( event, selector, handler ) { assert.equal( selector, "form fieldset > input" ); assert.equal( event, "change.testWidget" + uuid ); - assert.ok( $.isFunction( handler ) ); + assert.ok( typeof handler === "function" ); } }; }; @@ -1608,7 +1608,7 @@ QUnit.test( "$.widget.bridge()", function( assert ) { $.widget.bridge( "testWidget", TestWidget ); - assert.ok( $.isFunction( $.fn.testWidget ), "jQuery plugin was created" ); + assert.ok( typeof $.fn.testWidget === "function", "jQuery plugin was created" ); assert.strictEqual( elem.testWidget( { foo: "bar" } ), elem, "plugin returns original jQuery object" ); instance = elem.data( "testWidget" ); |