Testing javascript with Mocha - how can I use console.log to debug a test?

I am using javascript test-runner "Mocha".

I have a test that fails, so I would debug it using console.log .

But when the tests are executed, there is no way out (only the test results from Mocha). Mocha seems to have grabbed and suppressed console.log output!

How can I get mocha to output my output? (for failed tests)?

EDIT:

Huge apologies! - console.log works during tests! I must have expected it to suppress the output and I was not able to test my own code. Thanks for answering. So ... what was said ... maybe it would be nice to suppress the output for tests that pass? hmm ...

Regarding the note: I want to use console.log because I have a lot of problems trying to get the Eclipse debugger to connect to node.js.

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

+73
javascript mocha
May 19 '12 at 15:07
source share
3 answers

What Mocha options do you use?

Maybe this is due to the use of reporter (-R) or ui (-ui)?

 console.log(msg); 

works great during my test runs, although sometimes they are mixed in a bit dumb. Presumably due to the asynchronous nature of the test run.

Here are the parameters (mocha.opts) that I use:

 --require should -R spec --ui bdd 

Hmm .. checked without any mocha.opts and console.log still working.

+39
May 19 '12 at 3:24 pm
source share

If you are testing asynchronous code, you need to put done() in the callback of this asynchronous code. I had this problem when testing HTTP requests in a REST API.

+28
Nov 07 '13 at 20:13
source share

You may also have placed your console.log after a wait that failed and is not shown, so your log line will never be executed.

+12
Feb 28 '16 at 20:49
source share