mardi 27 octobre 2015

SpyOn returns Expected a spy, but got Function

I am testing a controller that calls a service(through the goToPage function) in order to redirect using the spyOn. It's simple but I am getting "Expected a spy, but got Function." error. What am I doing wrong? This is my Spec:

var createController,service scope;
beforeEach(inject(function($rootScope, $controller,$injector){
    service = $injector.get('service ');
    scope = $rootScope.$new();
    createController = function() {
        return $controller('controller', {
            '$scope': scope
        });
        spyOn(service , ['redirect']).andCallThrough();
    };
}));

describe('test if service is called', function() {
    it('should call the service', function() {
        var controller=createController();
        scope.goToPage();
        expect(service.redirect).toHaveBeenCalled();
    });
});

});

Aucun commentaire:

Enregistrer un commentaire