function calculatorService() {
const service = {};
service.add = function(a,b) {
return a + b
}
return service;
}
angular.module('app').factory('calculatorService', calculatorService);
Testing
describe('calculator service', function() {
var calculatorService;
beforeEach(angular.mock.module('app'));
beforeEach(inject(function(_calculatorService_) {
calculatorService = _calculatorService_;
}));
it('should should add two numbers', function(){
var actual = calculatorService.add(1,2);
expect(actual).toBe(3);
});
})