I have following code in Typescript:
export const commandsFactory = (options: CommandsOptions): CommandsFunctions => {
return {
waitForPageToLoad: (): void => {
browser.waitUntil(
() => {
// console.log('Waiting for the page to load');
return utils.checkIfPageLoaded();
},
{
timeout: TIMEOUT_10000_MS,
timeoutMsg: 'Page never completed loading'
});
},
checkForJavaScriptErrors: (): void => {
this.waitForPageToLoad(); // HERE I GET "TS2532: Object is possibly 'undefined'."
let logs: any[] = browser.getLogs('browser');
logs.forEach((log) => {
if (log.level.toLowerCase() == 'severe') {
if (log.source.toLowerCase() == 'javascript') {
console.error(`${log.source.toUpperCase()} ERROR: ${log.message}`);
expect.fail(`${log.source.toUpperCase()} ERROR: ${log.message}`);
}
else {
console.log(`${log.source.toUpperCase()} ERROR: ${log.message}`);
}
}
});
}
};
};
And I get an error for this
keyword: TS2532: Object is possibly 'undefined'.
How can I call waitForPageToLoad()
function from checkForJavaScriptErrors()
function?
I feel this might be newbie question but I am not that familiar with the Typescript :)
Thanks!