Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debug in browser using testacular (now karma)

I am trying to figure out the best way to debug my unit tests when I break them. Typically in previous test environments I could just run the tests in the browser and breakpoint the test, or the code and see why my test was failing. I can't seem to figure out how to do that with testacular. Is there an easy way to debug unit tests?

like image 812
Lucas Avatar asked Apr 09 '13 16:04

Lucas


People also ask

How do I run a karma test in Chrome?

To launch Chrome from karma, we need to use karma-chrome-launcher. Run the command npm install karma-chrome-launcher --save to install to the application. Add the karma-chrome-launcher plugin to the plugins list in your karma.


2 Answers

  1. In karma.conf.js:

    browsers = ['Chrome']; 
  2. In your failing spec:

    it('spec', function() {     debugger; // This is like setting a breakpoint     // ... }); 
  3. Run Karma.
  4. Go to the newly opened Chrome Browser, open the console and refresh the page.

Now in Chrome's Developer Tools source tab you should see the execution stopped at the debugger.

like image 69
Tomas Romero Avatar answered Oct 25 '22 09:10

Tomas Romero


Include "browsers = ['Chrome'];" in your karma.config file.

When Chrome opens, you should see "Karma - connected" at the top, with a "Debug" button to the upper-right.

Click this debug button, and a "Karma DEBUG RUNNER" tab will open. Then, simply right-click, inspect element, and debug as you normally would.

like image 20
Josh Noe Avatar answered Oct 25 '22 09:10

Josh Noe