2017-06-19 1 views
1

Ich möchte Jasmin's beforeAll anstelle von beforeJedes verwenden, aber die Funktionen angular.mock.module und angular.mock.inject funktionieren nicht in beforeAll, während sie arbeite in beforeEach.Die Funktionen angular.mock.module und angular.mock.inject funktionieren nicht in Jasmins vorherAll

Hier ist mein Test. der gleiche Code arbeitet in BeforeJedes Ansatz.

describe("This is a test", function() { 
    beforeAll(module("app")); 

    var vm; 
    beforeAll(function() { 
     angular.mock.module(function ($provide) { 
      $provide.factory("dataService", ["$q", function ($q) { 
       return { 
        getSomeDataById: function() { return $q.resolve({ }); } 
       }; 
      }]); 
     }); 

     angular.mock.inject(function (_$controller_,dataService) { 
      vm = _$controller_("TestController", 
      { 
       dataService: dataService 
      }); 
     }); 
    }); 
}); 

Antwort

0

Ich war mit Blick auf ein ähnliches Problem und mit dem module.sharedInjector() Anruf gelöst es für mich:

describe("This is a test", function() { 

    // Call SharedInjector before any call that might invoke the injector 
    angular.mock.module.sharedInjector(); 

    beforeAll(module("app")); 

    var vm; 
    beforeAll(function() { 
     angular.mock.module(function ($provide) { 
      $provide.factory("dataService", ["$q", function ($q) { 
       return { 
        getSomeDataById: function() { return $q.resolve({ }); } 
       }; 
      }]); 
     }); 

     angular.mock.inject(function (_$controller_,dataService) { 
      vm = _$controller_("TestController", 
      { 
       dataService: dataService 
      }); 
     }); 
    }); 
}); 
Verwandte Themen