AngularJS:使用Karma运行端到端测试



我想使用KarmaJS(0.9.2)运行我的Jasmine端到端测试。我在Windows 7上使用AngularJS(1.0.7)的Google Closure。当我开始使用karma start configkarma-e2e.js karma一切工作正常(浏览器导航到正确的页面),但它不执行我的测试(停止在'浏览器导航到')。

configkarma-e2e.js文件:

basePath = '../';
frameworks = ['ng-scenario'];
files = [
  'tests/e2e/**/*.js'
];
autoWatch = true;
singleRun = false;
browsers = ['Chrome'];
urlRoot = '/__karma/';
proxies = {
    '/': 'http://localhost:8080/'
}
plugins = [
    'karma-ng-scenario'
    'karma-chrome-launcher'
]

测试源(testse2escenarios.coffee)为:

describe 'Intro page view', ->
  it 'has hello world message', ->
    browser().navigateTo '/app/client/'
    expect(element('#text').text()).toBe 'Hello World'

我使用html5Mode路由,angular是使用angular.bootstrap手动引导的,我所有的咖啡脚本都是由IDE编译的,我在浏览器控制台或命令行中没有看到错误。那么我该怎么做呢?我做错了什么吗?

谢谢!

我解决了这个问题。看来angular场景需要ng-app指令,这至少是奇怪的(或者它是一个bug)。所以我在索引页上调用App.bootstrap()后,在正文中添加了ng-app属性。现在一切正常。

<script type="text/javascript">
App.bootstrap();
document.body.setAttribute('ng-app', 'App');
</script>

最新更新