jquery-ui/tests/unit/effects/scale.js
Michał Gołębiowski-Owczarek e7a10c70ae
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
2020-05-16 09:16:24 +02:00

76 lines
2.0 KiB
JavaScript

define( [
"qunit",
"jquery",
"lib/helper",
"ui/effects/effect-scale"
], function( QUnit, $, helper ) {
QUnit.module( "effect.scale: Scale", { afterEach: helper.moduleAfterEach } );
function run( position, v, h, vo, ho ) {
var desc = "End Position Correct: " + position + " (" + v + "," + h + ") - origin: (" + vo + "," + ho + ")";
QUnit.test( desc, function( assert ) {
var ready = assert.async();
assert.expect( 2 );
function complete() {
assert.close( parseInt( test.css( h ), 10 ), target[ h ], 1, "Horizontal Position Correct " + desc );
assert.close( parseInt( test.css( v ), 10 ), target[ v ], 1, "Vertical Position Correct " + desc );
ready();
}
var test = $( ".testScale" ),
css = {
position: position
},
effect = {
effect: "scale",
mode: "effect",
percent: 200,
origin: [ vo, ho ],
complete: complete,
duration: 1
},
target = {},
relative = position === "relative";
css[ h ] = 33;
css[ v ] = 33;
target[ h ] = h === ho ? css[ h ] : ho === "center" ? css[ h ] - 35 : css[ h ] - 70;
target[ v ] = v === vo ? css[ v ] : vo === "middle" ? css[ v ] - 35 : css[ v ] - 70;
if ( relative && h === "right" ) {
target[ h ] += 70;
}
if ( relative && v === "bottom" ) {
target[ v ] += 70;
}
test.css( css );
test.effect( effect );
} );
}
function suite( position ) {
run( position, "top", "left", "top", "left" );
run( position, "top", "left", "middle", "center" );
run( position, "top", "left", "bottom", "right" );
/* Firefox is currently not capable of supporting detection of bottom and right....
run( position, "bottom", "right", "top", "left" );
run( position, "bottom", "right", "middle", "center" );
run( position, "bottom", "right", "bottom", "right" );
*/
}
$( function() {
suite( "absolute" );
suite( "relative" );
var fixedElem = $( "<div>" )
.css( {
position: "fixed",
top: 10
} )
.appendTo( "body" );
if ( fixedElem.offset().top === 10 ) {
suite( "fixed" );
}
} );
} );