5

私のテストは次のようになります。

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)
4

2 に答える 2

4

QUnitのドキュメントによると、モジュールの開始(および終了)時にコールバックがあり、その時点でDOMを変更できます。

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

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

リストの真ん中に何かを置くことは、一種のいたずらなDOMの賢明なことですが、少なくともFireFoxではうまくいくようです。

于 2009-10-24T04:37:22.607 に答える
0

Justin Love のソリューションは私にはうまくいきませんでしたが、テストの後に次の 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>"
                ;})
        }
    });
});
于 2012-08-09T23:53:37.437 に答える