DevTools/mochitests coding standards: Difference between revisions

Jump to navigation Jump to search
Removing the custom asyncTest function with the native add_task
(Removing the custom asyncTest function with the native add_task)
Line 100: Line 100:
Here are a few things to keep in mind with regards to asynchronous testing:
Here are a few things to keep in mind with regards to asynchronous testing:


* head.js already calls waitForExplicitFinish() so there's no need for your new test to do it too. Since calling that function makes it mandatory to call finish() when the test does end, this is done automatically in the promise handler of the asyncTest() function. So if you used it, you don't need to worry about calling it.
* head.js already calls waitForExplicitFinish() so there's no need for your new test to do it too.


* Using asyncTest with a generator function means that you can yield calls to functions that return promises. It also means your main test function can be written as synchronous code would be, simply adding yield before calls to asynchronous functions. Here is, for example, a for loop:
* Using add_task with a generator function means that you can yield calls to functions that return promises. It also means your main test function can be written as synchronous code would be, simply adding yield before calls to asynchronous functions. Here is, for example, a for loop:


   for (let i = 0; i < testData.length; i ++) {
   for (let i = 0; i < testData.length; i ++) {
130

edits

Navigation menu