Reputation: 9224
I have the following code in my spec file
beforeEach(function () {
module('app');
inject(function ($injector) {
user = $injector.get('app.user');
});
});
user
is undefined, and isn't being injected. So I want to make sure that the app
module actually loaded.
Upvotes: 0
Views: 461
Reputation: 222493
If the module is not loaded, you get $injector:nomod
error. If the module is loaded but the service cannot be found, you get $injector:unpr
error. It is as easy as that. There is always a breadcrumb trail, no need to probe Angular to know if it fails silently or not.
Upvotes: 1
Reputation: 689
Just make sure you're using the right module name. You can use beforeEach
to load your module. Also, with $injector
you can get an instance of your service or controller you're trying to test:
'use strict';
describe('MyControllerName', function () {
var MyControllerName;
beforeEach(module('myAppMomduleName'));
beforeEach(inject(function ($injector) {
MyControllerName = $injector.get('MyControllerName');
}));
it('should create an instance of the controller', function () {
expect(MyControllerName).toBeDefined();
});
});
Upvotes: 0