Can anyone help me find a way to use both beforeEach(module()) and beforeEach(inject()) in the main describe() of my unit test?
When I include both
beforeEach(module('ngRoute'));
and
beforeEach(inject(function () {}));
in the main describe() of my test file, I get this error. But, If I remove the beforeEach(inject () {})) code, then ngRoute is properly loaded by karma.
I have checked many other posts related to this issue. Such as:
- Error: No module: ngRoute when trying to implement routing in angularjs
- AngularJS 1.2 $injector:modulerr
- AngularJS 1.2 ngRoute unit test error
As suggested by each of the above questions, I have made sure that angular-routes.js is included in my index.html and I have also made sure that 'ngRoute' is a dependency of my app.
test file :
define(['ngMock', 'controllers/home/main-home-ctrl'], function () {
'use strict';
describe.only('Controller: MainHomeController', function () {
beforeEach(module('ngRoute'));
beforeEach(inject(function () {}));
afterEach(function() {
});
describe('', function () {
it('should ', function () {
});
});
});
});
karma.config.js :
files: [
{pattern : 'www/js/bootstrap.js', included : false },
{pattern : 'www/js/lib/*.js', included : false },
{pattern : 'www/js/controllers/*.js', included : false },
{pattern : 'www/js/controllers/**/*.js', included : false },
{pattern : 'www/js/directives/*.js', included : false },
{pattern : 'www/js/directives/**/*.js', included : false },
{pattern : 'www/js/factories/*.js', included : false },
{pattern : 'www/js/factories/**/*.js', included : false },
{pattern : 'www/js/filters/*.js', included : false },
{pattern : 'www/js/filters/**/*.js', included : false },
{pattern : 'www/js/services/*.js', included : false },
{pattern : 'www/js/services/**/*.js', included : false },
{pattern : 'www-test/lib/*.js', included : false },
{pattern : 'www-test/spec/**/*.js', included : false },
{pattern : 'www-test/spec/**/**/*.js', included : false },
'www-test/main-test.js',
'www/js/lib/angular-route.js'
],
angular-routes.js is located at 'www/js/lib/angular-routes.js' and therefore should be included when karma runs my unit tests.
app.js :
define([
'angular',
'angular-route',
'controllers/index',
'directives/index',
'factories/index',
'filters/index',
'services/index'
], function (ng) {
'use strict';
return ng.module('app', ['ngRoute', 'app.controllers', 'app.directives', 'app.factories', 'app.filters', 'app.services']);
});