Joseph Freeman
Joseph Freeman

Reputation: 1784

Angular Jasmine Unit Testing: error [$injector:modulerr]

I'm to setup standalone jasmine testing. I believe I have everything setup correctly. When I run my first test:

describe('Logon Controller', function() {
    var controller, $scope;

    beforeEach(module("app"));

    //beforeEach(inject(function ($rootScope, $controller) {
    //    scope = $rootScope.$new();
    //    contoller = $controller('logonCtrl', {
    //        $scope: scope
    //    });
    //}));

    beforeEach(inject(function ($rootScope) { 
        scope = $rootScope.$new();
    }));

    //it('should say hello', function ($controller, $rootScope) {
    //    //var scope = $rootScope.$new();
    //    var controller = $controller('logonCtrl', { $scope: $scope });
    //    //expect(angular.isFunction(scope.get)).toEqual("Hello There :)");
    //    expect(scope.Hello()).toEqual("Hello There :)");
    //    expect($scope.Hello).toBeDefined();
    //});

    it('should say hello', inject(function ($controller, $rootScope) {
        //var scope = $rootScope.$new();
        var controller = $controller('logonCtrl', {$scope: $scope});
        //expect(angular.isFunction(scope.get)).toEqual("Hello There :)");
        //expect(scope.Hello()).toEqual("Hello There :)");
        expect($scope.Hello).toBeDefined();
    }));

});

I get this error message: Error: [$injector:modulerr] http://errors.angularjs.org/1.3.11/$injector/modulerr?p0=app.............

Here is my app module config.

var app = angular.module('app', ['ui.router','ngMaterial']);

Here is my controller:

app.controller('logonCtrl', ['$scope', '$state', '$interval', function ($scope, $state, $interval) {
  $scope.hello = function() {};
});
]);

I am using the standalone version of Jasmine 2.2.0. I have no clue what the issue could be, everything I have done is pretty basic stuff. Any help would be very much appreciated.

UPDATE: here is what my SpecRunner.html looks like:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Jasmine Spec Runner v2.2.0</title>

  <link rel="shortcut icon" type="image/png" href="JasmineUnitTest/lib/jasmine-2.2.0/jasmine_favicon.png">
  <link rel="stylesheet" href="JasmineUnitTest/lib/jasmine-2.2.0/jasmine.css">

  <script type="text/javascript" src="JasmineUnitTest/lib/jasmine-2.2.0/jasmine.js"></script>
  <script type="text/javascript" src="JasmineUnitTest/lib/jasmine-2.2.0/jasmine-html.js"></script>
  <script type="text/javascript" src="JasmineUnitTest/lib/jasmine-2.2.0/boot.js"></script>
  <script type="text/javascript" src="JasmineUnitTest/lib/jasmine-2.2.0/angular.min.js"></script>
  <script type="text/javascript" src="JasmineUnitTest/lib/jasmine-2.2.0/angular-mocks.js"></script>

  <!-- include source files here... -->
  <script type="text/javascript" src="js/controllers/logonCtrl.js"></script>      

  <!-- include spec files here... -->
  <script type="text/javascript" src="JasmineUnitTest/specs/logonController-spec.js"></script>
    
</head>

<body>
</body>
</html>

Upvotes: 3

Views: 2797

Answers (1)

Timoth&#233;e Jeannin
Timoth&#233;e Jeannin

Reputation: 9912

It looks like the $injector fails to find some of your dependencies. Are you sure the script containing your controller is properly loaded ?

Upvotes: 2

Related Questions