I am trying to write a test to verify that a function is called when the page is loaded. I am trying to spyon it but its saying that it does not exist.
Could someone please give me some help on how to properly spy on it?
Here is the angular code:
(function () {
angular
    .module('uotc')
    .controller('reportGroupArchiveCtrl', ReportGroupArchiveCtrl);
ReportGroupArchiveCtrl.$inject = ['$scope', '$http', '$stateParams', '$q'];
function ReportGroupArchiveCtrl($scope, $http, $stateParams, $q) {
    $scope.reportType = $stateParams.reportType;
    $scope.templateTypeId = $stateParams.templateTypeId;
    $scope.group = $stateParams.group;
    //Initialize the page
    activate();
    function activate() {
        //Call the API to get the generated reports for this group
        $http.get('api/url/params....)
            .then(getGeneratedReportsComplete)
            .catch(apiCallFailed);
    }
    function getGeneratedReportsComplete(data, status, headers, config) {
        //do stuff
    };
    function apiCallFailed(e) {
        return null;
    }
}
})();
Here is the test:
describe('Controller', function () {
var stateparams, controller, scope;
beforeEach(angular.mock.module('uotc'));
beforeEach(angular.mock.inject(function (_$controller_, _$rootScope_) {
    stateparams = { reportType: 'Vendor', templateTypeId: 2, group: 'VENDOR_1' };
    scope = _$rootScope_.$new();
    controller = _$controller_('reportGroupArchiveCtrl',{
        $scope: scope,
        $stateParams:stateparams
    });
    spyOn(controller, 'getGeneratedReportsComplete')
}));
describe('is loaded', ()=> {
    beforeEach(inject(function($injector) {
        $httpBackend = $injector.get('$httpBackend');
        $httpBackend
            .when('GET', 'api/url/params)
            .respond(200, '123')
        $httpBackend.flush();
    }));
    it('calls the generated reports API', ()=> {
        expect(controller.getGeneratedReportsComplete()).toHaveBeenCalled();
    })
})
});