QUnit output: visual separation of modules

My tests might look like this:

module("some module");

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

module("other module");

test("test C", ...);
test("test D", ...);

QUnit output will look like this:

1. test A (0, 0, 0)
2. test B (0, 0, 0)
3. test C (0, 0, 0)
4. test D (0, 0, 0)

Can QUnit get module names? I would like:

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)
+5
source share
2 answers

According to the QUnit Documentation , there is a callback when starting (and ending) the module, after which you can change the DOM.

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

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

Putting content in the middle of the list is a disgusting DOM, but it seems to work, at least in FireFox.

+4
source

Justin Love's solution did not work for me, but after the test, you can insert the following jQuery Javascript to achieve the same desired result:

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>"
                ;})
        }
    });
});
0
source

All Articles