Unfortunately, this is how code coverage is evaluated. If the code is executed, it is considered to be "covered". Luckily, there is something you can do to reduce some of the false positives. You can mock out your dependencies!
The following example will execute a jasmine spy instead of the actual service:
describe('Controller Tests', function() {
var $scope, mockServiceA;
beforeEach(module('app', function($provide) {
mockServiceA = jasmine.createSpyObj('mockServiceA', ['foo']);
$provide.value('ServiceA', mockServiceA);
}));
beforeEach(inject(function($rootScope, $controller) {
$scope = $rootScope.$new();
$controller('ControllerB', {
$scope: $scope
});
}));
describe('ControllerB', function() {
it('should call mock service', function() {
expect(mockServiceA.foo).not.toHaveBeenCalled();
$scope.useServiceA();
expect(mockServiceA.foo).toHaveBeenCalled();
});
});
});
Here is a working Plunker: http://plnkr.co/edit/x8gQQNsHT0R5n5iJSxKw?p=info