lairtech
lairtech

Reputation: 2417

Mocha JS: How to highlight specific assertion failure?

In my test with multiple assertions, Mocha's test report simply reports "AssertionError". There is no marker in the code output to indicate exactly which assertion failed. Is there a way to configure Mocha to give more informative reports?

Upvotes: 0

Views: 149

Answers (2)

machineghost
machineghost

Reputation: 35790

As Andreas mentioned, Mocha gives you a choice of reporters, which can affect your output.

But what he left out is that the failure messages you get have nothing to do with Mocha at all. Instead, they depend entirely on your assertion library (Chai, Expect, etc.). So if you aren't happy with the output your tests give when they fail, you should really look at your assertion library to see how it can generate better messages.

For example, with Chai there is an optional message argument:

expect(actual, 'message').to.be.true;

If that assertion fails you won't just get "AssertionError", you'll get:

message: expected false to be true.

Hope that helps.

Upvotes: 0

Andreas Köberle
Andreas Köberle

Reputation: 110912

You can change the reporter with: --reporter or -R. So this command will output the results for every spec:

mocha -R spec

Upvotes: 2

Related Questions