TypeError:无法读取属性' expectGET' $ httpBackend的未定义

时间:2016-06-15 17:58:54

标签: javascript angularjs testing ionic-framework karma-jasmine

我收到了一些不同的错误。其中一个是标题中列出的那个。 此失败是针对使用Karma编写的TEST文件。

我假设问题与$ httpBackend没有在某处注册有关。我正在使用IONIC,Angular和Rails构建应用程序。

我已尝试在_$httpBackend_中使用$httpBackend语法和beforeEach(inject(function())语法,但我仍然遇到同样的错误。

以下是完整错误:

BillService
    ✗ fetches a list of Bills
    Error: [$injector:modulerr] Failed to instantiate module starter due to:
    Error: [$injector:modulerr] Failed to instantiate module ionic due to:
    Error: [$injector:nomod] Module 'ionic' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
    http://errors.angularjs.org/1.5.3/$injector/nomod?p0=ionic
        at /Users/knowerlittle/Dropbox/Projects/splitter-frontend/www/lib/ionic/js/angular/angular.js:68:12

    TypeError: Cannot read property 'expectGET' of undefined
        at Object.<anonymous> (/Users/knowerlittle/Dropbox/Projects/splitter-frontend/test/unit/BillService.spec.js:15:16)   

以下是测试文件:

describe('BillService', function() {
  beforeEach(module('starter'));

  var billService, httpBackend;

  var billData = [{event: "Party"}, {event: "Birthday"}];

  beforeEach(inject(function(_billService_, _$httpBackend_) {
    billService = _billService_;
    httpBackend = _$httpBackend_;
  }));

  it('fetches a list of Bills', function(){

    httpBackend.expectGET("http://localhost:3000/bills/").respond(billData);

    var bill1 = { event: "Party"};
    var bill2 = { event: "Birthday"};

    billService.getAll().then(function(bills) {
      expect(bills).toEqual([bill1, bill2]);
    });
    httpBackend.flush();
  });
});

任何帮助都会很棒!提前谢谢。

0 个答案:

没有答案