Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript QUnit输出:模块的可视分离_Javascript_Unit Testing_Qunit - Fatal编程技术网

Javascript QUnit输出:模块的可视分离

Javascript QUnit输出:模块的可视分离,javascript,unit-testing,qunit,Javascript,Unit Testing,Qunit,我的测试可能如下所示: module("some module"); test("test A", ...); test("test B", ...); module("other module"); test("test C", ...); test("test D", ...); QUnit的输出将如下所示 1. test A (0, 0, 0) 2. test B (0, 0, 0) 3. test C (0, 0, 0) 4. test D (0, 0, 0) 可以让QUnit

我的测试可能如下所示:

module("some module");

test("test A", ...);
test("test B", ...);

module("other module");

test("test C", ...);
test("test D", ...);
QUnit的输出将如下所示

1. test A (0, 0, 0)
2. test B (0, 0, 0)
3. test C (0, 0, 0)
4. test D (0, 0, 0)
可以让QUnit输出模块名吗? 我希望:

some module
1. test A (0, 0, 0)
2. test B (0, 0, 0)

other module
3. test C (0, 0, 0)
4. test D (0, 0, 0)
根据,在模块start(和end)上有一个回调,此时您可以修改DOM

QUnit.moduleStart = function(name) {
  var tests = document.getElementById("qunit-tests");

  if ( tests ) {    
    var mod = document.createElement("h2");
    mod.innerHTML = name;
    tests.appendChild( mod );
  }
};

把东西放在列表中间是一种顽皮的DOMWISH,但它似乎是有效的,至少在Firefox中。

< P>贾斯廷爱的解决方案对我来说不起作用,但是你可以在测试之后插入下面的jQuery JavaScript以达到相同的期望结果:

QUnit.done(function( details )
{
    $("#qunit-tests > li ") //the test rows
    .each(function(index, Element){
        var moduleName = $(".module-name", this).text();
        if (moduleName !== $(".module-name", this.previousSibling).text())
        {
            $(this).before( //prepend header to it
                function(){
                    return "<h3 class='module-header'>" + moduleName + "</h3>"
                ;})
        }
    });
});
quonit.done(函数(细节)
{
$(“#quonit tests>li”)//测试行
.每个(功能(索引、元素){
var moduleName=$(“.module name”,this).text();
if(moduleName!=$(“.module name”,this.previousSibling).text())
{
$(this).before(//在其前面加上标题
函数(){
返回“+moduleName+”
;})
}
});
});