unit testing - How to test function in AngularJS service with mock data -
how create jasmine unit test 1 function in angularjs service provider. want create mock data myobject , test function getobjectshape() mock data parameter. how achieve that?
(function () { 'use strict'; angular.module('objectshapes') .provider('shapesresolver', shapesresolver); function shapesresolver() { this.$get = function () { return resolver; }; function resolver(myobject) { var service = { getobjectshape: getobjectshape }; function getobjectshape() { return myobject.shape; } } } })();
here's skeleton of test service.
describe('shapesresolver service', function() { var shapesresolver; beforeeach(module('objectshapes')); beforeeach(inject(function(_shapesresolver_) { shapesresolver = _shapesresolver_; })); it('should something, what?', function() { var mockmyobject = {}; shapesresolver(mockmyobject); // shapesresolver doesn't return anything, , doesn't // have side effect, there's nothing test. expect(true).tobetruthy(); }); });