设置Jasmine:获取undefined不是jasmine.js中的对象

时间:2017-02-18 19:18:51

标签: jasmine karma-jasmine

我正在尝试初始设置jasmine来为我的代码编写单元测试。当我运行'karma start unit-tests.conf.js'时,我一直遇到这个错误:

enter image description here

我不确定这意味着什么。如果您无法读取错误,它会像这样:

PhantomJS 2.1.1 (Windows 8 0/0/0) Error
TypeError: undefined is not an object (evaluating 'spacDefinitions.length') 
at C:/Users/GoogleDrive/.../node_modules/jasmine-core/lib/jasmine-core/jasmine.js:830

以下是我的配置文件。我没有正确配置吗?有什么我想念的吗?

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

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'lib/ionic/js/ionic.bundle.js',
      'lib/angular-mocks/angular-mocks.js',
      'js/*',
      'index.controller.js',
      'layout/mainView.directive.js',
    ],


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


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    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
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

在你的karma配置中,我没有在'files'部分看到angular.min.js的条目。将文件部分替换为: -

 files: [
   'lib/ionic/js/ionic.bundle.js',
   'lib/angular.min.js',
   'lib/angular-mocks/angular-mocks.js',
   'js/*',
   'index.controller.js',
   'layout/mainView.directive.js',
],

假设angular.min.js放在lib文件夹中。 它应该工作。

相关问题