JavaScript waitForever
Writing mochitests for new features in DevTools can be difficult and time-consuming. There are so many elements interacting in an async manner that I oftentimes find myself using the debugger to debug the debugger! In the case where it's unclear what interaction isn't working properly, I find myself going to a neat utility function: waitForever
. By using this function, paired with await
, I can interact with the page while a given test is running to find the problem!
The JavaScript
waitForever
is a super small snippet:
function waitForever() {
return new Promise(r => {});
}
// Usage:
await waitForever();
The function uses a promise which never resolves, thus no additional statements are triggered while also not locking up the browser. From there I can click around and explore elements to find what I've messed up in my test.
Utility functions like these make web development much easier and more enjoyable. Add this one to your toolbox!
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...
We all love trusted JavaScript frameworks like MooTools, jQuery, and Dojo, but there's a big push toward using focused micro-frameworks for smaller purposes. Of course, there are positives and negatives to using them. Positives include smaller JS footprint (especially good for mobile) and less cruft, negatives...
GitHub seems to change a lot but not really change at all, if that makes any sense; the updates come often but are always fairly small. I spotted one of the most recent updates on the pull request page. Links to long branch...
Thanks for the tip David! I’ll keep that in mind when working on mochi tests. Have you found any other uses for this snippet?