Reputation: 7967
I've been trying to unit test some angular js services using Mocha by injecting mock dependencies. I've read a lot about this and there is some suggestion that using the master branch of angular-mocks should work fine with mocha. However, when I try this, I get the follwing javascript error and the 'inject' and 'module' functions are undefined:
ReferenceError: beforeEach is not defined
I've also tried using angular.injector, which has led me to some success, however, I am unable to mock the services which my service depend on (in this case $http). My service:
var app = angular.module('app', ['ui.bootstrap'], function($provide){
$provide.factory('myService', ['$http', function($http){
return {
doSomething: function(batch){
...
}
};
}]);
});
Resolving:
$injector = angular.injector(['ng', 'app']);
var subject = $injector.get('myService');
Is this possible without using jasmine?
Upvotes: 2
Views: 1595
Reputation: 1336
The angular-mocks shipped with all AngularJS versions < 1.2.0 is not compatible with mocha. Use the bower version of angular-mocks instead: https://github.com/angular/bower-angular-mocks
Upvotes: 0