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!
Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...
CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals. Add animation and you've got something really neat. Unfortunately each CSS cube tutorial I've read is a bit...
Many times you'll see a form dynamically change available values based on the value of a form field. For example, a "State" field will change based on which Country a user selects. What annoys me about these forms is that they'll often do an...
I'd bet one of the most used MooTools methods is the setStyle()
method, which allows you to set CSS style declarations for an element. One of the limitations of MooTools' setStyle()
method is that it sets the specific style for all medias.
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?