edA-qa mort-ora-y
edA-qa mort-ora-y

Reputation: 31851

How to see errors of a Testacular/AngularJS test

I've inherited a AngularJS/Testacular/Jasmine unit test suite and am having difficulty determining how to run a test and see any associated failure messages. That is, I can easily run all the tests, I can do something like ddescribe to run one test, and I can see that it fails. But now I have no way to determine why it is failing.

I've installed Firebug and can see console.log statements, but not JavaScript errors (I assume it is a JS error since it just abruptly ends). I also saw the "debug.html" endpoint for Testacular but I have no clue how I'd use it.

How can I see the likely JavaScript errors which are causing my test to fail?

Upvotes: 0

Views: 1198

Answers (2)

Jmr
Jmr

Reputation: 12108

I'm not familiar with firebug, but if you're able to capture a Chrome browser you can open up the developer console (tools -> JavaScript console) and see errors there. You can set a breakpoint when the javascript console is open by putting the line

debugger;

in your code. The next time your tests are run, Chrome will pause at that line and you can use the console to inspect variables.

Upvotes: 2

musically_ut
musically_ut

Reputation: 34288

I am using Karma version 0.8.4

Not sure whether this is the best way of doing it, but I generally capture a browser while running Karma in the CI mode.

Then I can click on Debug button on the open browser window to run Jasmine in a single page mode. That file is hosted at http://localhost:9876/debug.html and can be directly accessed, if the Debug button is not available/visible.

Peeking at the console there tells me what errors ail my scripts. I have to do it sometimes since I am using RequireJS and missing dependencies just result in:

Uncaught Error: Script error http://requirejs.org/docs/errors.html#scripterror

As a side note: consider using JSHint to avoid common JS syntax errors.

Upvotes: 0

Related Questions