Hello,
I have a little problem with unit test.
I get an error : TypeError: Cannot call method 'success' of undefined
my *service *:
'use strict';
angular.module('regiePub')
.factory('Auth', ['$http', '$rootScope', function ($http, $rootScope) {
//we assign user to the variable $rootscope
function changeUser(user) {
$rootScope.user = user;
}
*return *{
*authentification*:* function (*userG, success, error*)* {
$http.get('data/login.json', userG)
*.success*(function (user) {
if(userG.login === user.login && userG.password ===
user.password){
changeUser(user);
success(user);
}else{
error("Invalid login !");
}
})
*.error*(function(){
console.log("Error");
});
}
};
}]);
my *test *:
'use strict';
describe('Service : Auth', function() {
*beforeEach*(module('regiePub'));
var $httpBackend;
var scope;
var myFactory;
var success = 'yes';
var error = 'error';
var user = {};
user.login = 'james';
user.password = '007';
user.token = '385aet';
beforeEach(inject(function (_$httpBackend_,$rootScope,Auth) {
$httpBackend = _$httpBackend_;
scope = $rootScope.$new();
myFactory = Auth;
$httpBackend.expectGET('data/login.json').respond(200,user);
}));
* it*('we need to get information 's authentication', function() {
//make the call
*myFactory.authentification*(user,success,error)
*.success*(function(user){
myFactory.changeUser(user);
success(user);
});
$httpBackend.flush();
expect(success).toEqual(user);
});
});
Thanks for your help :)
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.