AngularJS Jasmine Test Fails: Failed to instantiate module

My angular app worked great and so did my tests, using karma and jasmine, until I added a dependency in ui.bootstrap. Now the app still works as expected, but I can’t get my tests to run. This is what I have:

app.js – added dependency in ui.bootstrap

angular.module('myApp', ['ngResource', 'ngRoute', 'ui.bootstrap']).config(function(...) {...});


angular.module('myApp').service('myService', function () {})


angular.module('myApp').controller('MyController', function ($scope, $http, myService) {})


describe('Controller: MyController', function () {
    var MyController, scope;
    // load the controller's module
        inject(function ($controller, $rootScope) {
            scope = $rootScope.$new();
            MyController = $controller('MyController', {
    it('should do something', function () {

And my test, which I run using grunt and krama, fails due to:

Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module ui.bootstrap due to:
Error: [$injector:nomod] Module 'ui.bootstrap' is not available! You either misspelled the module name or forgot

What have I missed? The app runs with no problem, only the test fails.

In karma.conf.js there is a list of files that karma loads before test execution:

// list of files / patterns to load in the browser
files: [

Add bootstrap-ui.js there.

Inject your dependencies


I had the same problem. Just solved it. Somehow putting the module(myApp); function call inside a the function you provide to beforeEach() doesn’t work just try this:

Extract the module call into its own beforeEach():


And use another beforeEach() for the function you use.

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Saving a Uint8Array to a binary file

Similar Posts