I'm writing E2E tests in TypeScript and trying to keep its type system happy.
Initially I had the following code:
const textFromAllNoteParagraphs = $$('.markdown-preview-section p:not(.mod-ui)')
.map(p => p.getText())
const textContent = (await textFromAllNoteParagraphs).join('\n\n')
While it does the job, TypeScript is not completely happy, because for the second expression it says:
'await' has no effect on the type of this expression. ts(80007)
Also, TypeScript-ESLint complains for the same reason:
Unexpected `await` of a non-Promise (non-"Thenable") value. eslint (@typescript-eslint/await-thenable)
It makes sense to me, because according to types declared textFromAllNoteParagraphs
is Promise<string>[]
(mapped from WebdriverIO.Element[]
array).
Then I try to change the second expression to use Promise.all
as follows:
const textContent = (await Promise.all(textFromAllNoteParagraphs)).join('\n\n')
TypeScript is now happy, but if I run my WDIO test, it simply gets stuck forever spinning my CPU (I even have to execute kill -9
to kill it). How to refactor the code to keep it working and make TypeScript happy in this situation?