我有一个具有1个依赖关系的控制器,它是一个名为constantData的常量:
$scope.selectInputs = {
states: constantData().statesTerritories()
};
constantData类似于:
.constant('constantData', function(){
return {
statesTerritories: function(){
return [
{ name:'NSW' },
{ name:'ACT' },
{ name:'VIC' },
{ name:'QLD' },
{ name:'WA' },
{ name:'SA' },
{ name:'TAS' },
{ name:'NT' }
];
},
在我的单元测试中,我有:
constantData = {statesTerritories: function () {
}};
spyOn(constantData, 'statesTerritories').andReturn(
function () {
return [
{ name:'NSW' },
{ name:'ACT' },
{ name:'VIC' }
];
}
);
但是我得到业力的错误是:
TypeError: '[object Object]' is not a function (evaluating 'constantData()')
我如何在测试中模拟这个常量?