angularjs - Webstorm karma/jasmine angularjs 测试 - 引用错误模块未定义

标签 angularjs jasmine karma-runner webstorm

我正在尝试设置 WebStorm 来开发 AngularJS。我已经关注了instructions from JetBrains我正在尝试从 that tutorial 运行测试.

describe('PhoneCat controllers', function() {
  beforeEach(module('phonecatApp'));

  describe('PhoneListCtrl', function(){

    it('should create "phones" model with 3 phones', inject(function($controller) {
      var scope = {},
          ctrl = $controller('PhoneListCtrl', { $scope: scope });

      expect(scope.phones.length).toBe(3);
    }));
  });
});

我收到以下错误

"C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\JetBrains\WebStorm 7.0.3\plugins\js-karma\js_reporter\karma-intellij\lib\intellijRunner.js" --karmaPackageDir=C:\Users\L\node_modules\karma --serverPort=9876 --urlRoot=/
Testing started at 21:02 ...

    ReferenceError: module is not defined
        at null.<anonymous> (C:/Users/L/WebstormProjects/AngularJS/test/unit/ControllerTests.js:4:16)
        at C:/Users/L/WebstormProjects/AngularJS/test/unit/ControllerTests.js:3:1


Process finished with exit code 0

我的目录布局是

  • test/unit/ControllerTest.js

  • test/karma.conf.js

karma.conf.js 下面

// Karma configuration
// Generated on Sun Feb 16 2014 20:49:06 GMT+0000 (GMT Standard Time)

module.exports = function(config) {
  config.set({

    // base path, that will be used to resolve files and exclude
    basePath: '',


    // frameworks to use
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      {pattern: '*.js', included: true},
      {pattern: 'unit/*.js', included: true}
    ],


    // list of files to exclude
    exclude: [
    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


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


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


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera (has to be installed with `npm install karma-opera-launcher`)
    // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
    // - PhantomJS
    // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
    browsers: ['Chrome'],


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

最佳答案

缺少 angular-mocks.js 请参阅http://devnet.jetbrains.com/thread/452824?tstart=0

关于angularjs - Webstorm karma/jasmine angularjs 测试 - 引用错误模块未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21816634/

相关文章:

javascript - 没有 URL 状态的 AngularJS ui-router 默认状态

使用 Jasmine 和 Sinon 测试主干模型 - 对象 #<Object> 没有方法 'spy'

javascript - 使用 Jasmine 测试 Angular Controller 中的对象初始化

node.js - 如何从 Node 项目的命令行运行 Jasmine 测试框架 2.0

angularjs - 如何在 AngularJS Karma 单元测试中触发 `$on` 事件?

javascript - 系统关闭时 localStorage 未被清除

javascript - 用户界面路由器返回 : "Cannot GET/page"

jquery - AngularJS 中的 JSONP 请求不像 jQuery 那样工作

javascript - 无法使用 Karma 运行 Coverage

angularjs - ui-router 在 Controller 测试中导致 "full page reload"?