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

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


What Mocha options are you using?

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.

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

--require should-R spec--ui bdd

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


If you are testing asynchronous code, you need to make sure to place done() in the callback of that asynchronous code. I had that issue when testing http requests to a REST API.


You may have also put your console.log after an expectation that fails and is uncaught, so your log line never gets executed.