如何获取Mocha#< Test>的信息类型对象 [英] How to get information of Mocha #<Test> type object

查看:89
本文介绍了如何获取Mocha#< Test>的信息类型对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览器上使用摩卡咖啡.

I am using mocha on browser.

内部函数完成了,我有一个名为test的对象

inside function done i have a object named as test

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

如果我们检查日志,则会得到this.test一个测试"类型的对象.

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

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

如果我管理this.test.duration或任何我发现未定义的变量.

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

我想提取此测试"类型对象的持续时间信息.

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

该怎么做.. ??

推荐答案

我已经阅读了mocha的源代码,但是我没有看到一种从测试用例中提取想要的信息的方法.在跑.测试结束时,duration字段仅计算一次.

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);
});

这篇关于如何获取Mocha#< Test>的信息类型对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆