Keeping the Console Clean in Jasmine

August 29, 2013 Charles Hansen

I like running Jasmine with the console open. It gives you insight into various errors that you may not have tests around but may still show up in the console messages. It can detect anything from poorly written tests that fail to run at all to accidentally checked-in console logs.

This approach only works if the console isn’t flooded with useless error messages. If your html has images in it that are normally served by your web server, the images will be fetched and cause 404 messages. You can sometimes get around this by serving up the images in Jasmine or relying entirely on css for your images, but this only works in simple situations. The surefire way to kill these errors is to intercept the image requests and ignore them. If you are using the Jasmine gem, this can be done by adding the following code to your jasmine_helper.rb (not yet tested in Jasmine 2.0)

[gist id=6374623]

The code will specifically not interfere with any requests for javascript files, but it will respond to most images with 200, content type of “image/jpeg” and no actual data. It is in a premature case statement because you may find images aren’t the only thing causing this trouble (see the Chorus version).

Try adding the middleware to your jasmine_helper and possibly tweaking it to block out any unnecessary server requests. Now your Jasmine console should be nice and clean. If it isn’t, hopefully that is telling you something useful about a fragile part of your JavaScript.

About the Author

Biography

Previous
Using Ruby Expect Library to Reboot Ruckus Wireless Access Points via ssh
Using Ruby Expect Library to Reboot Ruckus Wireless Access Points via ssh

Abstract We require a nightly rebooting of our Ruckus Wireless WiFi access points. The Ruckus controllers ...

Next
The Next Evolution of North American Banking: P2P Payments
The Next Evolution of North American Banking: P2P Payments

It is no secret that person-to-person payments (P2P payments) have made an impact in Kenya. Since Safaricom...