Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度服务jasmine测试can';找不到$http_Javascript_Angularjs_Service_Jasmine - Fatal编程技术网

Javascript 角度服务jasmine测试can';找不到$http

Javascript 角度服务jasmine测试can';找不到$http,javascript,angularjs,service,jasmine,Javascript,Angularjs,Service,Jasmine,按照这里的教程:下面的jasmine测试应该可以工作——但是不行。我已将测试简化为最简单的测试。与我链接的示例测试不同,我无法通过此测试。知道我做错了什么吗 正在测试的服务: var-appServices=angular.module('MyApp.services',['$http','$rootScope']); appServices.factory('Auth',['$http','$rootScope',函数($http,$rootScope){ var accessLevels=r

按照这里的教程:下面的jasmine测试应该可以工作——但是不行。我已将测试简化为最简单的测试。与我链接的示例测试不同,我无法通过此测试。知道我做错了什么吗

正在测试的服务:

var-appServices=angular.module('MyApp.services',['$http','$rootScope']);
appServices.factory('Auth',['$http','$rootScope',函数($http,$rootScope){
var accessLevels=routingConfig.accessLevels,
userRoles=routingConfig.userRoles,
currentUser={username:'',角色:userRoles.public};
函数更改用户(用户){
角度扩展(当前用户,用户);
}
返回{
授权:功能(访问级别、角色){
如果(角色===未定义){
role=currentUser.role;
}
返回accessLevel.bitMask和role.bitMask;
},
isLoggedIn:函数(用户){
如果(用户===未定义){
用户=当前用户;
}
返回user.role.title==userRoles.user.title;
},
登录:函数(用户、成功、错误){//ignore jslint
user.role=userRoles.user;
变更用户(用户);
$rootScope.$broadcast('login');
成功(用户);
},
注销:函数(成功,错误){//ignore jslint
变更用户({
用户名:“”,
密码:“”,
角色:userRoles.public
});
成功();
},
访问级别:访问级别,
userRoles:userRoles,
用户:当前用户
};
}]);
测试:

description('services tests',function(){
beforeach(函数(){
模块(“MyApp.services”);
//获取您的服务,同时获取$httpBackend
//由于angular-mocks.js,$httpBackend将是一个模拟
注入(函数(_Auth,$httpBackend){
Auth=_Auth;
httpBackend=$httpBackend;
});
});
它('应该有一个授权函数',函数(){
expect(angular.isFunction(Auth.authorize)).toBe(true);
});
});
错误消息:

Error: [$injector:modulerr] Failed to instantiate module MyApp.services due to:
Error: [$injector:modulerr] Failed to instantiate module $http due to:
Error: [$injector:nomod] Module '$http' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.13/$injector/nomod?p0=%24http
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:78:12
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:1531:17
    at ensure (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:1456:38)
    at module (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:1529:14)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:3632:22
    at Array.forEach (native)
    at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:304:11)
    at loadModules (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:3626:5)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:3633:40
    at Array.forEach (native)
http://errors.angularjs.org/1.2.13/    

var-appServices=angular.module('MyApp.services',['$http','$rootScope'])

应该是


var-appServices=angular.module('MyApp.services',[])


$http
$rootScope
不是模块,因此错误是
appServices
找不到
$http
模块。

var-appServices=angular.module('MyApp.services',['http','$rootScope')

应该是


var-appServices=angular.module('MyApp.services',[])

$http
$rootScope
不是模块,因此错误是
appServices
找不到
$http
模块