gpt4 book ai didi

testing - E2E 测试远程 AngularJS 应用程序

转载 作者:行者123 更新时间:2023-11-28 20:12:11 26 4
gpt4 key购买 nike

我正在尝试使用 Karma Test Runner 实现对现有 AngularJS 应用程序的端到端测试。我的申请位于 host1.internal我在 host2.internal .所以在我的 karma 配置文件中我有:

proxies = {
'/': 'http://host1.internal/',
};

登录前显示不同的<div>index.html 里面的, 但在登录后它会隐藏所有可见的 div 之前 ng-hide='loggedIn' .问题是正在为 <div ng-view> 获取部分 View 文件使用 AngularJS 这样的路由配置:

$routeProvider.
when('/', {
controller: overviewController,
templateUrl: 'views/overview.html',
// templateUrl: 'http://host2.internal/views/overview.html',
title_prefix: 'Home'
}).
etc. etc. etc.

我在浏览器的控制台中收到这些错误:

GET http://localhost:9876/views/homepage.html 404 (Not Found)

正如您在路由配置代码片段中所见,我尝试获取具有完整 URL 的模板,但不幸的是,请求并不简单 GET ,它是 OPTIONS (我不确定为什么?)而且我收到有关旧的 Access-Control-Allow-Origin header 的错误。

如何在 Karma 配置中正确配置代理,以便我可以获取这些静态文件?或者任何其他解决方案?

谢谢!

最佳答案

我已经找到解决这个问题的方法,我已经使用了 $templateCache。这样一来,所有 html 文件都与我的 index.html 上的所有其余脚本一起加载到一个 .js 文件中。

如果你像我一样使用 Grunt,请查看 grunt-html2js .

干杯!

关于testing - E2E 测试远程 AngularJS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16341070/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com