Domanda

Sto usando Jasmine Runner per testare il codice angolare.

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

Devo istanziare qualcosa una volta prima delle dichiarazioni IT, se l'esecuzione più volte il risultato è piuttosto negativo. Come posso farlo correttamente?

È stato utile?

Soluzione

Credo che tu lo chiami una volta nel primo prima che verrà eseguito una volta per ogni descrizione che è al di sotto di esso.

Nel codice seguente, Des2Var verrà impostato una volta per l'intero test1 Descrivere.

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...
    });
  });
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top