I have a simple unit test I am trying to write. I simply need to test if my function was called. In my service I have a simple method that calls another method like so
svc.getNewestNotifications = function getNewestNotifications() {
getNewNotifications(username);
};
in my test:
describe('notification service tests', function () {
var $rootScope, $http, $q, notificationSvc, $httpBackend;
beforeEach(module('myApp'));
beforeEach(inject(function(_$rootScope_,_$http_,_$httpBackend_,_$q_,_$sce_,_notificationsFeedService_){
$rootScope = _$rootScope_;
$httpBackend = _$httpBackend_;
$http = _$http_;
$q = _$q_;
notificationSvc = _notificationsFeedService_;
_scope_ = $rootScope.$new();
$scope = _scope_;
$httpBackend.whenGET(/\.html$/).respond('');
}));
describe("getNewestNotifications test", function() {
it('calls the getNewestNotifications when scroll to top', function() {
spyOn(notificationSvc, 'getNewestNotifications').and.callThrough();
expect(notificationSvc.getNewestNotifications).toHaveBeenCalled();
});
});
}
Its the " describe("getNewestNotifications test", function() {} " block that is my issue. I get "Expected spy getNewestNotifications to have been called." in the console. I am very new to unit testing in general and I am at a complete loss as to why I am seeing this i am simply trying to test that the method was indeed called. Any help?
Aucun commentaire:
Enregistrer un commentaire