0

I am using jasmine runner to test angular code.

describe('des1', function() {
  var des1Var = function(){};
  beforeEach() {
    //....
  }

  describe('test1', function() {
    var scope4Compile = $rootScope.$new();
    var des2Var = des1Var(scope4Compile); // returns undefined.

    beforeEach(function() {
      des2Var = des1Var(scope4Compile); // returns des1Var() fine;
    })

    it('should do ', function(){
      //should do...
    })

    it('should also do', function(){
      //should also do...
    })
  })
})

I need to instantiate something once before the it statements, if run multiple times result is pretty bad. How can I get it done properly?

4

1 回答 1

1

我相信你在第一个 beforeEach 中调用它一次,它将为它下面的每个描述运行一次。

在下面的代码中,des2Var 将为整个 test1 描述设置一次。

describe('des1', function() {
  var des1Var = function () { };
  beforeEach(function () {
    var des2Var = des1Var();
  });

  describe('test1', function() {
    it('should do ', function(){
        //should do...
    });

    it('should also do', function(){
        //should also do...
    });
  });
});
于 2013-11-12T20:58:28.320 回答