tests: Use `async`/`await` instead of returning Promises
This has a few benefits: * It's more readable: It's easier for a user of the function to know that they should use `await` when calling the function. * Stack traces are more useful. * Some code (e.g., the async npm package) uses introspection to determine if a function is `async` vs. takes a callback.pull/4989/head
parent
b164a34e64
commit
3790c0e41c
|
@ -76,10 +76,10 @@ helper.defaultText =
|
||||||
* @param {string} message the chat message to be sent
|
* @param {string} message the chat message to be sent
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.sendChatMessage = (message) => {
|
helper.sendChatMessage = async (message) => {
|
||||||
const noOfChatMessages = helper.chatMessages.length;
|
const noOfChatMessages = helper.chatMessages.length;
|
||||||
helper.padChrome$('#chatinput').sendkeys(message);
|
helper.padChrome$('#chatinput').sendkeys(message);
|
||||||
return helper.waitForPromise(() => noOfChatMessages + 1 === helper.chatMessages.length);
|
await helper.waitForPromise(() => noOfChatMessages + 1 === helper.chatMessages.length);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,10 +87,10 @@ helper.sendChatMessage = (message) => {
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.showSettings = () => {
|
helper.showSettings = async () => {
|
||||||
if (helper.isSettingsShown()) return;
|
if (helper.isSettingsShown()) return;
|
||||||
helper.settingsButton().click();
|
helper.settingsButton().click();
|
||||||
return helper.waitForPromise(() => helper.isSettingsShown(), 2000);
|
await helper.waitForPromise(() => helper.isSettingsShown(), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,10 +99,10 @@ helper.showSettings = () => {
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
* @todo untested
|
* @todo untested
|
||||||
*/
|
*/
|
||||||
helper.hideSettings = () => {
|
helper.hideSettings = async () => {
|
||||||
if (!helper.isSettingsShown()) return;
|
if (!helper.isSettingsShown()) return;
|
||||||
helper.settingsButton().click();
|
helper.settingsButton().click();
|
||||||
return helper.waitForPromise(() => !helper.isSettingsShown(), 2000);
|
await helper.waitForPromise(() => !helper.isSettingsShown(), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,11 +111,11 @@ helper.hideSettings = () => {
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.enableStickyChatviaSettings = () => {
|
helper.enableStickyChatviaSettings = async () => {
|
||||||
const stickyChat = helper.padChrome$('#options-stickychat');
|
const stickyChat = helper.padChrome$('#options-stickychat');
|
||||||
if (!helper.isSettingsShown() || stickyChat.is(':checked')) return;
|
if (!helper.isSettingsShown() || stickyChat.is(':checked')) return;
|
||||||
stickyChat.click();
|
stickyChat.click();
|
||||||
return helper.waitForPromise(() => helper.isChatboxSticky(), 2000);
|
await helper.waitForPromise(() => helper.isChatboxSticky(), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,11 +124,11 @@ helper.enableStickyChatviaSettings = () => {
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.disableStickyChatviaSettings = () => {
|
helper.disableStickyChatviaSettings = async () => {
|
||||||
const stickyChat = helper.padChrome$('#options-stickychat');
|
const stickyChat = helper.padChrome$('#options-stickychat');
|
||||||
if (!helper.isSettingsShown() || !stickyChat.is(':checked')) return;
|
if (!helper.isSettingsShown() || !stickyChat.is(':checked')) return;
|
||||||
stickyChat.click();
|
stickyChat.click();
|
||||||
return helper.waitForPromise(() => !helper.isChatboxSticky(), 2000);
|
await helper.waitForPromise(() => !helper.isChatboxSticky(), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,11 +137,11 @@ helper.disableStickyChatviaSettings = () => {
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.enableStickyChatviaIcon = () => {
|
helper.enableStickyChatviaIcon = async () => {
|
||||||
const stickyChat = helper.padChrome$('#titlesticky');
|
const stickyChat = helper.padChrome$('#titlesticky');
|
||||||
if (!helper.isChatboxShown() || helper.isChatboxSticky()) return;
|
if (!helper.isChatboxShown() || helper.isChatboxSticky()) return;
|
||||||
stickyChat.click();
|
stickyChat.click();
|
||||||
return helper.waitForPromise(() => helper.isChatboxSticky(), 2000);
|
await helper.waitForPromise(() => helper.isChatboxSticky(), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,10 +150,10 @@ helper.enableStickyChatviaIcon = () => {
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.disableStickyChatviaIcon = () => {
|
helper.disableStickyChatviaIcon = async () => {
|
||||||
if (!helper.isChatboxShown() || !helper.isChatboxSticky()) return;
|
if (!helper.isChatboxShown() || !helper.isChatboxSticky()) return;
|
||||||
helper.titlecross().click();
|
helper.titlecross().click();
|
||||||
return helper.waitForPromise(() => !helper.isChatboxSticky(), 2000);
|
await helper.waitForPromise(() => !helper.isChatboxSticky(), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,12 +168,12 @@ helper.disableStickyChatviaIcon = () => {
|
||||||
* @todo for some reason this does only work the first time, you cannot
|
* @todo for some reason this does only work the first time, you cannot
|
||||||
* goto rev 0 and then via the same method to rev 5. Use buttons instead
|
* goto rev 0 and then via the same method to rev 5. Use buttons instead
|
||||||
*/
|
*/
|
||||||
helper.gotoTimeslider = (revision) => {
|
helper.gotoTimeslider = async (revision) => {
|
||||||
revision = Number.isInteger(revision) ? `#${revision}` : '';
|
revision = Number.isInteger(revision) ? `#${revision}` : '';
|
||||||
const iframe = $('#iframe-container iframe');
|
const iframe = $('#iframe-container iframe');
|
||||||
iframe.attr('src', `${iframe.attr('src')}/timeslider${revision}`);
|
iframe.attr('src', `${iframe.attr('src')}/timeslider${revision}`);
|
||||||
|
|
||||||
return helper.waitForPromise(() => helper.timesliderTimerTime() &&
|
await helper.waitForPromise(() => helper.timesliderTimerTime() &&
|
||||||
!Number.isNaN(new Date(helper.timesliderTimerTime()).getTime()), 10000);
|
!Number.isNaN(new Date(helper.timesliderTimerTime()).getTime()), 10000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ helper.contentWindow = () => $('#iframe-container iframe')[0].contentWindow;
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.showChat = () => {
|
helper.showChat = async () => {
|
||||||
const chaticon = helper.chatIcon();
|
const chaticon = helper.chatIcon();
|
||||||
if (!chaticon.hasClass('visible')) return;
|
if (!chaticon.hasClass('visible')) return;
|
||||||
chaticon.click();
|
chaticon.click();
|
||||||
return helper.waitForPromise(() => !chaticon.hasClass('visible'), 2000);
|
await helper.waitForPromise(() => !chaticon.hasClass('visible'), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,10 +25,10 @@ helper.showChat = () => {
|
||||||
*
|
*
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
helper.hideChat = () => {
|
helper.hideChat = async () => {
|
||||||
if (!helper.isChatboxShown() || helper.isChatboxSticky()) return;
|
if (!helper.isChatboxShown() || helper.isChatboxSticky()) return;
|
||||||
helper.titlecross().click();
|
helper.titlecross().click();
|
||||||
return helper.waitForPromise(() => !helper.isChatboxShown(), 2000);
|
await helper.waitForPromise(() => !helper.isChatboxShown(), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue