Reputation: 6952
I'm trying to inject a service into my controllers unit test. I'm not looking to make a mock out of the service but just include it so that I can have access to all of its methods. Is this possible?
'use strict';
describe('Offers : controller', function(){
beforeEach(module('client'));
var $scope,
controller,
$rootScope,
genericService;
beforeEach(inject(function($injector, $controller) {
$rootScope = $injector.get('$rootScope');
controller = $controller('OffersCtrl', { $scope: $scope });
genericService = $injector.get('genericService');
$scope = $rootScope.$new();
}));
it('should have a genericService', function () {
expect(genericService.method).toBeDefined();
});
});
Upvotes: 1
Views: 1353
Reputation: 7926
Just inject your own service the same way you did with the angular services:
var genericService;
beforeEach(inject(function(_genericService_) {
genericService = _genericService_;
});
Note that you can use underscores around the argument name to avoid naming conflicts. Angular will strip those from the argument name when resolving the services to inject.
Upvotes: 2