jeudi 30 avril 2015

My Karma spy is not picking up on my controller function

My spec:

describe('ScheduleController', function() {
    var ScheduleController, scope, spies = {};

    beforeEach(function() {
      module('mapApp');

      return inject(function($injector) {
        var $controller, $rootScope;
        $rootScope = $injector.get('$rootScope');
        $controller = $injector.get('$controller');

        scope = $rootScope.$new()

        $controller('ScheduleController', {
            $scope: scope
        });

        spies.buildScheduleUrl = spyOn(scope, 'buildScheduleUrl').and.callThrough();
      });
    });

    it('should build a schedule url', function() {
        expect(spies.buildScheduleUrl).toHaveBeenCalled();
    });
});

My controller:

window.map.controller('ScheduleController', ['$scope', '$window', 'cache', 'scheduleCache', 'dosingCache', 'patientCache', '$modal', 'util',
    function ($scope, $window, cache, scheduleCache, dosingCache, patientCache, $modal, util) {
        // other stuff here


        $scope.buildScheduleUrl();

    }

]);

So my buildScheduleUrl function does not get called it seems. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire