mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 11:46:55 +00:00
c74d2e5313
Bug: T202739 Change-Id: Ie3f68977598f46f7e12b216f8381b2e9dc6d83ad
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
import wait from '../../src/wait';
|
|
|
|
QUnit.module( 'ext.popups/wait' );
|
|
|
|
QUnit.test( 'it should resolve after waiting', function ( assert ) {
|
|
const then = Date.now();
|
|
return wait( 150 ).then( () => {
|
|
assert.strictEqual(
|
|
( Date.now() - then ) > 150,
|
|
true,
|
|
'It waits for the given duration'
|
|
);
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'it should not catch after resolving', function ( assert ) {
|
|
return wait( 0 ).catch( () => {
|
|
assert.ok( false, 'It never calls a catchable after resolution' );
|
|
} ).then( () => {
|
|
assert.ok( true, 'It resolves' );
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'it should not resolve after aborting', function ( assert ) {
|
|
const deferred = wait( 0 );
|
|
|
|
const chain = deferred.then( () => {
|
|
assert.ok( false, 'It never calls a thenable after rejection' );
|
|
} ).catch( () => {
|
|
assert.ok( true, 'It calls the catchable' );
|
|
} );
|
|
|
|
deferred.abort();
|
|
|
|
return chain;
|
|
} );
|
|
|
|
QUnit.test( 'it should catch after resolving and aborting', function ( assert ) {
|
|
const deferred = wait( 0 );
|
|
|
|
const chain = deferred.catch( () => {
|
|
assert.ok( true, 'It calls the catchable' );
|
|
} );
|
|
|
|
deferred.then( () => {
|
|
assert.ok( true, 'It resolves' );
|
|
deferred.abort();
|
|
} );
|
|
|
|
return chain;
|
|
} );
|