Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get title (name) of currently running QUnit test

I would like to log a quick separator to the console in each QUnit test like this:

test( "hello test", function() {
    testTitle = XXX; // get "hello test" here
    console.log("========= " + testTitle + "==============");
    // my test follows here
});

How can I get the title (maybe also called "name") of the test?

like image 908
nachtigall Avatar asked Feb 11 '13 10:02

nachtigall


1 Answers

You can achieve that using the callbacks of QUnit. They are called at several different points during the execution of the tests (e.g. before each test, after each module, ...)

Here is an example from my test suite:

QUnit.begin = function() {
    console.log('####');
};

QUnit.testStart = function(test) {
    var module = test.module ? test.module : '';
    console.log('#' + module + " " + test.name + ": started.");
};

QUnit.testDone = function(test) {
    var module = test.module ? test.module : '';
    console.log('#' + module + " " + test.name + ": done.");
    console.log('####');
};

It put this in a file called helper.js and include it on the test index.html page.

It produces output like this:

####
#kort-Availability Includes: started.
#kort-Availability Includes: done.
#### 
#kort-UrlLib Constructor: started.
#kort-UrlLib Constructor: done.
#### 
#kort-UrlLib getCurrentUrl: started.
#kort-UrlLib getCurrentUrl: done. 
#### 
like image 127
Odi Avatar answered Sep 28 '22 01:09

Odi