Looking to create a unit test for a simple factory that calculates the sum of two numbers.
(function () {
"use strict";
angular
.module("math")
.factory("addservice", [addTwoNumbers]);
function addTwoNumbers(a, b) {
return a + b;
}
return { add: addTwoNumbers };
})();
Here's my test spec progress so far.
describe('adding two numbers', function () {
var addService;
beforeEach(function () {
module('math');
inject(function ($injector) {
addService = $injector.get('addservice');
});
});
it('should add two numbers and equal 2', function () {
var result = addService.add(1, 1);
expect(result).toBe(2);
});
});
Encountering a TypeError: addService.add is not a function when running the test. Before, we had a different factory structure to avoid minification issues with parameter names getting muddled. However, the refactored code seems to require referencing the addTwoNumbers function in a different way. Any insight on how to address this would be appreciated.