使用Zombie.js验证Qunit的结果 [英] Verifying Qunit's results with Zombie.js

查看:108
本文介绍了使用Zombie.js验证Qunit的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Qunit 进行测试驱动开发:在创建新函数时,我为它编写测试,创建函数,重新加载页面,如果所有测试都通过,我继续...虽然这在开始时工作正常,但它开始变成一个耗时的过程虽然所有测试都需要几秒钟才能运行,而且每次刷新浏览器时都需要等待。

I am doing test-driven development with Qunit: when creating a new function, I write tests for it, create the function, reload the page, and if all the tests pass I move on... Whilst this works fine at the beginning, it starts to become a time consuming process after a while as all the tests take several seconds to run, and that's the time I have to wait for every time I refresh my browser.

为了解决这个问题,我考虑过引入 Zombie.js 来执行少测试:想法是 Zombie.js 不断检查网页(例如 $ watch -n1节点queryTheWebpage.js)并在编码时向我报告 Qunits 的结果(偶尔, Zombie.js 不是一个真正的浏览器,我会打开一个浏览器并手动检查页面以进行验证。

In an attempt to workaround that problem, I thought about introducing Zombie.js to perform head-less testing: the idea is to have Zombie.js continuously check the webpage (e.g. $ watch -n1 "node queryTheWebpage.js") and report to me Qunits's results while coding (once in a while, as Zombie.js isn't a "real" browser, I would open up a browser and check the page manually to validate).

到目前为止,这里是我的节点/ Zombie代码:

So far here is what I have for my node/Zombie piece of code:

browser.visit("http://localhost/mywebpage.html", function () {
        var qunit_tests = browser.query('body');
        console.log(qunit_tests.innerHTML);
});

在控制台输出中,我看到 Qunit 测试容器< ol id =qunit-tests>< / ol> 但它是空的,这意味着当访问时调用回调函数,测试没有运行。

In the console output I do see the Qunit tests container <ol id="qunit-tests"></ol> but it is empty which means when the visit callback function is called, the tests haven't run.

我试过使用等待等待测试运行的函数,但不成功:

I've tried to use the wait function to wait for the tests to run, but unsuccessfully:

function waitForQunitToEnd(window) {
    var last = window.document.querySelector('selectorOfMyLastTest');
    var first_failed = window.document.querySelector('li.failed');
    return (last || first_failed);
}

browser.visit("http://localhost/mywebpage.html", function () {
    browser.wait(waitForQunitToEnd, function() {
        var qunit_tests = browser.query('body');
        console.log(qunit_tests.innerHTML); // still gives me empty <ol id="qunit-tests"></ol>
    });    
});

我尝试使用 waitFor 选项(例如设置为 5000 ms)但这也无济于事。

I tried to play with the waitFor option (e.g. set to 5000ms) but that didn't help either.

Q1:是什么我想要做一些有意义的事情,还是有一种更简单的方法来做类似的事情?

Q2:你知道我怎么做可以让Zombie.js等待Qunit测试运行吗?

推荐答案

我不知道是不是会帮你但看看这个: http://api.qunitjs.com/QUnit.done/

I don't know if it will help you but look this : http://api.qunitjs.com/QUnit.done/

这篇关于使用Zombie.js验证Qunit的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆