我有一個控制器內該功能:茉莉花類型錯誤:未定義是不是構造
$scope.delt = function() {
$scope.data = {};
$scope.confirmPopup = $ionicPopup.confirm({
title: '<b>Delete user</b>',
template: "Are you sure you want to delete this user ?<br>can't be undo."
}).then(function(res) {
if (res) {
API.editeTheUser.delete({ id: $scope.user.id }, function(res, header) {
$scope.addEvent('delete-user', 'Delete the user with phone_number :' + $scope.user.phone);
$rootScope.popup('delete', "delete was success");
$ionicHistory.goBack();
}, function(err) {
$rootScope.popup("Error", err.data.error);
});
} else {
console.log('You are not sure');
}
});
}
,當我只需要調用這個函數在我的單元測試:
describe('manageUserCtrl', function() {
var controller, window, scope,
$rootScope,
$q, store, API, $ionicPopup, deferredLogup;
beforeEach(inject(function($controller, _$ionicPopup_, _$rootScope_, $q, _API_, _$window_) {
$q = $q;;
$ionicPopup = _$ionicPopup_;
deferredLogup = $q.defer();
$rootScope = _$rootScope_;
spyOn($ionicPopup, 'confirm');
scope = $rootScope.$new();
API = _API_;
window = _$window_;
controller = $controller('manageUserCtrl', {
'$scope': scope,
'API': API,
'$window': window,
'$ionicPopup': $ionicPopup
});
}));
it('expect delete', function() {
scope.delt();
});
});
然後我得到了錯誤
「類型錯誤:未定義不是構造函數(近 '......}),然後(函數(RES))({...')」
。 這裏有什麼錯誤,我是單元測試新手? p.s.代碼運行良好。
@jlogan請問,你能幫忙嗎? –