How do I test $scope.$on in AngularJS

前端 未结 4 1368
Happy的楠姐
Happy的楠姐 2020-12-31 00:54

How do I test that the scope is populated after the broadcast? I\'ve searched and found a few QA\'s here in stackexchange, but none answered my problem. The code is working

4条回答
  •  抹茶落季
    2020-12-31 01:28

    As far as "toHavebeenCalled" concerned, there is no need of "andCallThrough()". Simple spy would work. In your case your arguments are different.

    You are broadcasting like, rootScope.$broadcast('updatecrappy', [{id : 2, name : 'crappy'}]);

    But you expect :

    expect(rootScope.$broadcast).toHaveBeenCalledWith('updscenes', [{id : 2, name : 'crappy'}]);

    look at argument " updarecrappy" but in tohavebeencalled it is "updscenes".

提交回复
热议问题