设置Jasmine和Karma来测试Angular

nic*_*tme 1 javascript angularjs karma-runner

我只是想让Karma设置为使用Jasmine测试我的Angular应用程序.我收到这个错误:

INFO [karma]: Karma v0.10.4 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 30.0.1599 (Mac OS X 10.9.0)]: Connected on socket pxDaOUXMfGXOVL7ZOuPb
Chrome 30.0.1599 (Mac OS X 10.9.0) ItemCtrl should work FAILED
    TypeError: Object [object Object] has no method 'off'
        at null.<anonymous> (/Users/macbookpro/Sites/groceries/spec/angular-mocks.js:1917:36)
Run Code Online (Sandbox Code Playgroud)

这是以下功能angular-mocks.js:

afterEach(function() {
    var injector = currentSpec.$injector;

    currentSpec.$injector = null;
    currentSpec.$modules = null;
    currentSpec = null;

    if (injector) {
      injector.get('$rootElement').off();
      injector.get('$browser').pollFns.length = 0;
    }

    angular.mock.clearDataCache();

    // clean up jquery's fragment cache
    angular.forEach(angular.element.fragments, function(val, key) {
      delete angular.element.fragments[key];
    });

    MockXhr.$$lastInstance = null;

    angular.forEach(angular.callbacks, function(val, key) {
      delete angular.callbacks[key];
    });
    angular.callbacks.counter = 0;
  });
Run Code Online (Sandbox Code Playgroud)

我想我只是在我的业力配置中要求错误顺序的文件.这是我的文件结构:

karama.config.js/spec它所需的文件位于同一目录中:

// list of files / patterns to load in the browser
    files: [
      'angular.min.js',
      'angular-mocks.js',
      'app_testable.js',
      'app_spec.js'
    ],
Run Code Online (Sandbox Code Playgroud)

app_testable.js是我的应用程序的精简版本,没有除角度以外的依赖项.这是我的考试.我只是想true成为true.

'use strict';

describe('ItemCtrl', function(){
  var scope;
  beforeEach(angular.mock.module('Grocerease'));
  beforeEach(angular.mock.inject(function($rootScope, $controller){
      scope = $rootScope.$new();
      $controller('ItemCtrl', {$scope: scope});
    })
  );

  it('should work', function(){
    expect(true).toBe(true);
  });

});
Run Code Online (Sandbox Code Playgroud)

我如何设置业力以便能够正确运行测试?

dim*_*irc 5

问题似乎是依赖项被错误加载.

你正在使用什么版本的角度?'angular'和'angular-mocks'文件应该是相同的版本.