Angular Jasmine单元测试:错误[$ injector:modulerr]

时间:2015-04-02 14:35:18

标签: angularjs jasmine

我要设置独立的茉莉花测试。我相信我已经正确设置了一切。当我进行第一次测试时:

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();
    }));

});

我收到此错误消息:错误:[$ injector:modulerr] http://errors.angularjs.org/1.3.11/ $ injector / modulerr?p0 = app .............

这是我的app模块配置。

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

这是我的控制器:

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

我使用的是Jasmine 2.2.0的独立版本。我不知道问题是什么,我所做的一切都是非常基本的东西。非常感谢任何帮助。

更新:这是我的SpecRunner.html的样子:

<!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>

1 个答案:

答案 0 :(得分:2)

看起来$injector无法找到您的某些依赖项。您确定包含控制器的脚本已正确加载吗?