0

该应用程序与我的模块一起正常工作。但是构建以下模拟返回:

$global_vars is not defined

我想我没有正确注入模块。我在这里想念什么?

describe('CalendarController', function() {
  beforeEach(module("$global_vars"));
  beforeEach(inject(function($rootScope, $controller, $location, $injector, $global_vars) {
    var $httpBackend;
    $httpBackend = $injector.get('$httpBackend');
    return this.controller = $controller(CalendarController, {
      $scope: this.scope,
      $location: $location,
      $global_vars: $global_vars
    });
  }));
  return it("can be instantiated", function() {
    return expect($global_vars).not.toBeNull();
  });
});

注意:这是对 vanilla js 的咖啡脚本翻译

更新

好的,这样做我得到另一个可能更好的错误?

Error: Unknown provider: $httpProvider <- $http <- $global_vars

.

describe 'CalendarController', ->

  beforeEach module("$global_vars")
  beforeEach module("GlobalService")
  beforeEach inject ($rootScope, $controller, $location, $injector) ->
    $injector = angular.injector [ '$global_vars' ]
    $global_vars = $injector.get('$global_vars')

    $global_vars = $injector.get('$global_vars')
    @controller = $controller CalendarController, {$scope: @scope, $location: $location}

我的backbone.js 的骨架

angular.module("VarsService", []).factory "$global_vars", ["$http", '$location', ($http, $location) ->  
  global_vars.get_calendar = ->
     console.log 'blam!'
4

0 回答 0