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