用Mochatestingjavascript – 我如何使用console.log来debuggingtesting?

我正在使用JavaScripttesting运行“Mocha”。

我有一个失败的testing,所以我会debugging它使用console.log

但是当testing运行时,没有输出(仅来自Mocha的testing结果)。 摩卡似乎已经捕获并压制了我的console.log输出!

我怎样才能让摩卡显示我的输出? (在testing失败)?

编辑:

巨大的歉意! – console.log在testing过程中不起作用! 我一定是期待它压制输出,我没有正确地检查我自己的代码。 感谢您的回应。 所以…说的话…也许它实际上会是很好的压制输出testing通过? 嗯…

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

我是唯一一个发现这个棘手的人吗? 你们如何debuggingnode.js? 用debugging器,还是用console.log语句?

你正在使用什么摩卡选项?

也许这跟使用记者(-R)或者ui(-ui)有关系?

 console.log(msg); 

在我的testing运行期间工作正常,虽然有时混合在一个有点愚蠢。 可能是由于testing运行的asynchronous性质。

这里是我正在使用的选项(mocha.opts):

 --require should -R spec --ui bdd 

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

如果您正在testingasynchronous代码,则需要确保将done()放在该asynchronous代码的callback中。 在testinghttp请求到REST API时,我遇到了这个问题。

你可能也会把你的console.log放在一个失败的预期之后,因此你的日志行不会被执行。