Angularjs 执行业力测试时出错

Angularjs 执行业力测试时出错,angularjs,unit-testing,gruntjs,jasmine,karma-runner,Angularjs,Unit Testing,Gruntjs,Jasmine,Karma Runner,我正在尝试为我的应用程序运行karma单元测试。该应用程序是使用我公司的自定义角度生成器创建的。(发电机非常类似于角形耶曼发电机) 我正在尝试为我的应用程序运行karma jasmine测试。但是每当我运行grunt测试时,我总是收到错误消息 Chrome 35.0.1916(Mac OS X 10.9.0)错误未捕获对象位于 /用户//虚拟 Apps/karma1/app/bower_components/angular/angular.js:1611 警告:任务“因果报应:单位”失败。使用-

我正在尝试为我的应用程序运行karma单元测试。该应用程序是使用我公司的自定义角度生成器创建的。(发电机非常类似于角形耶曼发电机)

我正在尝试为我的应用程序运行karma jasmine测试。但是每当我运行grunt测试时,我总是收到错误消息

Chrome 35.0.1916(Mac OS X 10.9.0)错误未捕获对象位于 /用户//虚拟 Apps/karma1/app/bower_components/angular/angular.js:1611

警告:任务“因果报应:单位”失败。使用--force继续

我的Gruntfile.js中包含以下内容:

karma: {
      unit: {
        configFile: 'karma.conf.js',
        singleRun: true
      }
    }
在karma.conf.js文件中,我有:

    module.exports = function(config) {
     config.set({
    // base path, that will be used to resolve files and exclude
    basePath: '',

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['jasmine'],

    // list of files / patterns to load in the browser
    files: [
      'app/bower_components/angular*/angular.js',
      'app/bower_components/angular-mocks/angular-mocks.js',
      'app/bower_components/angular-resource/angular-resource.js',
      'app/bower_components/angular-cookies/angular-cookies.js',
      'app/bower_components/angular-sanitize/angular-sanitize.js',
      'app/bower_components/angular-route/angular-route.js',
      'app/bower_components/angular-bootstrap/ui-bootstrap.js',
      'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
      'app/bower_components/service-state/js/StateService.js',      
      'app/scripts/controllers/dashboard.js',
      '../test/spec/**/*.js'
    ],

    // list of files / patterns to exclude
    exclude: [],
    // web server port
    port: 8080,

    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};
My package.json文件:

{
  "name": "karma1",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-css": "~0.5.4",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-coffee": "~0.7.0",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-compass": "~0.5.0",
    "grunt-contrib-jshint": "~0.6.0",
    "grunt-contrib-less": "~0.9.0",
    "grunt-contrib-cssmin": "~0.6.0",
    "grunt-contrib-connect": "~0.5.0",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-watch": "~0.5.2",
    "grunt-autoprefixer": "~0.2.0",
    "grunt-usemin": "~0.1.11",
    "grunt-rev": "~0.1.0",
    "grunt-shell": "~0.2.2",
    "grunt-concurrent": "~0.3.0",
    "load-grunt-tasks": "~0.1.0",
    "grunt-google-cdn": "~0.2.0",
    "grunt-ngmin": "~0.0.2",
    "time-grunt": "~0.1.0",
    "karma-ng-scenario": "^0.1.0",
    "grunt-karma": "^0.8.3",
    "karma": "^0.12.16",
    "karma-ng-html2js-preprocessor": "^0.1.0",
    "karma-jasmine": "^0.1.5",
    "karma-chrome-launcher": "^0.1.4",
    "karma-mocha": "latest",
    "chai": "1.4.0",
    "karma-script-launcher": "~0.1.0",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-requirejs": "~0.2.0",
    "karma-coffee-preprocessor": "~0.1.0",
    "karma-phantomjs-launcher": "~0.1.0",
    "grunt-open": "~0.2.2",
    "ng-midway-tester": "2.0.5"
  },
  "engines": {
    "node": ">=0.8.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}
我的测试控制器是: "严格使用",

describe('Controller: DashboardCtrl', function () {

  // load the controller's module
  beforeEach(module('karma1App'));

  var DashboardCtrl,
    scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function ($controller,$rootScope) {
    scope = $rootScope.$new();
    DashboardCtrl = $controller('DashboardCtrl', {
      $scope: scope
    });
  }));

  it('should attach a list of awesomeThings to the scope', function () {
    expect(scope.awesomeThings.length).toBe(3);
  });
});
我使用REQUIREJS加载其他依赖项,但REQUIRE仅在指令中使用。作为一个开始,我想测试我的控制器和服务,但我不断得到这个错误

知道出了什么问题吗


谢谢

我缺少的一点是,我没有加载angular应用程序。我正在通过config.js配置文件加载angular应用程序

/*全局角度*/

"严格使用",

describe('Controller: DashboardCtrl', function () {

  // load the controller's module
  beforeEach(module('karma1App'));

  var DashboardCtrl,
    scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function ($controller,$rootScope) {
    scope = $rootScope.$new();
    DashboardCtrl = $controller('DashboardCtrl', {
      $scope: scope
    });
  }));

  it('should attach a list of awesomeThings to the scope', function () {
    expect(scope.awesomeThings.length).toBe(3);
  });
});
var karma1App=angular.module('karma1App',[
“pascalprecht.translate”、“ngResource”、“ngRoute”,
'ui.bootstrap']); karma1App.config(['$routeProvider',函数($routeProvider){

*/ .when(“/admin”{ templateUrl:'views/admin.html', 控制器:“AdminCtrl” }) .否则({ 重定向到:'/site' }); }]);

在karma.conf.js中,我添加了以下脚本标记:

files: [
  'app/bower_components/angular*/angular.js',
  'app/bower_components/angular-mocks/angular-mocks.js',
  'app/bower_components/angular-resource/angular-resource.js',
  'app/bower_components/angular-cookies/angular-cookies.js',
  'app/bower_components/angular-sanitize/angular-sanitize.js',
  'app/bower_components/angular-route/angular-route.js',
  'app/bower_components/angular-bootstrap/ui-bootstrap.js',
  'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
  './test/test-main.js', 
  'app/scripts/controllers/dashboard.js',
  '../test/spec/**/*.js'
]
test-main.js仅包含以下代码行:

  /* global angular */

  'use strict';

 var karma1App = angular.module('karma1App', [
  'ngResource',
  'ngRoute', // Angular 1.2 requires separate ngRoute
  'ui.bootstrap',
  'StateService'
   ]);
在将test-main.js文件加载到karma.conf.js文件中之后,我能够使用karma对我的应用程序进行单元测试

希望这有帮助

谢谢,
Anirban

@68cherries-你好,请详细说明您的评论。也许我错过了什么。谢谢