【发布时间】:2017-08-09 02:09:24
【问题描述】:
在这个指令中,我想测试以下内容:
$scope.$on('loggedMsg', function(){
if($scope.users.length){
$scope.callingFn();
}
});
我能够发出loggedMsg 和$scope.apply(),它将调用$scope.callingFn()。有没有办法不实际调用 $scope.callingFn,而只是监视它?我正在使用 mocha 和 sinon 来编写这些单元测试。我的建议可行吗?
describe('testing directive', function(){
const elemScope = element.isolateScope;
it('should trigger callingFn if loggedMsg is emitted', function(){
scope.$emit('loggedMsg');
scope.$apply();
//elemScope.callingFn will be called due to the apply. Is there a way to just spy on that fn being called?
}
});
【问题讨论】:
标签: angularjs unit-testing mocha.js sinon