我只是想让 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)
这是 中的函数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;
});
我想我只是在我的业力配置中要求文件顺序错误。这是我的文件结构:
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'
],
app_testable.js
是我的应用程序的精简版本,除了 angular 之外没有任何依赖项。这是我的测试。我只是想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);
});
});
我需要如何设置 karma 才能正确运行测试?