jeudi 2 juin 2016

Jasmine: why beforeEach() works in nested describe but beforeAll() doesn't?

I am struggling to understand why my code won't work and why the tests fail when I use a simple beforeAll() instead of a beforeEach() in a nested describe suite of tests? Here is a small example to outline my problem:

describe("myService", function() {
  // Basic services
  // Some variables 

  beforeEach(module('app'));   // Invoke the module
  beforeEach(function(){

    // Inject the services
    inject(function(_myService_) {
      myService = _myService_;
    });
  });

  /************************ Add more unit tests here ************************/

  describe("myFunction", function() {
    describe("calls function with one set of input paramenters", function() {

      //beforeAll(function() {
      beforeEach(function() { // <-- Why this works but beforeAll doesn't???
        // Call myFunction with different parameters
        result = myService.myFunction(parametersType_1);
      });

      it("should do tests on result (the return from the function)", function() {
      });
    });

  describe("calls function with other set of input paramenters", function() {

    //beforeAll(function() {
    beforeEach(function() { // <-- Why this works but beforeAll doesn't???
      // Call myFunction with different parameters
      result = myService.myFunction(parametersType_2);
    });

    it("should do tests on result (the return from the function)", function() {
    });
  });
}); 

Aucun commentaire:

Enregistrer un commentaire