Suppose I have this (fake) JavaScript code:
asynchronousOperation.addEventListener("completed",
function (event) {
if (event.property == "required value") tell Selenium we are good;
else tell Selenium the test failed;
});
asynchronousOperation.run();
I'm using Python for writing tests, but I think I'd find a way to adapt the code if it is in some other language.
The best I could manage so far is to write the result somewhere in the page and then check that place using timer. But this sounds like it could be done better.