karma运行角度测试适用于Chrome浏览器,但不适用于PhantomJs

时间:2014-07-24 15:39:35

标签: angularjs jasmine phantomjs karma-runner

我在我的角度项目中运行单元测试,如果我使用Chrome运行它,这可以正常工作,但不是很多,我使用PhantomJS

我有一个像这样的karma.config.js文件:

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/*.js',
        'web/js/*.js',
        'test/spec/*spec.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', 'junit'],

    // the default configuration
    junitReporter: {
        outputFile: 'testResult/test-results.xml',
        suite: ''
    },



    // 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: false,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


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

并且像这样(使用Chrome)正常工作

 Running "karma:unit" (karma) task
 INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
 INFO [launcher]: Starting browser Chrome
 INFO [Chrome 36.0.1985 (Windows 7)]: Connected on socket oi7YLBSbpVbZSiVI_BPs
 Chrome 36.0.1985 (Windows 7): Executed 8 of 8 SUCCESS (0.238 secs / 0.019 secs)

但如果我更改浏览器(到PhantomJS)会出错

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket Uy390TQWuDGR2pCi_GRy
PhantomJS 1.9.7 (Windows 7) ERROR
TypeError: '[object NodeList]' is not a valid argument for 
'Function.prototype.apply' (evaluating 'push.apply')
at C:/Users/Lino Simões/Documents/bitbucket/jenkins-test/lib/angular.js: 2594
PhantomJS 1.9.7 (Windows 7): Executed 0 of 0 ERROR (0.131 secs / 0 secs)
Warning: Task "karma:unit" failed. Used --force, continuing.

所以我的问题是,为什么这适用于Chrome但不适用于PhantomJs,我可以更改哪些内容以使其适用于PhantomJS

1 个答案:

答案 0 :(得分:0)

在PhantomJS 1.x中运行时,'[object NodeList]' is not a valid argument问题已在angular.js v1.3.0-beta.14中修复,请参阅#7851

尝试将angular.js升级为v1.3.0-beta.14或更新版本。

PS。另一种解决方案是使用PhantomJS 2