Reputation: 13
I'm getting the following error when trying to test a factory in angualar:
Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- myService
There are already tests in the project that do similar things and they work fine, so I can't for the life of me figure out why these don't work. Here is the impl code:
(function () {
'use strict';
var module = angular.module('first.module', []);
function firstThing() {
this.doSomething = function (something) {
return campaign;
};
}
module.service('firstThing', firstThing);
function myServiceFactory($resource, notifier) {
var Resource = $resource('/api/campaigns/:id', { id: '@id' }, {
get: { method: 'GET' }
});
function listItems() {
return [];
}
return {
list: listItems
};
}
module.factory('myService', myServiceFactory);
})();
The test code is:
'use strict';
describe('My service test', function () {
var myServiceFactory, campaign, $injector;
beforeEach(module('first.module'));
beforeEach(inject(function (_$injector_) {
$injector = _$injector_;
myServiceFactory = $injector.get('myService');
}));
it('true is true', function () {
expect(true).toEqual(true);
});
});
Karma is being used for the tests. Thanks for any help.
Upvotes: 0
Views: 758
Reputation: 1525
You should add ngResource
module into your module dependencies.
var module = angular.module('first.module', ['ngResource']);
Upvotes: 1