【问题标题】:AngularJS + Grunt + Karma + E2EAngularJS + Grunt + Karma + E2E
【发布时间】:2013-09-04 00:18:44
【问题描述】:

我尝试使用 Grunt Karma 运行 E2E 测试,但没有成功。我看了很多解决方案,但没有一个有效!

我的 karma-e2e.conf.js:

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

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

    // frameworks to use
    frameworks: ['ng-scenario'],


    // list of files / patterns to load in the browser
    files: [            
        'test/e2e/**/*.js',
        'test/e2e/*.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: 9877,


    // 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: ['PhantomJS'],


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

    // Uncomment the following lines if you are using grunt's server to run the tests
    proxies: {
        '/': 'http://localhost/test/e2e/'
    },
    // URL root prevent conflicts with the site root
    urlRoot: '/_karma_/'
});

};

PS:我的应用在端口 80(Apache 默认)上运行。

我的规格如下:

describe('E2E: Testing Routes:', function () {
'use strict';

beforeEach(function() {
    browser().navigateTo('/');
});

it('should jump to the /videos path when / is accessed', function() {
    browser().navigateTo('#/');
    expect(browser().location().path()).toBe("/main");
});

})

所以,当我运行这个规范时,我收到了这条消息:

“类型错误:未定义不是函数(正在评估 $document.injector())”

此错误发生在“expect(browser().location().path()).toBe("/main");”行

有什么想法吗?

【问题讨论】:

标签: angularjs gruntjs karma-runner angularjs-e2e


【解决方案1】:

确保你运行你的网络服务器也是一个因果报应。尝试将您的代理设置更改为以下内容:

    proxies: {
    '/': 'http://localhost:8000/'
    },

【讨论】:

  • 我在端口 80 上运行我的服务器。(Apache 默认)。我使用了代理,但没有成功。
【解决方案2】:

你需要

 plugins: [
      'karma-ng-scenario',
    ],

在您的配置文件中。

npm install karma-ng-scenario --save-dev 首先

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多