Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Spec filtering for Jasmine
/**
* Determines if the given jasmine spec should run based on whether it's highest
* level suite desciption match the value of the runMatch parameter in the url.
*
* @param {Spec} spec Jasmine spec object that is about to be executed.
*
* @returns {Boolean} True if spec should run, false if it should be skipped.
*/
var specFilter = function(spec){
/**
* @param {String} name Key of the value to be retrieved from the url.
*
* @returns {Object} Value of the requested key or undefined if the key does
* not exist in the url.
*/
var getQueryParam = function(name){
var pairs = window.location.search.slice(1).split('&');
for (key in pairs){
var arr = pairs[key].split('=');
if (arr[0] === name)
return decodeURIComponent(arr[1].replace(/\+/g, " "));
}
}
var val = getQueryParam('runMatch') || '';
// Find the outermost suite this spec belongs to.
var suite = spec.suite;
while (suite.parentSuite) suite = suite.parentSuite;
return suite.description.toLowerCase().indexOf(val.toLowerCase()) !== -1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment