I've been facing some challenges while attempting to test my AngularJs services with Jasmine as I encounter various errors consistently. In an effort to troubleshoot, I decided to create a simple Sum service for testing purposes but unfortunately, the errors persist.
Below is the AngularJS service that I am trying to test:
angular.module('base', [])
.service('operacoes', [function () {
this.somar = function (n1,n2) {
return n1 + n2;
};
}]);
Here's the test script I have written:
/// <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('should be initialized', function () {
expect(operacoesObj).toBeDefined();
});
it('should be able to add 2 numbers', function () {
expect(operacoesObj.somar(5, 1)).to.equal(6);
});
});
Upon running these tests, I encountered 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 have experimented with different versions of Jasmine like 2.4.1 and currently using version 2.5.2.