JavaScript waitForever
Publikováno: 10.12.2018
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. […]
The post JavaScript waitForever appeared first on David Walsh Blog.
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!
The post JavaScript waitForever appeared first on David Walsh Blog.