Expected a spy, but got Function.

4,672 views
Skip to first unread message

ashok kumar

unread,
Jun 28, 2017, 12:00:46 PM6/28/17
to Jasmine

My service is

   
var testappserviceone = angular.module('testappserviceonemodule',[])

testappserviceone.factory('testappServiceone',[function(){
    return function (x,y) {

        function addobj (x,y){
            return x+y;
        }

        return{
            add:addobj
        }
    }
}]);


My service is

var testappserviceone = angular.module('testappserviceonemodule',[])

testappserviceone.factory('testappServiceone',[function(){
    return function (x,y) {

        function addobj (x,y){
            return x+y;
        }

        return{
            add:addobj
        }
    }
}]);

My test suite is

describe('testappserviceone add method functionality', function(){

    beforeEach(function () {
        spyOn(testappServiceone(10,15),'add').and.callThrough();
    });

    it('testappServiceone add method functionality', function() {
        testappServiceone(10,15).add();
        expect(testappServiceone(10,15).add).toHaveBeenCalled();
    });

});


The Exception I am getting is

 Error: <toHaveBeenCalled> : Expected a spy, but got Function.

Usage: expect(<spyObj>).toHaveBeenCalled()


Please help me to understand and solve this problem

Reply all
Reply to author
Forward
0 new messages