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!
One of my favorite social APIs was the Open Graph API adopted by Facebook. Adding just a few META tags to each page allowed links to my article to be styled and presented the way I wanted them to, giving me a bit of control...
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...
One of the website features my customers love to provider their web users is an online dynamic calendar. An online calendar can be used for events, upcoming product specials, memos, and anything else you can think of. I've taken some time to completely...
I love that JavaScript toolkits make enhancing web pages incredibly easy. Today I'll cover an effect that I've already coded with MooTools: creating a Twitter-style animated "Sign In" button. Check out this five minute tutorial so you can take your static...
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?