From e7a10c70ae75c741992afdda60a433be205fd85e Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Sat, 16 May 2020 09:16:24 +0200 Subject: Tests: Ensure no timers are running at the end of each test (#1920) This helps fix issues that make tooltip tests sometimes fail when run against jQuery 3.2 or newer due to timing differences. Details: * Add the `moduleAfterEach` function ensuring no timers are running. * Attach this function via `common.testWidget`. * Attach this function to most test suites. * Add a tooltip test helper cleaning up leftover timers. * Rename legacy `setup`/`teardown` hooks to `beforeEach`/`afterEach`. Closes gh-1920 --- tests/unit/draggable/core.js | 5 +++-- tests/unit/draggable/events.js | 4 +++- tests/unit/draggable/methods.js | 4 +++- tests/unit/draggable/options.js | 8 ++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) (limited to 'tests/unit/draggable') diff --git a/tests/unit/draggable/core.js b/tests/unit/draggable/core.js index 1dd6f572a..b5dec8104 100644 --- a/tests/unit/draggable/core.js +++ b/tests/unit/draggable/core.js @@ -1,13 +1,14 @@ define( [ "qunit", "jquery", + "lib/helper", "./helper", "ui/widgets/draggable", "ui/widgets/droppable", "ui/widgets/resizable" -], function( QUnit, $, testHelper ) { +], function( QUnit, $, helper, testHelper ) { -QUnit.module( "draggable: core" ); +QUnit.module( "draggable: core", { afterEach: helper.moduleAfterEach } ); QUnit.test( "element types", function( assert ) { var typeNames = ( diff --git a/tests/unit/draggable/events.js b/tests/unit/draggable/events.js index f8c4a6551..c25754923 100644 --- a/tests/unit/draggable/events.js +++ b/tests/unit/draggable/events.js @@ -1,8 +1,9 @@ define( [ "qunit", "jquery", + "lib/helper", "ui/widgets/draggable" -], function( QUnit, $ ) { +], function( QUnit, $, helper ) { var element; @@ -12,6 +13,7 @@ QUnit.module( "draggable: events", { }, afterEach: function() { element.draggable( "destroy" ); + return helper.moduleAfterEach.apply( this, arguments ); } } ); diff --git a/tests/unit/draggable/methods.js b/tests/unit/draggable/methods.js index 8e95dac30..19c7424a0 100644 --- a/tests/unit/draggable/methods.js +++ b/tests/unit/draggable/methods.js @@ -1,9 +1,10 @@ define( [ "qunit", "jquery", + "lib/helper", "./helper", "ui/widgets/draggable" -], function( QUnit, $, testHelper ) { +], function( QUnit, $, helper, testHelper ) { var element; @@ -13,6 +14,7 @@ QUnit.module( "draggable: methods", { }, afterEach: function() { element.remove(); + return helper.moduleAfterEach.apply( this, arguments ); } } ); diff --git a/tests/unit/draggable/options.js b/tests/unit/draggable/options.js index ff72f9d02..32963b3f6 100644 --- a/tests/unit/draggable/options.js +++ b/tests/unit/draggable/options.js @@ -1,13 +1,14 @@ define( [ "qunit", "jquery", + "lib/helper", "./helper", "ui/widgets/draggable", "ui/widgets/droppable", "ui/widgets/sortable" -], function( QUnit, $, testHelper ) { +], function( QUnit, $, helper, testHelper ) { -QUnit.module( "draggable: options" ); +QUnit.module( "draggable: options", { afterEach: helper.moduleAfterEach } ); // TODO: This doesn't actually test whether append happened, possibly remove QUnit.test( "{ appendTo: 'parent' }, default, no clone", function( assert ) { @@ -301,6 +302,9 @@ QUnit.test( "connectToSortable, dragging out of a sortable", function( assert ) dx: dx, dy: dy } ); + + // Cleanup + element.stop( true ); } ); QUnit.test( "connectToSortable, dragging clone into sortable", function( assert ) { -- cgit v1.2.3