This might be a question more for Karma or Angular, but I’m wondering how to use the Loopback-generated Angular services in my tests. I don’t need to test the services themselves, but I need to test controllers that rely on those services, but they’re not using a typical promise set up. I usually test promise-based services like this (in Karma):
var deferred = $q.defer();
$rootScope.currentUser = null;
spyOn(User, 'login').andReturn(deferred.promise);
scope.doLogin();
expect(User.login).toHaveBeenCalled();
deferred.resolve();
$rootScope.$digest();
expect($rootScope.currentUser).not.toBeNull();
But if User.login() comes from LoopBack, which structures its promises like User.login().$promise.then() instead of User.login().then(), I get this error:
TypeError: 'undefined' is not an object (evaluating 'User.login({ email: user.email, password: user.password }).$promise.then')
I'm relatively new to Angular testing, so I may be missing something obvious.
Aucun commentaire:
Enregistrer un commentaire