使用Mocha测试javascript - 如何使用console.log调试测试? [英] Testing javascript with Mocha - how can I use console.log to debug a test?

查看:81
本文介绍了使用Mocha测试javascript - 如何使用console.log调试测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javascript test-runnerMocha。

I am using the javascript test-runner "Mocha".

我有一个失败的测试,所以我想用 console.log 。

I have a test that is failing, so I would to debug it using console.log.

但是当测试运行时,没有输出(只有Mocha的测试结果)。
似乎Mocha已经捕获并压制了我的 console.log 输出!

But when the tests are run, there is no output (only the test results from Mocha). It seems like Mocha has captured and suppressed my console.log output!

我怎样才能得到摩卡要显示我的输出? (对于失败的测试)?

How can I get Mocha to show my output? (at for tests that fail)?

编辑:

巨大的道歉! - console.log 在测试期间有效!我一定期待它抑制输出,我没有正确检查自己的代码。谢谢你的回复。
所以...说的......也许真的会很好地抑制通过测试的输出?嗯...

Huge apologies! — console.log does work during tests! I must have been expecting it to suppress the output, and I didn't properly check my own code. Thanks for responding. So... that being said... maybe it actually would be nice to suppress the output for tests that pass? hmm...

在相关说明中:我想使用 console.log 因为我有很多试图让Eclipse调试器连接到node.js的麻烦。

On a related note: I want to use console.log because I am having a lot of trouble trying to get the Eclipse debugger to connect to node.js.

我是唯一一个发现这个棘手的人吗?你们怎么调试node.js?使用调试器,还是使用 console.log 语句?

Am I the only one who finds this tricky? How do you guys debug node.js? With a debugger, or with console.log statements?

推荐答案

什么您正在使用摩卡选项吗?

What Mocha options are you using?

可能与使用的记者(-R)或ui(-ui)有关吗?

Maybe it is something to do with reporter (-R) or ui (-ui) being used?

console.log(msg);

在我的测试运行期间工作正常,但有时混合有点傻。大概是由于测试运行的异步性质。

works fine during my test runs, though sometimes mixed in a little goofy. Presumably due to the async nature of the test run.

以下是我正在使用的选项(mocha.opts):

Here are the options (mocha.opts) I'm using:

--require should
-R spec
--ui bdd

嗯..只测试没有任何mocha.opts和 console.log 仍然有效。

Hmm..just tested without any mocha.opts and console.log still works.

这篇关于使用Mocha测试javascript - 如何使用console.log调试测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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