Page MenuHomeWickedGov Phorge

utils.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

utils.js

'use strict';
/**
* Waits until the specified selector to no longer match any elements in the QUnit test fixture.
*
* @param {string} selector The JQuery selector to check
* @return {Promise}
*/
function waitUntilElementDisappears( selector ) {
return waitUntilElementCount( selector, 0 );
}
/**
* Waits until the specified selector appears in the QUnit test fixture.
*
* @param {string} selector The JQuery selector to check
* @return {Promise}
*/
function waitUntilElementAppears( selector ) {
return waitUntilElementCount( selector, 1 );
}
/**
* Waits until the specified selector matches the specified count of elements in
* the QUnit test fixture.
*
* @param {string} selector The JQuery selector to check
* @param {number} count The number of elements to wait for
* @return {Promise}
*/
function waitUntilElementCount( selector, count ) {
// eslint-disable-next-line no-jquery/no-global-selector
const $qunitFixture = $( '#qunit-fixture' );
return new Promise( ( resolve ) => {
// Check every 10ms if the class matches any element in the QUnit test fixture.
// If the class is no longer present, then resolve is called.
// If this condition is not met ever, then QUnit will time the test out after 6s.
function runCheck() {
setTimeout( () => {
if ( $( selector, $qunitFixture ).length === count ) {
return resolve();
}
runCheck();
}, 10 );
}
runCheck();
} );
}
module.exports = {
waitUntilElementDisappears: waitUntilElementDisappears,
waitUntilElementAppears: waitUntilElementAppears,
waitUntilElementCount: waitUntilElementCount
};

File Metadata

Mime Type
text/plain
Expires
Tue, Aug 18, 23:57 (2 d, 16 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f6/92/bb9cad392346be7aa92d614257c8
Default Alt Text
utils.js (1 KB)

Event Timeline