Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript, Jasmine, hide disabled jasmine specs

I'd like to hide the disabled jasmine specs when I run chosen tests. I'll have lot's of tests, so I wouldn't like to scroll down after each refresh to reach the tests which are at the bottom.

Is there any option in jasmine that allows it? I've went through the docs but didn't find anything.

like image 615
Emil A. Avatar asked Jul 22 '14 07:07

Emil A.


Video Answer


2 Answers

This was a design decision by pivotal as documented by this issue.

https://github.com/pivotal/jasmine/issues/510

Here is the fix from a comment in the issue.

In jasmine-html.js, add a function to recursively determine if a result node has any active specs:

function hasActiveSpec(resultNode) {
  if (resultNode.type == "spec" && resultNode.result.status != "disabled") {
    return true;
  }

  if (resultNode.type == 'suite') {
    for (var i = 0, j = resultNode.children.length; i < j; i++) {
      if (hasActiveSpec(resultNode.children[i])) {
        return true;
      }
    }
  }
}

Then, in the summaryList function, just run that filter for suites:

// ...
var resultNode = resultsTree.children[i];
if (resultNode.type == "suite") {
  // Don't display inactive suites
  if (!hasActiveSpec(resultNode)) {
    continue;
  }

  // var suiteListNode = ...
  // ...
}
like image 100
Randall Sutton Avatar answered Sep 24 '22 01:09

Randall Sutton


If you don't want to modify the Jasmine source, you can also add a hook like this (my example assumes jQuery is present):

jasmine.getEnv().addReporter({
    jasmineDone: function () {
        $(".disabled").parents(".suite").hide();
    }
});

See http://jasmine.github.io/2.1/custom_reporter.html for more info.

like image 31
John Kurlak Avatar answered Sep 21 '22 01:09

John Kurlak