Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a handle to current spec from beforeEach in jasmine test?

I understand that currentSpec reference is no longer available in beforeEach from jasmine 2.0.0 (Ref: https://github.com/pivotal/jasmine/issues/492)

Is there an alternative to find the current Spec or Suite(a nested suite) in beforeEach?

Thanks, vj.

like image 843
vjk Avatar asked Nov 11 '22 10:11

vjk


1 Answers

You can use a reporter

describe("outer", function() {

  var specDescription, specFullName;

  (function() {
    jasmine.getEnv().addReporter({
      suiteStarted: function(result) {
        specDescription = result.description;
        specFullName = result.fullName;
      }
    });
  })();

  beforeEach(function() {
    console.debug(specDescription);
    console.debug(specFullName);
  });


  describe("test1", function() {
    it("bla bla", function() {});
  });
  describe("test2", function() {
    it("bla bla", function() {});
  });
}
like image 132
zjk Avatar answered Nov 14 '22 21:11

zjk