I'm trying to test my AngularJs services using Jasmine but I keep getting all kinds of errors. So I tried to create a very basic Sum service to test it and the errors keep on coming.
This is the AngularJS service I'm trying to test:
angular.module('base', [])
.service('operacoes', [function () {
this.somar = function (n1,n2) {
return n1 + n2;
};
}]);
And my test:
/// <reference path="../../Scripts/angularjs/angular.min.js" />
/// <reference path="../../Scripts/angularjs/angular-mocks.js" />
/// <reference path="../../ServicoBase.js" />
describe("Testing Services", function () {
var operacoesObj;
beforeEach(angular.module('base'));
beforeEach(inject(function (operacoes) {
operacoesObj = operacoes;
}));
it('deve ter inicializado', function () {
expect(operacoesObj).toBeDefined();
});
it('deve conseguir somar 2 números', function () {
expect(operacoesObj.somar(5, 1)).to.equal(6);
});
});
Trying to run this tests returns me the following errors:
- TypeError: Object doesn't support property or method 'call'
- [$injector:unpr] http://errors.angularjs.org/1.4.4/$injector/unpr?p0=operacoesProvider%20%3C-%20operacoes
- Expected undefined to be defined.
I've tried other Jasmine versions like 2.4.1 (running now on 2.5.2).