event testing fails to call event

8 views
Skip to first unread message

ioanna...@gmail.com

unread,
Feb 2, 2016, 2:39:27 PM2/2/16
to karma-users

I have the controller code:

 

$scope.$on('load', function (event) {

  $scope.getData();

  event.stopPropagation();

});


and the test code:


 it('$on load', function(event) {

        var controller=createController();

        spyOn(scope, 'getData').andCallThrough();

        spyOn(scope, "$on").andCallFake(function (event) {

            expect(event).toEqual("load");

        });

        scope.$broadcast('load',event);

        expect(scope.getData).toHaveBeenCalled();

        expect(scope.$on).toHaveBeenCalled();


 });


TypeError: event.stopPropagation is not a function

How can I define the event parameter in the call from the Unit test so that it won't fail?

Reply all
Reply to author
Forward
0 new messages