javascript - Injecting dependencies into Angular services for testing -
i'm trying test driven development of angular service i'm writing using jasmine. however, seem have stumbled @ first hurdle, , cannot $resource dependency resolve.
the error unknown provider: $resourceprovider <- $resource <- lookupservice
my code follows
module:
(function() { 'use strict'; angular .module('common', ['ngsanitize', 'nganimate']); })();
service:
(function() { 'use strict'; angular .module('common') .service('lookupservice', lookupservice); lookupservice.$inject = ['$resource', 'api']; function lookupservice($resource, api) { return { getlookup: getlookup }; function getlookup() { return "something"; } } })();
test:
describe('service tests', function () { var lookupservice, mockapi, $httpbackend; //mocks beforeeach(function () { mockapi = { geturi: jasmine.createspy() }; angular.mock.module('common', function ($provide) { $provide.value('api', mockapi); }); }); //injects beforeeach(function () { inject(function ($injector) { $httpbackend = $injector.get('$httpbackend'); lookupservice = $injector.get('lookupservice'); }); }); //tests it('should able return something', inject(function () { expect(lookupservice.getlookup()).toequal("something"); })); });//service tests
the angular-resource.js file included in runner file. i'm not sure i'm going wrong, appreciated.
thanks
ngresource must dependency:
(function() { 'use strict'; angular .module('common', ['ngsanitize', 'nganimate', 'ngresource']); })();
Comments
Post a Comment