【发布时间】:2015-09-27 12:25:20
【问题描述】:
我有以下只有私有功能的控制器。我正在努力测试这个控制器。我应该测试它是否正在执行 $emit,因为 ImageService 已经过测试?在这种情况下如何测试 $emit ?或者我应该测试它是否正在调用 ImageService.fetchImageStacks 方法?这种情况下如何触发init函数?
(function (angular, global, undefined) {
'use strict';
var ImageController = {};
ImageController.$inject = [
'$rootScope',
'$log',
'ImageService'
];
ImageController = function (
$rootScope,
$log,
ImageService
) {
var getImageStacks = function() {
ImageService
.fetchImageStacks()
.success(function (result) {
ImageService.setImageStacks(result);
$rootScope.$emit('rootScope:imageStacksUpdated', result);
})
.error(function (){
$log.error('Failed to get imageStackInfo file.');
});
};
var init = function () {
getImageStacks();
};
init();
return {
getImageStacks: getImageStacks
};
}
angular.module('myApp')
.controller('ImageController', ImageController);
})(angular, this);
【问题讨论】: