我正在使用茉莉跑者测试角度代码。

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...
    })
  })
})

如果多次运行结果非常糟糕,我需要在IT语句之前实例化某些内容。我该如何正确完成?

有帮助吗?

解决方案

我相信您在第一个之前的第一个中将其称为一次,每个描述都将在其下方运行一次。

在下面的代码中,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...
    });
  });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top