In a previous post, I showed how to run browserified unit tests in a headless browser using PhantomJS and grunt-contrib-jasmine. Shortly after posting that, I found myself needing to run a debugger on my tests (because console.log debugging is not sufficient).
What to do? How do I get a debugger attached to my grunt-contrib-jasmine specs? Is it even possible to run a debugger attached to a PhantomJS instance?
A moment later, I came to my senses, opened my browser and debugged the test with Chrome DevTools.
Here’s the thing… grunt-contrib-jasmine allows you to run your tests in a headless browser… but it’s still a browser. So why not take PhantomJS out of the picture and us an actual browser when you need to debug the tests? And it turns out this is easy using grunt-contrib-connect. Just add that package to your gruntfile and configure the jasmine tests to keep the specrunner file that it generates.