0
单元测试控制器我试图单元测试使用$ ionicView.enter这样
myControllers.controller('MyCtrl', [
'$scope',
function($scope) {
'use strict';
$scope.$on('$ionicView.enter', function(){
$scope.myValue = 1;
});
}]);
在我的单元测试控制器我可以窥视事件,并检查它已被调用,但它不会进入函数并设置$ scope.myValue。这是我的测试:
it('should do stuff', function() {
spyOn(scope, '$on').and.callThrough();
scope.$on('$ionicView.enter');
// this passes
expect(scope.$on).toHaveBeenCalledWith('$ionicView.enter')
// this fails - scope.myValue is undefined
expect(scope.myValue).toEqual(1);
});
我以为callThrough会调用我正在监视的功能,但似乎并没有在这里的代码。
任何帮助表示赞赏。
你能显示所有的代码吗? :) – jdnichollsc