As I followed the tutorial at , I encountered an issue with the jasmine test provided. Despite simplifying the test to its core, it still fails to pass. Could someone point out where I might be going wrong?
The service being tested is:
var appServices = angular.module('MyApp.services', ['$http', '$rootScope']);
appServices.factory('Auth', ['$http', '$rootScope', function ($http, $rootScope) {
var accessLevels = routingConfig.accessLevels,
userRoles = routingConfig.userRoles,
currentUser = { username: '', role: userRoles.public };
function changeUser(user) {
angular.extend(currentUser, user);
}
return {
authorize: function (accessLevel, role) {
if (role === undefined) {
role = currentUser.role;
}
return accessLevel.bitMask & role.bitMask;
},
isLoggedIn: function (user) {
if (user === undefined) {
user = currentUser;
}
return user.role.title === userRoles.user.title;
},
login: function (user, success, error) {
user.role = userRoles.user;
changeUser(user);
$rootScope.$broadcast('login');
success(user);
},
logout: function (success, error) {
changeUser({
username: '',
password: '',
role: userRoles.public
});
success();
},
accessLevels: accessLevels,
userRoles: userRoles,
user: currentUser
};
}]);
The jasmine test case is as follows:
describe('services tests', function () {
beforeEach(function () {
module('MyApp.services');
inject(function (_Auth_, $httpBackend) {
Auth = _Auth_;
httpBackend = $httpBackend;
});
});
it('should have an authorize function', function () {
expect(angular.isFunction(Auth.authorize)).toBe(true);
});
});
The resulting error message is:
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
...