Search code examples
javascriptmocha.jstestcase

How to get information of Mocha #<Test> type object


I am using mocha on browser.

inside function done i have a object named as test

it('', function(done){
                console.log(this.test);
                  done(error);
              });

if we check on log we get this.test a 'Test' type object.

Test {title: "", fn: function, async: 1, sync: false, _timeout: 50000…}

if i console this.test.duration or any variable i find undefined.

i want to extract duration information of this 'Test' type object.

How to do that..??


Solution

  • I've read mocha's source but I do not see a way to extract from a test case the information you want while a test is running. The duration field is computed once, when the test ends.

    You could still compute how long your tests has been running with:

    it('', function(done){
        var started_at = new Date;
        [... do stuff ...]
        console.log("duration so far:" , (new Date - started_at) + "ms");
        [... do more stuff ...]
        done(error);
    });