如何在茉莉花测试中获得来自beforeEach的当前规范?

时间:2014-03-21 18:46:48

标签: javascript jasmine

据我所知,来自jasmine 2.0.0的beforeEach中不再提供currentSpec参考 (参考:https://github.com/pivotal/jasmine/issues/492

是否可以在beforeEach中找到当前的Spec或Suite(嵌套套件)?

谢谢, VJ。

1 个答案:

答案 0 :(得分:0)

您可以使用记者

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