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?
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.
####
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With