如何用角度解决业力中的以下错误

时间:2015-08-20 07:44:33

标签: angularjs karma-runner

我已执行以下行

expect($rootScope.$broadcast).toHaveBeenCalledWith("dateApply");

但我收到了以下错误

  

TypeError:'undefined'不是对象   (evaluating'c。$广播( “$ locationChangeStart”,B,A,K。$$状态中,f).defaultPrevented')

请帮我解决这个错误。

1 个答案:

答案 0 :(得分:0)

首先在顶部定义rootScope

然后将其注入beforeEach这样的

inject(function($injector) {
  rootScope = $injector.get('$rootScope');
});

然后在你的测试用例中

expect(rootScope.$broadcast).toHaveBeenCalledWith("dateApply");

如果您正在进行缩小,请确保未重命名rootScope。

相关问题