Using $ injector in AngularJS when testing integration (without using ngMock)
I need to set up some integration tests in AngularJS using Karma / Jasmine, but you're in trouble because when you don't use ngMock (since I want to hit the actual $ http endpoints), there are no module
or inject
methods.
So how do I add services to my tests?
I've tried angular.injector.invoke(...)
but can't get it to work, it always returns with an error, eg Unknown provider: AuthServiceProvider <- AuthService
.
Thoughts?
+3
source to share
1 answer
try it
'use strict';
describe('Login User', function () {
var app, LoginService;
beforeEach(module('app')) ;
beforeEach(inject(function(_LoginService_) {
LoginService = _LoginService_;
})) ;
it('Should be logged in', function () {
var isLoggedIn = LoginService.isUserLoggedIn();
expect(isLoggedIn).toBeTruthy();
});
});
+2
source to share