lundi 3 juillet 2017

Creating a spy on service not working

My target service is

var app = angular.module('testapp');
  app.factory('testAppServiceOne', function () {
         return function (count, page) {
               this.count = 0;
               this.currentPage = page;
          };
  });

My current service is

var app = angular.module('testapp');
  app.factory('testAppService', function () {
         return function (count, currentPage) {
                     var getPageModel = function(){
                           return new testAppServiceOne(count, currentPage);
                     }
                      return {
                          getPageModel: getPageModel
                      };
          };
  });

I am unit testing 'testAppService().getPageModel()' method and my test case is as follows

describe('testAppService getPageModel method functionality -->', function(){
    var windowobj,testAppServiceObj;
    beforeEach(function (done) {
        testAppServiceObj = testAppService();
        spyOn(testAppServiceObj,'getPageModel').and.callThrough();
        windowobj = jasmine.getGlobal();
        spyOn(windowobj, testAppServiceOne);
        testAppServiceObj.getPageModel();
        done();
    });
    it('method should return testAppServiceOne object', function(){
        expect(windowobj.testAppServiceOne).toHaveBeenCalled();
    });

});

The exception I am getting is

Error: <spyOn> : function (count,page)
   {__cov_yZntKTPynIMLK8OsQyDl5w.f['63']++;__cov_yZntKTPynIMLK8OsQyDl5w.s['145']++; 
   this.count=0; 
   __cov_yZntKTPynIMLK8OsQyDl5w.s['146']++; 
   this.currentPage=page;}() method does not exist

Please help in understanding and solving this issue.

Aucun commentaire:

Enregistrer un commentaire