业力宣言例外

时间:2014-05-14 01:28:45

标签: angularjs karma-runner

我似乎无法开始业力。虽然它试图加载服务但它失败了。这是规范文件:

describe('Service: angelloModel', function () {

    beforeEach(module('Angello'));

    var modelService;

    beforeEach(inject(function (angelloModel) {
        modelService = angelloModel;
    }));

    describe('#getStatuses', function () {
       it('should return seven different statuses', function () {
          expect(modelService.getStatuses().length).toBe(7);
        });
     })
});

要使用的文件的karam配置部分:

    files: [
                'bower_components/angular/angular.js',
                 app.js',
                 'tests/*.spec.js'
            ],

最后是错误:

INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 34.0.1847 (Mac OS X 10.9.2)]: Connected on socket edWal-wdFxcFp1KPQndO with id 43277901
 Chrome 34.0.1847 (Mac OS X 10.9.2) Service: angelloModel encountered a declaration exception FAILED
    ReferenceError: module is not defined
        at null.<anonymous> (/Users/e002678/dev/Dropbox/angular/ng-inaction/tests/angelloModel.spec.js:3:16)
        at /Users/e002678/dev/Dropbox/angular/ng-inaction/tests/angelloModel.spec.js:1:1
Chrome 34.0.1847 (Mac OS X 10.9.2): Executed 1 of 1 (1 FAILED) ERROR (0.015 secs / 0.013 secs)

这里是服务定义:

myModule.factory('angelloModel', function () {
var getStatuses = function () {
    ...
};

var getTypes = function () {
  ...
};

var getStories = function () {
  ...
};

return {
  getStatuses: getStatuses,
  getTypes: getTypes,
  getStories: getStories
};

});

谢谢!

1 个答案:

答案 0 :(得分:10)

您需要在角度之后和测试文件之前在文件数组中包含angular-mocks.js

来自我的模板项目的

Here's an example config