Filtering Jasmine Tests

Any non-trivial project that uses Jasmine to test its front-end code will run into the problem of having to wait a long time for their test suite to finish. There are some solutions like using Jasmine’s built in runOnly url parameter but sometimes this doesn’t completely solve your problem. For instance many times I’ll be working on a specific part of an application but touching both (Backbone) models and views in my code and want to run tests against all modules that deal with this part of the application.

I’ve written a specFilter.js that support exactly this workflow. Hooking into Jasmine’s specFilter functionality is checks for a runMatch query parameter in the url and uses that to only run specs whose top-most describe block description contains the value of the runMatch parameter.

e.g. Navigating to SpecRunner.html?runMatch=View would run any top-level describe blocks that have View in the description (case-insensitive).

To use this filter simply put the following line of code before the call to start Jasmine:

jasmine.getEnv().specFilter = specFilter;