找不到Angular JS Karma模块

时间:2014-01-11 07:01:26

标签: javascript angularjs jasmine karma-runner

我收到错误消息 - " ReferenceError:模块未定义"当试图测试角js代码。

测试脚本[testSpec.js]

describe('Project controllers', function() {
beforeEach(module('project')); 
describe('ListCtrl', function() {
    expect(1).toBe(1);
});
});

我的html文件中有以下条目

<script src="angular.min.js"></script>
<script src="angular-resource.min.js"></script>
<script src="angular-mocks.js"></script>

然后是我的测试脚本 - testSpec.js

我再次特别包括angular.js和angular-mocks.js。我看到以下错误消息

Chrome 31.0.1650 (Windows 7) Project controllers ListCtrl should create 11 records FAILED
    TypeError: Object #<Object> has no method 'apply'
    Error: Unknown provider: ProjectsProvider <- Projects
        at Error (<anonymous>)
        at c:/Angular/angular-phonecat/app/angular.min.js:30:24
        at Object.c [as get] (c:/Angular/angular-phonecat/app/angular.min.js:27:310)
        at c:/Angular/angular-phonecat/app/angular.min.js:30:109
        at c (c:/Angular/angular-phonecat/app/angular.min.js:27:310)
        at d (c:/Angular/angular-phonecat/app/angular.min.js:27:444)
        at Object.instantiate (c:/Angular/angular-phonecat/app/angular.min.js:29:80)
        at c:/Angular/angular-phonecat/app/angular.min.js:53:80
        at null.<anonymous> (c:/Angular/angular-phonecat/app/testSpec.js:10:12)
        at Object.d [as invoke] (c:/Angular/angular-phonecat/app/angular.min.js:28:464)
    Error: Declaration Location
        at window.jasmine.window.inject.angular.mock.inject (c:/Angular/angular-phonecat/app/angular-mocks.js:1781:2

这是完整的错误

5) at null.<anonymous> (c:/Angular/angular-phonecat/app/testSpec.js:8:34)\n
   at null.<anonymous> (c:/Angular/angular-phonecat/app/testSpec.js:6:2)\n
   at c:/Angular/angular-phonecat/app/testSpec.js:2:1

Chrome 31.0.1650 (Windows 7) Project controllers ListCtrl should contain new fields FAILED
    TypeError: Object #<Object> has no method 'apply'
    Error: Unknown provider: ProjectsProvider <- Projects

2 个答案:

答案 0 :(得分:0)

我怀疑你在karma配置文件中遗漏了一些包含文件。具体来说,请确保加载angular.js。

答案 1 :(得分:0)

您是否包含 angular-mocks.js ? 那应该可以解决你的问题。 你需要它才能发挥作用。