Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma - Jasmine : Show line number when test failed

Is it possible to print the line number of the expect that failed ?

I'm using grunt to launch karma test (jasmine configuration) of my angularjs application).

Currently, the console log show, for example, "Expected true to equal false." and the "describe" and "it" who it comes from... But I have a lot of expect by "it" asset so it's not easy to find the "wrong" line.

Thanks

like image 727
Julien Meyer Avatar asked Nov 01 '22 12:11

Julien Meyer


1 Answers

Stack traces should be available wherever the browser used supports the .stack property on its errors. I think this has been available in PhantomJS since about v1.6.

It looks like the problem with seeing this in Jasmine is that PhantomJS only creates the stack trace when the error is thrown, and Jasmine doesn't throw errors for failed expectations.

There is a pull request to fix this in Jasmine, but it seems to be closed under the assumption that everything should be better in Jasmine 2.0 which I think is still in release candidate stages.

That leaves three main choices:

  1. Use Chrome or another browser where this does work
  2. Wait for Jasmine 2.0.0 to be stable, or install one of the release candidates to see if you get the traces
  3. Merge the pull request yourself into your own Jasmine, it's only three lines and seems the easiest to me
like image 63
Andyrooger Avatar answered Nov 09 '22 11:11

Andyrooger