I am writing tests for a controller in Jasmine; the controller depends on the service I am inserting with beforeEach(inject). However, when I try to spy on a method in a service, I always get the following error:
spyOn could not find an object to spy upon for replacePod()
The code for my test is as follows:
describe('Controller: ResultsController', function () {
'use strict';
var ctrl;
var ResultsService;
var RouteService;
var PodService;
var $scope;
var httpMock;
var log;
beforeEach(module('waApp'));路
路路路路
beforeEach(inject(function(
$rootScope,
$log,
$controller,
$httpBackend,
ResultsService,
RouteService,
PodService
) {
$scope = $rootScope.$new();
log = $log;
log.reset();
httpMock = $httpBackend;
ctrl = $controller('ResultsController', {
$scope: $scope,
ResultsService: ResultsService,
RouteService: RouteService,
PodService: PodService
});
}));
it('processRecalculate should call PodService.replacePod', function() {
$scope.getResults({input:'kitten'});
spyOn(PodService, 'replacePod');
expect(PodService.replacePod).toHaveBeenCalled();
});
This gives the above error. Is there something wrong with my code, or is it just impossible to look into the method in the injected service?
source
share