开发者

How to extract QUnit results from the document

开发者 https://www.devze.com 2022-12-18 20:08 出处:网络
When QUnit adds the test result details to your HTML document, it thoughtfully wraps the numbers of tests taken, passed and failed inside span elements, each with its own class, to let you recover the

When QUnit adds the test result details to your HTML document, it thoughtfully wraps the numbers of tests taken, passed and failed inside span elements, each with its own class, to let you recover these three numbers programmatically. However, even though I can see the spans in the finished HTML, I can开发者_运维问答't find them when I search with

jQuery('span.failed');   // For example

They aren't there during the onload event, although they are for the onunload event. Nor can I get them just after the QUnit test() calls.

What am I doing wrong?


QUnit offers a callback-method, which you need to overwrite: QUnit.done(failures, total)

It is called when the last test has finished, and gets both the number of failed tests as well we the total number of tests. so you simply define

QUnit.done = function(failures, total) {
   // do whatever here
}

and that's it.


Javascript timing can be a little tricky. Instead of doing:

test();
yourMethod();

You might want to try doing:

test();
window.setTimeout(yourMethod, 1000);

Depending on what the issue is exactly, you may even be able to get away with 1 instead of 1000 (but I figure 1 second isn't that terrible in any case).

0

精彩评论

暂无评论...
验证码 换一张
取 消