Debugging Unit Tests in Karma

Wouldn’t it be nice if there is an easy way to debug our unit tests in browser, just as we do during development. Well, it turns out to be as easy as that.

The simplest command to spin up a Karma test runner is:
karma start karma.conf.js

just add these options to that command and you should see a Chrome browser that doesn’t close automatically once the tests are completed:

karma start karma.conf.js --browsers=Chrome --single-run=false

Karma in debug mode
Karma in debug mode

Notice the debug button to the top right. Click on that. That would open up a new tab. In Chrome Developer Tools, you can see the source code and test files associated with this test. You can then go about just keeping breakpoints, as you would do during development, and reload the tab.

 

Karma debug mode – view files

Leave a Reply

Your email address will not be published. Required fields are marked *