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 it7;s unclear what interaction isnR7;t working properly, I find myself going to a neat utility function: .  By using this function, paired with await, I can interact with the page while a given test is running to find the problem!


The


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!

  • 9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we’re still playing a bit of catch up to natively duplicate the animation capabilities that Adobe’s old provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available…

  • Write Simple, Elegant and Maintainable Media Queries with Sass
  • Cross Browser CSS Box Shadows

    Box shadows have been used on the web for quite a while, but they weren’t created with CSS — we needed to utilize some Photoshop game to create them.  For someone with no design talent, a.k.a me, the need to use Photoshop sucked.  Just because we…

  • MooTools Overlay Plugin

    Overlays have become a big part of modern websites; we can probably attribute that to the numerous lightboxes that use them. I’ve found a ton of overlay code snippets out there but none of them satisfy my taste in code. Many of them are…



Source link
thanks you RSS link
( https://davidwalsh.name/javascript-wait)

LEAVE A REPLY

Please enter your comment!
Please enter your name here