vjk
vjk

Reputation: 73

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.

Upvotes: 5

Views: 1127

Answers (1)

zjk
zjk

Reputation: 2153

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() {});
  });
}

Upvotes: 1

Related Questions