TypeError:对象#<object>在$ log对象</object>上没有方法'debug'Karma

时间:2013-08-22 17:12:44

标签: angularjs jasmine karma-runner

在我的角度项目上运行我的业力单元测试时,我在定义了$log的行上遇到错误。

我正在使用Karma版本:0.10.1,我的配置文件是:

// Karma configuration
// Generated on Wed Aug 21 2013 14:10:06 GMT-0400 (EDT)

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: [
        '../build/angular/angular.js',
        '../build/angular/angular-mocks.js',
        '../build/angular/angular-resource.js',
        '../build/angular/angular-cookies.js',
        '../src/**/*.js',
        '../dist/tmp/**/*.js',
        '../vendor/angular-bootstrap/*.js',
        '../vendor/angular-ui-utils/modules/route/*.js',
        '../vendor/angular-ui-utils/modules/mask/*.js',
        '../vendor/angular-ui-utils/modules/event/*.js',
        '../vendor/angular-ui-utils/modules/keypress/*.js',
        '../vendor/moment/moment.js',
        '../vendor/Highcharts-3.0.2/highcharts.js',
        '../vendor/Highcharts-3.0.2/modules/exporting.js'
    ],


    // list of files to exclude
    exclude: [

    ],


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


    // web server port
    port: 9018,


    // 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
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['Chrome'],//nothing so we can start it on our own


    // 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
});
};

2 个答案:

答案 0 :(得分:2)

如果您使用稳定版本的角度(目前为1.0.8),则没有方法$log.debug(请参阅v1.0.8's $log documentation$log.debug仅适用于v1.1.2以后,e.g. from v1.1.2's $log documentation

最佳选择可能是$log.log()

答案 1 :(得分:0)

Lorcan对问题的识别是完全正确的,但有一个更好的解决方案。我只是遇到了这个问题,它的根源在于版本升级的不一致。我参加了一个项目中期。这个项目从角度版本1.0开始。*。该项目最终升级为角度1.2.3。问题是,当更新主lib目录时,单元测试的angular-mock.js文件不是。单元测试在模拟文件中运行较旧版本的angular。转到http://code.angularjs.org/并选择您正在使用的角度版本。然后将angular-mock.js替换为适合您的角度版本。这解决了.debug错误。